Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save maxca/9eb5bab5f0442d193461c101212f4fa7 to your computer and use it in GitHub Desktop.
Save maxca/9eb5bab5f0442d193461c101212f4fa7 to your computer and use it in GitHub Desktop.
' @Author samark chaisanguan
' @Email samark.work@gmail.com
' @Since 20/07/2020
' Defined global input string
Global inputString As String
Sub testValidateTxtInput()
inputString = Range("A1")
convertStrToAssiicode (inputString)
getOs
End Sub
' Override printing message
' @param message as string
Public Function dd(msg As String)
Debug.Print (msg)
End Function
' Convert String to Assiicode
' @param s as String
' @return the string to its respective ascii numbers
Public Function convertStrToAssiicode(txtInput As String)
Dim i As Integer
Dim myArray() As Variant
' Resize array
ReDim myArray(Len(txtInput))
For i = 1 To Len(txtInput)
' myArray(x) = i
j = CStr(Asc(Mid(txtInput, i, 1)))
validateAssiiCode (j)
'dd (j)
Next i
End Function
' Validataion allowed rage of assii code
' @thow exception
' @modify custom result of validation
' Thai assii code start from 161 to 249 end of number thai 0-9
' Thai assii code for mac osx 95
' English Alphabets Small Letters assiicode start form 97 to 122
' English Alphabets Capital Letters assiicode start from 65 to 90
' Number assiicode start from 48 to 57
' Space assiicode 32
' Custom for OSx assiicode 95
Public Function validateAssiiCode(ass As Integer)
' Get Operation System
Dim Os As String
Os = getOs
If Os = "window" Then
' [For thai charector ] [For Small Letters] [For Capital Leters] [For Numeric]
If ((ass >= 161 And ass <= 249) Or (ass >= 97 And ass <= 122) Or (ass >= 65 And ass <= 90) Or (ass >= 48 And ass <= 57) Or (ass = 32)) Then
'dd("validation pass")
Else
' You can custom response here
dd ("validation fail")
End If
ElseIf Os = "osx" Then
' [For thai charector ] [For Small Letters] [For Capital Leters] [For Numeric]
If ((ass >= 161 And ass <= 249) Or (ass >= 97 And ass <= 122) Or (ass >= 65 And ass <= 90) Or (ass >= 48 And ass <= 57) Or (ass = 32) Or (ass = 95)) Then
'dd("validation pass")
Else
' You can custom response here
dd ("validation fail")
End If
End If
' printing debug assiicode
dd ("debug " & ass)
End Function
' Get Operation System
' @return OS as String
Public Function getOs() As String
Dim Os As String
Os = Application.OperatingSystem
If (InStr(Os, "Windows")) Then
getOs = "window"
ElseIf (InStr(Os, "Macintosh")) Then
getOs = "osx"
Else
getOs = "other"
End If
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment