Full Version: Istext?
UtterAccess Forums > Microsoft® Access > Access Forms
realgoldn
Is tehre a such thing as istext function? I want to know if a value in a text box is all letters.
adamsherring
Its easy to create your own.
I have a few string functions I include with all of my projects. Combining a few can make your isText function.
example
CODE
  
public function isText(sText as string) as boolean
   dim x as integer
  
   for x = 1 to len(sText)
         isText = isalpha(asc(charat(sText ,x)))
         if isText = false then exit function
   next x

end function
Public Function isAlpha(cChar As Integer) As Boolean    'returns if its a alphabetic character
    isAlpha = IIf((cChar >= 65 And cChar <= 90) Or (cChar >= 97 And cChar <= 122), True, False)
End Function
Public Function charAt(sText As String, nLoc As Integer) As String
    'this is much like the java function - returns a specific character from a string
    charAt = (Mid(sText, nLoc, 1))
End Function

There may be an easier way - but this will do the trick, and I find it easier to have those little functions around.
Adam
dallr
I just put this together for you. Just place it in a module so you can call it from where ever you want.
CODE

Public Function IsText(MyCtl As String) As Boolean
im C As Integer, I As Integer, Counter As Integer
IsText = False
For C = 1 To Len(MyCtl)
    For I = 65 To 90
        If Mid(UCase(MyCtl), C, 1) = Chr(I) Then
            Counter = Counter + 1
        End If
    Next I
Next C
If Counter = Len(MyCtl) Then IsText = True
End Function

Dallr
fkegley
I like to use the KeyPress event to check the ASCII code of the key that was pressed BEFORE I send it to the text box to be displayed.
For instance, this code will only allow up to 10 letters to be entered into a text box:
Private Sub Text0_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then
Exit Sub
End If
End Sub
Private Sub Text0_KeyPress(KeyAscii As Integer)
If Len(Text0.Text) < 10 Then
If UCase$(Chr(KeyAscii)) >= "A" And UCase$(Chr(KeyAscii)) <= "Z" Then
Else
KeyAscii = 0
End If
Else
KeyAscii = 0
End If
End Sub
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.