Qn: Ensure Number is valid for a circle??

M

Michael Vaughan

Hello Everyone,

I am trying to put in a error trap with a MsgBox to check and see if a
number that is input into a TextBox is NOT a valid number. The TextBox
input is for a Wind Direction such as 040 degrees, OR 180 degrees. Now,
since the direction of the wind is only valid for 360 degrees in a circle,
is there a way to ensure the number they input meets the criteria for a
degree. Example: If they put in the number 36, my wind formula will not
calculate the correct wind correction angle from the runway. The wind
direction MUST be 360 to calculate properly. Can I do a error routine to
ensure that??
Thanks in Advance... mv

PS: Tom... your my man!
 
T

Tom Ogilvy

Unless there is some other information you can use in conjunction with this
value, the best you could do is check that the number is between 0 and 359
inclusive or 1 and 360 inclusive. If your example represents entering 36
when 360 was intended, there is no way to determine that 360 was intended
rather than 36 degrees. If you only accept numbers divisible by 5 or 10,
then you could use the MOD operator to check that. (but 30 vice 300).
Perhaps you could add an additional entry such as N, NW, SE etc and check
your numbers in conjunction with that.

In any event, your code would go in the exit event if the textbox is on a
userform.
 
R

Ron de Bruin

Hi Michael

You can use the Exit event of the textbox to test the input.


Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Not IsNumeric(TextBox1) Or Len(TextBox1) > 3 Then Cancel = True
Me.TextBox1.Text = Format(TextBox1, "000")
End Sub
 
N

NickHK

Michael,
Instead of poping up an Input box, why not show them a userform with a
compass-like graphic and arrow that they can drag around to the correct
direction. You couls even only allow certain increments, 15o say.
No validation required as the must give you a valid response and kudos for
style.

NickHK
 

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

Top