ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   check number on a form (https://www.excelbanter.com/excel-programming/329515-check-number-form.html)

inquirer

check number on a form
 
I'm not quite sure of the correct terms but I want to test if a number
entered on a form is log of a power 10
ie, I want to know if the number entered is 0.001,0.01,0.1,1,10,100 etc. If
then number is not one of this series, then the user has to go back and
enter an acceptable number.
Thanks
Chris



William[_2_]

check number on a form
 

Assuming the number on the form is entered into a text box (TextBox1) and a
command button on the form (CommandButton1) triggers the test you refer to
then perhaps....

Private Sub CommandButton1_Click()
Dim s As Double
s = Application.WorksheetFunction.Log(Val(TextBox1))
If Int(s) = s Then
MsgBox "Number OK"
Else
MsgBox "Number not OK"
End If
End Sub

(Some error checking will be required that a number has been entered into
the text box.)
--


XL2003
Regards

William



"inquirer" wrote in message
...
I'm not quite sure of the correct terms but I want to test if a number
entered on a form is log of a power 10
ie, I want to know if the number entered is 0.001,0.01,0.1,1,10,100 etc.
If then number is not one of this series, then the user has to go back and
enter an acceptable number.
Thanks
Chris




Toppers

check number on a form
 
Hi,
This routine will check 10 to the power of -10 to +10. It returns
TRUE or FALSE.

Function Valid10(v) As Boolean
For i = -10 To 10 Step 1
If v = Application.Power(10, i) Then
Valid10 = True
Exit Function
End If
Next i
Valid10 = False
End Function


For example, =Valid10(A1) in cell B1 will check value of A1

or in VBA:


Sub Test()
Dim valid as Boolean
MyValue=0.0001
valid=valid10(MyValue)
End sub


HTH

"inquirer" wrote:

I'm not quite sure of the correct terms but I want to test if a number
entered on a form is log of a power 10
ie, I want to know if the number entered is 0.001,0.01,0.1,1,10,100 etc. If
then number is not one of this series, then the user has to go back and
enter an acceptable number.
Thanks
Chris




inquirer

check number on a form
 
The value of these newsgroups and the people who help amateurs like me is
immeasurable.
Here was I thinking I was asking something near impossible and within a few
hours I get 2 great solutions.

Thank you
Chris

"William" wrote in message
...

Assuming the number on the form is entered into a text box (TextBox1) and
a command button on the form (CommandButton1) triggers the test you refer
to then perhaps....

Private Sub CommandButton1_Click()
Dim s As Double
s = Application.WorksheetFunction.Log(Val(TextBox1))
If Int(s) = s Then
MsgBox "Number OK"
Else
MsgBox "Number not OK"
End If
End Sub

(Some error checking will be required that a number has been entered into
the text box.)
--


XL2003
Regards

William



"inquirer" wrote in message
...
I'm not quite sure of the correct terms but I want to test if a number
entered on a form is log of a power 10
ie, I want to know if the number entered is 0.001,0.01,0.1,1,10,100 etc.
If then number is not one of this series, then the user has to go back
and enter an acceptable number.
Thanks
Chris







All times are GMT +1. The time now is 01:03 PM.

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