Results 1 to 27 of 27

Thread: [Resolved]Comparing

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2006
    Location
    England
    Posts
    49

    Resolved [Resolved]Comparing

    VB Code:
    1. Private Sub Command3_Click()
    2. Dim pass1 As String
    3. Dim pass2 As String
    4.  
    5. pass1 = Jorn
    6. pass2 = Jorn
    7.  
    8. If pass1.Text = pass1 & pass2.Text = pass2 Then
    9. MsgBox "Correct"
    10. Else
    11. MsgBox "Hahah"
    12.  
    13. End If
    14.  
    15.  
    16. End Sub
    This is basicly checking if the same text has been entered into two different boxes and when I press a button and they are the same I want a message to be shown
    Why do I get the error invalid qualifier? vb highlights this bit
    Private Sub Command3_Click()
    help please
    Last edited by LeeMcCurry; Oct 26th, 2006 at 08:51 AM.
    If life was something money could buy, the poor would not live and the rich would not die.

  2. #2
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Comparing

    change this
    VB Code:
    1. If pass1.Text = pass1 & pass2.Text = pass2 Then
    to
    VB Code:
    1. If pass1.Text = pass1 & pass2.Text  Then

  3. #3

    Thread Starter
    Member
    Join Date
    Oct 2006
    Location
    England
    Posts
    49

    Re: Comparing

    Still says invalid qualifier
    If life was something money could buy, the poor would not live and the rich would not die.

  4. #4
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Comparing

    change this
    VB Code:
    1. pass1 = Jorn
    2. pass2 = Jorn
    to
    VB Code:
    1. pass1 = "Jorn"
    2. pass2 = "Jorn"

  5. #5

    Thread Starter
    Member
    Join Date
    Oct 2006
    Location
    England
    Posts
    49

    Re: Comparing

    Weird it still highlights the private sub and says invalid qualifier. Btw did you (write it for only 1 box before? because the same information needs to be in both boxes. probaly not but just checking)
    If life was something money could buy, the poor would not live and the rich would not die.

  6. #6
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: Comparing

    Dim pass1 As String
    pass1.Text???

    I don't get what you're trying to do here... but:
    VB Code:
    1. If StrComp(pass1.Text, pass2.Text, vbTextCompare) = 0 Then
    2.     MsgBox "Correct!"
    3. Else
    4.     MsgBox "Haha!"
    5. End If

  7. #7
    Hyperactive Member
    Join Date
    Oct 2006
    Location
    USA
    Posts
    476

    Re: Comparing

    Quote Originally Posted by LeeMcCurry
    Still says invalid qualifier

    You need to use the form name to qualify the text box, i.e. formname.textboxname.text instead of textboxname.text

    Also dim pass1 and pass2 as variants.

  8. #8

    Thread Starter
    Member
    Join Date
    Oct 2006
    Location
    England
    Posts
    49

    Re: Comparing

    Ok Ill try explain it abit better. Also your code gavio still gives me invalid qualifier
    I made 2 variables that both contain the information Jorn(I only really need one avriable actually). If I type jorn in both boxes and then I click a command button I want it to display correcy if they are the same and haha if they are not.
    If life was something money could buy, the poor would not live and the rich would not die.

  9. #9
    Hyperactive Member
    Join Date
    Oct 2006
    Location
    USA
    Posts
    476

    Re: Comparing

    Quote Originally Posted by LeeMcCurry
    Ok Ill try explain it abit better. Also your code gavio still gives me invalid qualifier
    I made 2 variables that both contain the information Jorn(I only really need one avriable actually). If I type jorn in both boxes and then I click a command button I want it to display correcy if they are the same and haha if they are not.
    Lee, this works for me in VB6:

    VB Code:
    1. Private Sub Command3_Click()
    2. Dim pass1 As Variant
    3. Dim pass2 As Variant
    4.  
    5. pass1 = "Jorn"
    6. pass2 = "Jorn"
    7.  
    8. If frmTestForm.pass1.Text = pass1 & frmTestForm.pass2.Text = pass2 Then
    9. MsgBox "Correct"
    10. Else
    11. MsgBox "Hahah"
    12.  
    13. End If
    14. End Sub

  10. #10

    Thread Starter
    Member
    Join Date
    Oct 2006
    Location
    England
    Posts
    49

    Re: Comparing

    Doing variants got rid of invalid qualifier thanks. However this bit
    If cmdloops.pass1.Text = pass1 & frmcmdloops.pass2.Text = pass2 Then
    From your previous code gets object required.
    If life was something money could buy, the poor would not live and the rich would not die.

  11. #11
    Fanatic Member Comintern's Avatar
    Join Date
    Nov 2004
    Location
    Lincoln, NE
    Posts
    826

    Re: Comparing

    My guess is that you have controls named pass1 and pass2. You should never declare variables with the same names as global objects. Also, there is really no need to set these to variables at all as the values are constant. Just use the constant values in your If expression. Finally, & is the concat operator not the bitwise And. Try something like this:
    VB Code:
    1. Private Sub Command3_Click()
    2.    
    3.     If (pass1.Text = "Jorn") And (pass2.Text = "Jorn") Then
    4.         MsgBox "Correct"
    5.     Else
    6.         MsgBox "Hahah"
    7.     End If
    8.  
    9. End Sub

  12. #12

    Thread Starter
    Member
    Join Date
    Oct 2006
    Location
    England
    Posts
    49

    Re: Comparing

    The above code gives not errors but for for some reason only shows the hahah box even though the information in both fields are the same
    If life was something money could buy, the poor would not live and the rich would not die.

  13. #13
    Hyperactive Member
    Join Date
    Oct 2006
    Location
    USA
    Posts
    476

    Re: Comparing

    Quote Originally Posted by LeeMcCurry
    Doing variants got rid of invalid qualifier thanks. However this bit
    If cmdloops.pass1.Text = pass1 & frmcmdloops.pass2.Text = pass2 Then
    From your previous code gets object required.

    You're not using the same name; you're qualifying one with cmdloops.pass1.text and the other with frmcmdloops.pass2.text. Please copy and paste the entire code block from VB6.

  14. #14

    Thread Starter
    Member
    Join Date
    Oct 2006
    Location
    England
    Posts
    49

    Re: Comparing

    Disruptive yours works too but its the same problem as with comintherns code.
    If life was something money could buy, the poor would not live and the rich would not die.

  15. #15
    Fanatic Member Comintern's Avatar
    Join Date
    Nov 2004
    Location
    Lincoln, NE
    Posts
    826

    Re: Comparing

    Quote Originally Posted by LeeMcCurry
    The above code gives not errors but for for some reason only shows the hahah box even though the information in both fields are the same
    Is the text in the Textboxes trimmed? Also, this will be case sensitive.

  16. #16
    Hyperactive Member
    Join Date
    Oct 2006
    Location
    USA
    Posts
    476

    Re: Comparing

    Quote Originally Posted by LeeMcCurry
    Disruptive yours works too but its the same problem as with comintherns code.
    This also works for me with the added benefit of not having to deal with the hard-coded "Jorn" thing:

    VB Code:
    1. Private Sub Command3_Click()
    2.  
    3.  
    4. If CriteriaSelection.pass1.Text = CriteriaSelection.pass2.Text Then
    5. MsgBox "Correct"
    6. Else
    7. MsgBox "Hahah"
    8.  
    9. End If
    10.  
    11.  
    12. End Sub

    If this doesn't work then I dunno what else to suggest, especially without seeing the code. Be sure to change 'CriteriaSelection' to the name of the form you're using.

  17. #17

    Thread Starter
    Member
    Join Date
    Oct 2006
    Location
    England
    Posts
    49

    Re: Comparing

    Trimmed? and yes I have been doing it case sensitive.
    If life was something money could buy, the poor would not live and the rich would not die.

  18. #18
    Fanatic Member Comintern's Avatar
    Join Date
    Nov 2004
    Location
    Lincoln, NE
    Posts
    826

    Re: Comparing

    Quote Originally Posted by LeeMcCurry
    Trimmed? and yes I have been doing it case sensitive.
    VB Code:
    1. If (Trim$(pass1.Text) = "Jorn") And (Trim$(pass2.Text) = "Jorn") Then
    @disruptivehair: Based on the original code, it looks like there are 2 password Textboxes that have to match a single constant, not match each other.

  19. #19

    Thread Starter
    Member
    Join Date
    Oct 2006
    Location
    England
    Posts
    49

    Re: Comparing

    Quote Originally Posted by disruptivehair
    This also works for me with the added benefit of not having to deal with the hard-coded "Jorn" thing:

    VB Code:
    1. Private Sub Command3_Click()
    2.  
    3.  
    4. If CriteriaSelection.pass1.Text = CriteriaSelection.pass2.Text Then
    5. MsgBox "Correct"
    6. Else
    7. MsgBox "Hahah"
    8.  
    9. End If
    10.  
    11.  
    12. End Sub

    If this doesn't work then I dunno what else to suggest, especially without seeing the code. Be sure to change 'CriteriaSelection' to the name of the form you're using.
    Worked brilliantly and less code too thanks.
    If life was something money could buy, the poor would not live and the rich would not die.

  20. #20
    Hyperactive Member
    Join Date
    Oct 2006
    Location
    USA
    Posts
    476

    Re: Comparing

    Quote Originally Posted by Comintern
    VB Code:
    1. If (Trim$(pass1.Text) = "Jorn") And (Trim$(pass2.Text) = "Jorn") Then
    @disruptivehair: Based on the original code, it looks like there are 2 password Textboxes that have to match a single constant, not match each other.
    Alrighty then.

  21. #21
    Hyperactive Member
    Join Date
    Oct 2006
    Location
    USA
    Posts
    476

    Re: Comparing

    Quote Originally Posted by LeeMcCurry
    Worked brilliantly and less code too thanks.
    Goody! If you're happy with that then can you use the thread tools to mark the thread as resolved? Thanks!

  22. #22

    Thread Starter
    Member
    Join Date
    Oct 2006
    Location
    England
    Posts
    49

    Re: Comparing

    yours works too comn, what does trim do though? onyl take abit of the code entered? and daniel why did I have to define the form like when I had to write cmdloops.pass2text or at least I think it was.
    If life was something money could buy, the poor would not live and the rich would not die.

  23. #23
    Fanatic Member Comintern's Avatar
    Join Date
    Nov 2004
    Location
    Lincoln, NE
    Posts
    826

    Re: Comparing

    Quote Originally Posted by LeeMcCurry
    yours works too comn, what does trim do though? onyl take abit of the code entered?
    Trim removes all of the spaces from the right and left of the string.

  24. #24
    Fanatic Member Comintern's Avatar
    Join Date
    Nov 2004
    Location
    Lincoln, NE
    Posts
    826

    Re: Comparing

    Q:
    Quote Originally Posted by LeeMcCurry
    and daniel why did I have to define the form like when I had to write cmdloops.pass2text or at least I think it was.
    A:
    Quote Originally Posted by Comintern
    My guess is that you have controls named pass1 and pass2. You should never declare variables with the same names as global objects.
    When you have different variables with the same name, you have to find some way to explicitly let the compiler know which one is which. You can avoid this by keeping your variable names distinct.

  25. #25

    Thread Starter
    Member
    Join Date
    Oct 2006
    Location
    England
    Posts
    49

    Re: [Resolved]Comparing

    So I have to avoid naming variables the same as objects? got it, I just cames up with the names pass1 and 2 because they were the same as the text boxes.
    If life was something money could buy, the poor would not live and the rich would not die.

  26. #26
    Fanatic Member Comintern's Avatar
    Join Date
    Nov 2004
    Location
    Lincoln, NE
    Posts
    826

    Re: [Resolved]Comparing

    Quote Originally Posted by LeeMcCurry
    So I have to avoid naming variables the same as objects? got it, I just cames up with the names pass1 and 2 because they were the same as the text boxes.
    VB treats a form object like an object variable, it is just implicitly declared for you. Same thing for forms and modules. So, you should treat the controls on your form as if they were object instances (which they are). What VB6 does let you do is have variables with the same name and different scope. The controls on a form are all treated as form level variables, so it allows you to re-use names in more restrictive scopes. It's just a really bad idea because it makes it hard to tell what is going on in the code, and as you found out can lead to strange compiler errors. Check out the example below to see what I mean:
    VB Code:
    1. Option Explicit
    2.  
    3. Dim Command3 As String          'Will give a "Member already exists" error.
    4.  
    5. Private Sub Command3_Click()
    6.  
    7.     Dim Command3 As String      'Will not throw an error, but
    8.                                 'supercedes the object in this scope.
    9. End Sub

  27. #27

    Thread Starter
    Member
    Join Date
    Oct 2006
    Location
    England
    Posts
    49

    Re: [Resolved]Comparing

    Ah I see what you mean. Thanks alot for your help. I forgot these things easily so I have wrote them all down lol.
    If life was something money could buy, the poor would not live and the rich would not die.

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