-
Hello,I am new to vb and I had this question.
I need to read a file that has different fields.
one of the fields has to be uppercase.
what i need to do is a validation if the string is lowercase raise an error.
It only has to be upper.
Thanx for your help
-
This will check for uppercase:
Code:
Dim SomeText As String
SomeText = "HELLO"
If Ucase(SomeText) = SomeText Then
Msgbox "Uppercase."
Else
MsgBox "Not uppercase."
End If
-
There is a like function (forgot my vb textbook at school so I can't show you how to use it) sorry
-
Like is a simple operator.
Code:
If String1 Like String2 Then TheyAreTheSame
-
<?>
Private Sub Command1_Click()
'this will not work as ucase converts it to uppercase
'and so it will always be uppercase even if it isn't
Dim SomeText As String
SomeText = "Hello"
If UCase(SomeText) = SomeText Then
MsgBox "Uppercase."
Else
MsgBox "Not uppercase."
End If
End Sub
'option like is not an option as you are not
'comparing strings you are merely looking for
'any uppercase characters anywhere in string
'Working Code
Code:
Option Explicit
Private Sub Form_Load()
'this would be the var read from file
Dim myString As String
myString = "hello"
Dim myLen As Integer 'string len
Dim iCount As Integer 'var to loop the string
'set to false at beginning
myAt = False
'get the len for loop
myLen = Len(x)
'loop and check for ascii value of letters in string
For iCount = 1 To myLen
y = Left(x, 1)
'if any capital found then alert user and exit sub
If Asc(y) <= 90 _
And Asc(y) >= 65 Then
MsgBox "Capital is included"
Exit Sub
End If
Next
End Sub