Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie: Strange behavior of a comparison

Status
Not open for further replies.

agual

Programmer
Nov 1, 2001
77
ES
In the following snippet

Code:
option explicit
dim i: i=5
dim f: f=inputbox ("","",0) 
msgbox "f=" & f & "   i="& i & "   f<i is " & (f<i) & "   f<5 is " & (F<5)
Why f<i is always False, no matter which value i enter?



Antoni
 
Variables are case sensitive. You assign a value to "f", then in the msgbox, you use "F". Since "F" is not initialized it will have a null value.

The question is: why did "option explicit" not warn you about "F" not being declared?
 
Also, the input box is going to assign a string value to "f"; convert it to an integer (or other type as needed) before the comparison.

Code:
option explicit
dim i
i=5
dim f
f=inputbox ("","",0)
msgbox "f=" & Cint(f) & "   i="& i & "   f<i is " & (Cint(f)<i) & "   f<5 is " & (f<5)
 
I realized my mistake shortly after I posted! I'm glad my 2nd answer helped.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top