ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Qn: Ensure Number is valid for a circle?? (https://www.excelbanter.com/excel-programming/307485-qn-ensure-number-valid-circle.html)

Michael Vaughan

Qn: Ensure Number is valid for a circle??
 
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!



Tom Ogilvy

Ensure Number is valid for a circle??
 
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.

--
Regards,
Tom Ogilvy

"Michael Vaughan" wrote in message
...
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!





Ron de Bruin

Ensure Number is valid for a circle??
 
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


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Michael Vaughan" wrote in message ...
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!





NickHK

Ensure Number is valid for a circle??
 
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

"Michael Vaughan" wrote in message
...
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!






All times are GMT +1. The time now is 02:11 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com