Utilizzo una funzione che consente di rivedere una stringa di testo e valutare se è composta da lettere. È ospitato in un modulo chiamato "Generale". Il modulo generale esiste solo per ospitare funzioni pubbliche e variabili. Codice funzione è elencato di seguito:Come posso verificare se una stringa contiene solo lettere?
Public Function IsAlpha(strValue As String) As Boolean
Dim intPos As Integer
For intPos = 1 To Len(strValue)
Select Case Asc(Mid(strValue, intPos, 1))
Case 65 To 90, 97 To 122
IsLetter = True
Case Else
IsLetter = False
Exit For
End Select
Next
End Function
successivo ho due "se" routine che valutano i primi 2 caratteri di una casella di testo nella mia userform. La prima routine chiede se il 1 ° carattere è numerico e la seconda routine chiede se il 2 ° carattere è alfa. Attualmente, la seconda routine "if" mi sta espellendo dalla sub-routine quando IsAlpha verifica True, piuttosto che generare MsgBox. La funzione IsAlpha non viene chiamata correttamente?
Se il codice routine elencati di seguito:
Private Sub CmdMap_Click()
With TxtDxCode
If IsNumeric(Left(Me.TxtDxCode.Text, 1)) Then
MsgBox "Incorrect DX Code format was entered. ", vbExclamation, "DX Code Entry"
TxtDxCode.Value = ""
TxtDxCode.SetFocus
Exit Sub
End If
If IsAlpha(Left(Me.TxtDxCode.Text, 2)) Then
MsgBox "Incorrect DX Code format was entered. ", vbExclamation, "DX Code Entry"
TxtDxCode.Value = ""
TxtDxCode.SetFocus
Exit Sub
End If
End With
Come deve apparire il codice DX? –
il tuo nome di funzione "IsAlpha" .. il tuo incarico uscita: "IsLetter" .. che non funziona bene .. – Ditto
@MaciejLos char1 = Alpha char2 = numerico Caratteri aggiuntivi = Alpha Numeric + –