|
-
Oct 26th, 2006, 08:08 AM
#1
Thread Starter
Member
[Resolved]Comparing
VB Code:
Private Sub Command3_Click()
Dim pass1 As String
Dim pass2 As String
pass1 = Jorn
pass2 = Jorn
If pass1.Text = pass1 & pass2.Text = pass2 Then
MsgBox "Correct"
Else
MsgBox "Hahah"
End If
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.
-
Oct 26th, 2006, 08:13 AM
#2
Re: Comparing
change this
VB Code:
If pass1.Text = pass1 & pass2.Text = pass2 Then
to
VB Code:
If pass1.Text = pass1 & pass2.Text Then
-
Oct 26th, 2006, 08:16 AM
#3
Thread Starter
Member
Re: Comparing
Still says invalid qualifier
If life was something money could buy, the poor would not live and the rich would not die.
-
Oct 26th, 2006, 08:17 AM
#4
Re: Comparing
change this
VB Code:
pass1 = Jorn
pass2 = Jorn
to
VB Code:
pass1 = "Jorn"
pass2 = "Jorn"
-
Oct 26th, 2006, 08:18 AM
#5
Thread Starter
Member
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.
-
Oct 26th, 2006, 08:19 AM
#6
Re: Comparing
Dim pass1 As String
pass1.Text???
I don't get what you're trying to do here... but:
VB Code:
If StrComp(pass1.Text, pass2.Text, vbTextCompare) = 0 Then
MsgBox "Correct!"
Else
MsgBox "Haha!"
End If
-
Oct 26th, 2006, 08:21 AM
#7
Hyperactive Member
Re: Comparing
 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.
-
Oct 26th, 2006, 08:23 AM
#8
Thread Starter
Member
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.
-
Oct 26th, 2006, 08:25 AM
#9
Hyperactive Member
Re: Comparing
 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:
Private Sub Command3_Click()
Dim pass1 As Variant
Dim pass2 As Variant
pass1 = "Jorn"
pass2 = "Jorn"
If frmTestForm.pass1.Text = pass1 & frmTestForm.pass2.Text = pass2 Then
MsgBox "Correct"
Else
MsgBox "Hahah"
End If
End Sub
-
Oct 26th, 2006, 08:28 AM
#10
Thread Starter
Member
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.
-
Oct 26th, 2006, 08:28 AM
#11
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:
Private Sub Command3_Click()
If (pass1.Text = "Jorn") And (pass2.Text = "Jorn") Then
MsgBox "Correct"
Else
MsgBox "Hahah"
End If
End Sub
-
Oct 26th, 2006, 08:31 AM
#12
Thread Starter
Member
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.
-
Oct 26th, 2006, 08:32 AM
#13
Hyperactive Member
Re: Comparing
 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.
-
Oct 26th, 2006, 08:34 AM
#14
Thread Starter
Member
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.
-
Oct 26th, 2006, 08:36 AM
#15
Re: Comparing
 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.
-
Oct 26th, 2006, 08:39 AM
#16
Hyperactive Member
Re: Comparing
 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:
Private Sub Command3_Click()
If CriteriaSelection.pass1.Text = CriteriaSelection.pass2.Text Then
MsgBox "Correct"
Else
MsgBox "Hahah"
End If
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.
-
Oct 26th, 2006, 08:40 AM
#17
Thread Starter
Member
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.
-
Oct 26th, 2006, 08:43 AM
#18
Re: Comparing
 Originally Posted by LeeMcCurry
Trimmed? and yes I have been doing it case sensitive.
VB Code:
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.
-
Oct 26th, 2006, 08:44 AM
#19
Thread Starter
Member
Re: Comparing
 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:
Private Sub Command3_Click()
If CriteriaSelection.pass1.Text = CriteriaSelection.pass2.Text Then
MsgBox "Correct"
Else
MsgBox "Hahah"
End If
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.
-
Oct 26th, 2006, 08:45 AM
#20
Hyperactive Member
Re: Comparing
 Originally Posted by Comintern
VB Code:
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.
-
Oct 26th, 2006, 08:45 AM
#21
Hyperactive Member
Re: Comparing
 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!
-
Oct 26th, 2006, 08:47 AM
#22
Thread Starter
Member
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.
-
Oct 26th, 2006, 08:49 AM
#23
Re: Comparing
 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.
-
Oct 26th, 2006, 08:52 AM
#24
Re: Comparing
Q:
 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:
 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.
-
Oct 26th, 2006, 08:54 AM
#25
Thread Starter
Member
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.
-
Oct 26th, 2006, 09:06 AM
#26
Re: [Resolved]Comparing
 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:
Option Explicit
Dim Command3 As String 'Will give a "Member already exists" error.
Private Sub Command3_Click()
Dim Command3 As String 'Will not throw an error, but
'supercedes the object in this scope.
End Sub
-
Oct 26th, 2006, 09:10 AM
#27
Thread Starter
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|