|
-
Jul 26th, 2005, 12:29 PM
#1
Thread Starter
Frenzied Member
case select question
Hello
I originally had the following code
Code:
Select Case txtCar.Text
Case is <= 2500
msg = MsgBox("Car Price not recommended for this model. Are you sure you want to use this Price", vbQuestion)
Case is <= 4000
save_parameters
NodeBAll.SaveTab2.Enabled = False
NodeBAll.MousePointer = 0
'do nothing
Case Else
msg = MsgBox("Car Price not recommended for this model. Are you sure you want to use this Price", vbQuestion)
End Select
whenever i had a txtcar value of say 35000, it would still og through the second case (case is <=4000). i changed the code to the code below
Code:
Select Case txtCar.Text
Case txtCar.Text <= 2500
msg = MsgBox("Car Price not recommended for this model. Are you sure you want to use this Price", vbQuestion)
Case txtCar.Text <= 4000
save_parameters
NodeBAll.SaveTab2.Enabled = False
NodeBAll.MousePointer = 0
'do nothing
Case Else
msg = MsgBox("Car Price not recommended for this model. Are you sure you want to use this Price", vbQuestion)
End Select
and it works, i was wondering why does not the is operator work?
-
Jul 26th, 2005, 12:49 PM
#2
Re: case select question
because you are comparing the textbox directly means you are dealing with a string and by doing so that means that 35000 is smaller than 4000, try using this line instead.
VB Code:
Select Case Val(txtCar.Text)
casey.
-
Jul 26th, 2005, 12:59 PM
#3
Re: case select question
Does it! It may now work for a value of 35000 but now the case statement won't work for other values (try 1).
A Select Case statement looks for a True value. Think of it like
txtCar.Text = txtCar.Text <= "4000"
which evaluates to
"35000" = "35000" <= "4000"
which evaluates to
"35000" = "True"
which of course is False - thus the Case Else fires.
When you compare numeric strings, "35000" is less than "4000".
Change to a numeric comparison.
VB Code:
Select Case Val(txtcar.Text)
Case Is <= 2500
MsgBox ("<=2500")
Case Is <= 4000
MsgBox ("<=4000")
Case Else
MsgBox ("Else")
End Select
-
Jul 26th, 2005, 04:00 PM
#4
Thread Starter
Frenzied Member
Re: case select question
thanks for the reply
i did not understand your explanation
txtCar.Text = txtCar.Text <= "4000"
which evaluates to
"35000" = "35000" <= "4000"
which evaluates to
"35000" = "True"
should not my code
Code:
Select Case txtCar.Text
Case txtCar.Text <= 2500
msg = MsgBox("Car Price not recommended for this model. Are you sure you want to use this Price", vbQuestion)
Case txtCar.Text <= 4000
save_parameters
NodeBAll.SaveTab2.Enabled = False
NodeBAll.MousePointer = 0
'do nothing
Case Else
msg = MsgBox("Car Price not recommended for this model. Are you sure you want to use this Price", vbQuestion)
End Select
read as follows for a txtcar.text value of "35000"
case txtcar.text <= 4000
which would result in
case "35000" <= 4000
which would result in False and would go to the last statement
i did not understand where we get the extra "35000"
"35000" = "35000" <= "4000"
also how does
Case is <= 2500 differ from Case txtCar.Text <= 2500
i guess use of
Code:
Select Case Val(txtCar.Text)
woudl result in the following implementation
Code:
Select Case Val(txtcar.Text)
Case Is <= 2500
MsgBox ("<=2500")
Case Is <= 4000
MsgBox ("<=4000")
Case Else
MsgBox ("Else")
End Select
as well as
Code:
Select Case Val(txtcar.Text)
Case Val(txtcar.Text)<= 2500
MsgBox ("<=2500")
Case Val(txtcar.Text)<= 4000
MsgBox ("<=4000")
Case Else
MsgBox ("Else")
End Select
-
Jul 27th, 2005, 05:07 AM
#5
Thread Starter
Frenzied Member
Re: case select question
my original code seems to be working now
Select Case txtCar.Text
Case is <= 2500
msg = MsgBox("Car Price not recommended for this model. Are you sure you want to use this Price", vbQuestion)
Case is <= 4000
save_parameters
NodeBAll.SaveTab2.Enabled = False
NodeBAll.MousePointer = 0
'do nothing
Case Else
msg = MsgBox("Car Price not recommended for this model. Are you sure you want to use this Price", vbQuestion)
End Select
!!! how?
i just copy pasted the code
-
Jul 29th, 2005, 01:45 AM
#6
Re: case select question
The text box gives you a string value for testing, not a numeric value
You should use
Select Case Val(txtCar.Text)
Like vbasicgirl sugested.
Try this, maybe you'll see what we mean.
Code:
debug.Print asc("3")
-
Jul 29th, 2005, 05:14 PM
#7
Thread Starter
Frenzied Member
Re: case select question
they both seem to work now !
i will try debug.print asc("3")
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
|