Comparing values in Textbox controls

dave8

Active Member
Joined
Jul 8, 2007
Messages
275
I have two input textboxes on my worksheet. Actually, they are not used for "Text" input pe se. I'm using it to input numeric values and making a comparison. In the first input box (textbox1) if I enter a value of 20, and in the second input box (textbox2) a value of 7.

The code looks something like this:

if frame1.controls("textbox1").text > frame1.controls("textbox2").text
msgbox("Textbox1 > Textbox2")
else
msgbox("Textbox1 < Textbox2")
End if


How is it that this statement evaluates to the else (Textbox1 < Textbox2) ? Do I need to convert the input into numeric?? How to do this?
 
Hi

As strings "20" < "7". If you want to compare the numbers 20 and 7, try:

Code:
If Val(frame1.controls("textbox1").text) > Val(frame1.controls("textbox2").text) Then
 
Upvote 0
Thank you. This works well. I am using the Microsoft Forms 2.0 Frame in which I have the Textboxes contained in the frame control. I use it to be able to tab between the two fields. But, when running it on 2007, it crashes. How to make it compatible so 2007 will recognize the ActiveX controls?
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top