Verifying user input

warpedone

Board Regular
I'm an idiot and can't figure out what's wrong with this. I want to ask for 3 angles of a triangle and make sure they total 180 degrees and if not, ask again.

what's wrong with this? I get caught in an infinite loop

Do Until j = 180
angleABC = InputBox("Enter the Angle ABC (in degrees)")
angleBCA = InputBox("Enter the Angle BCA (in degrees)")
angleCAB = InputBox("Enter the Angle CAB (in degrees)")
j = angleABC + angleBCA + angleCAB
Loop

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
If you dimension the variables as Double (or Integer if you're only looking at whole numbers), it'll work. Since you didn't declare them at all, they're strings, and the + was concatenating the strings. Hope that helps!

The only problem with dimensioning the variables as a number format is if the user hits Cancel, it will generate a Type Mismatch error.

Perhaps:

Code:
``````Sub test()
Dim angleabc, angleBCA, angleCAB
Do Until j = 180
angleabc = InputBox("Enter the Angle ABC (in degrees)")
angleBCA = InputBox("Enter the Angle BCA (in degrees)")
angleCAB = InputBox("Enter the Angle CAB (in degrees)")
j = Val(angleabc) + Val(angleBCA) + Val(angleCAB)
If j <> 180 Then MsgBox "Total of all angles must equal 180"
Loop
End Sub``````

Thanks, told you I was an idiot.

Replies
11
Views
690
Replies
6
Views
12K
Replies
5
Views
788
Replies
1
Views
302
Replies
4
Views
3K

1,203,326
Messages
6,054,747
Members
444,748
Latest member
knowak87

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.

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

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