Stupid logic is messing up again... < = > Statements crapping out...

  • Thread starter Thread starter Shaka215
  • Start date Start date
S

Shaka215

Hello! I am having issues with the following code...It seems that my
statment below isn't working the way it should. Here is the
situation... THE < ans, > ans, = ans is the problem. I need the code to
only match the TRUE completed value of TextBox3... I applogize how
disorganized this appears but there is no better way to present it.

COMPLETED CODE

Private Sub CommandButton1_Click()
On Error GoTo nogood
ans = TextBox3.Value
'================================vvvvvv======
If Sheet1.Range("datacorrect").Find(ans).Row < ans Then
'================================^^^^^^^======
MsgBox "OK"
Unload Me
Exit Sub
End If
nogood: MsgBox "Information Incorrect...Please try again."
Userform1.Show
End Sub



SITUATION 1 [ > ans ] -- Partial Information Completes Macro
'================================vvvvvv======
If Sheet1.Range("datacorrect").Find(ans).Row < ans Then
'================================^^^^^^^======
Situation: If the person types the first few characters but not the
true value of the range it still completes the macro even though the
answer is wrong. The named range "datacorrect" only lists "booking" in
this instance but it will complete the macro if someone types "boo" in
Textbox1.

SITUATION 2 [ < ans ] -- Anything typed in fails
'================================vvvvvv======
If Sheet1.Range("datacorrect").Find(ans).Row > ans Then
'================================^^^^^^^======
Situation: If the person types any thing in it wont complete the macro
and sends them straight to "NOGOOD: EVENT"

SITUATION 2 [ = ans ] -- Anything typed in fails
'================================vvvvvv======
If Sheet1.Range("datacorrect").Find(ans).Row = ans Then
'================================^^^^^^^======
Situation: If the person types any thing in it wont complete the macro
and sends them straight to "NOGOOD: EVENT"
 
Not sure what you are trying to do.

You code says:
If the row number where the string variable ans is found is less than the
the string variable ans, then....
Depending what you are entering in TextBox3, you have something like

If 10 < "some string" Then..

What do you expect that to evaluate to ?

Possibly you mean:
If Sheet1.Range("datacorrect").Find(ans).Row < CLng(ans) Then....

NickHK
 
Actually found out that if I do

ans = "13" & TextBox3.Value & "13"
If Sheet1.Range("datacorrect").Find(ans).Row < ans Then

It works the way I wanted it to...I figure the problem was it wasn't
searching the entire contents for whatever reason...since there is a 13
before and after the value it will not bother to search for 13boo13
because it wouldn't exsist but if its typed in the spreadsheet as
13booking13 it works fine...just sorta came to me before i called it
quits for the night...Thanks for your input though!

-Todd

Not sure what you are trying to do.

You code says:
If the row number where the string variable ans is found is less than the
the string variable ans, then....
Depending what you are entering in TextBox3, you have something like

If 10 < "some string" Then..

What do you expect that to evaluate to ?

Possibly you mean:
If Sheet1.Range("datacorrect").Find(ans).Row < CLng(ans) Then....

NickHK

Hello! I am having issues with the following code...It seems that my
statment below isn't working the way it should. Here is the
situation... THE < ans, > ans, = ans is the problem. I need the code to
only match the TRUE completed value of TextBox3... I applogize how
disorganized this appears but there is no better way to present it.

COMPLETED CODE

Private Sub CommandButton1_Click()
On Error GoTo nogood
ans = TextBox3.Value
'================================vvvvvv======
If Sheet1.Range("datacorrect").Find(ans).Row < ans Then
'================================^^^^^^^======
MsgBox "OK"
Unload Me
Exit Sub
End If
nogood: MsgBox "Information Incorrect...Please try again."
Userform1.Show
End Sub



SITUATION 1 [ > ans ] -- Partial Information Completes Macro
'================================vvvvvv======
If Sheet1.Range("datacorrect").Find(ans).Row < ans Then
'================================^^^^^^^======
Situation: If the person types the first few characters but not the
true value of the range it still completes the macro even though the
answer is wrong. The named range "datacorrect" only lists "booking" in
this instance but it will complete the macro if someone types "boo" in
Textbox1.

SITUATION 2 [ < ans ] -- Anything typed in fails
'================================vvvvvv======
If Sheet1.Range("datacorrect").Find(ans).Row > ans Then
'================================^^^^^^^======
Situation: If the person types any thing in it wont complete the macro
and sends them straight to "NOGOOD: EVENT"

SITUATION 2 [ = ans ] -- Anything typed in fails
'================================vvvvvv======
If Sheet1.Range("datacorrect").Find(ans).Row = ans Then
'================================^^^^^^^======
Situation: If the person types any thing in it wont complete the macro
and sends them straight to "NOGOOD: EVENT"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top