Results 1 to 5 of 5

Thread: Compare text

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2000
    Posts
    10
    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

  2. #2
    Fanatic Member
    Join Date
    Feb 2000
    Location
    The Netherlands
    Posts
    715
    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

  3. #3
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    There is a like function (forgot my vb textbook at school so I can't show you how to use it) sorry

  4. #4
    Guest
    Like is a simple operator.
    Code:
    If String1 Like String2 Then TheyAreTheSame

  5. #5
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>


    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
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width