Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

multiple of 10000

Status
Not open for further replies.

barbola

Technical User
Feb 27, 2003
1,132
0
0
CA
Can someone help me validate a text box? I want my user to enter multiples of 10,000 (ie not 35,000).

thanks!

Thanks!
Barb E.
 
In this case you can use the mod Math function. SAy you enter X. If X mod 10000 <> 0 then it is not a multiple of 10000.

The mod function returns the remander of a division function. (ie 17 mod 8 = 1)
 
Use the mod operator.
Code:
Private Sub Text1_Validate(Cancel As Boolean)
   If Val(Text1.Text) Mod 10000 = 0 Then
      MsgBox "Good"
   Else
      MsgBox "Bad"
   End If
End Sub


zemp
 
Thanks - I will take a look at both options!

Thanks!
Barb E.
 
Just get them to put the leading digits in and multiply programmatically!

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'

for steam enthusiasts
 
in case of Validate it might be usefull to check if it is numeric first:

Private Sub Text1_Validate(Cancel As Boolean)
Dim strText As String
Dim blnOK As Boolean

strText = Text1.Text

If IsNumeric(strText) Then
blnOK = (Val(strText) Mod 10000 = 0)
Else
blnOK = False
End If

Cancel = Not blnOK

End Sub

You might want to customize handling of zero and empty.

vladk
 
Good idea! Wouldn't want anyone to enter their name instead of a number! Sorry I'm still learning this stuff and my boss thinks I'm a pro and asks for all kinds of validation stuff as if the users are idiots...I guess that's the way its supposed to be though.

Thanks!
Barb E.
 
hmmm...

I would do this...
Code:
Private Sub Text1_Validate(Cancel As Boolean)
  Dim V As Double
  V = Val(Text1.Text)
  If IsNumeric(strText) Then
    While V Mod 10000
      V = V * 10
    Wend
    Text1 = V
  Else
    '''MsgBox "Hey!!! Did I say a NAME??? NOooo... Enter a #@!$# number!!!" ';-)
    Cancel = True
  End If
End Sub

That way if the forget a 0 (or four 0's for that matter) it will add it for them :)

*Note: The 'Commented OUT' message box is a joke... not suggested for use in a bussiness app ;-)

Have Fun, Be Young... Code BASIC
-Josh

cubee101.gif


PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
well... on the other hand... you may want to check for negative and zero numbers too...

Code:
Private Sub Text1_Validate(Cancel As Boolean)
  Dim V As Double
  V = [b]Abs[/b](Val(Text1.Text))
  If IsNumeric(strText) [b]And V[/b] Then
    While V Mod 10000
      V = V * 10
    Wend
    Text1 = V
  Else
    Cancel = True
  End If
End Sub

Have Fun, Be Young... Code BASIC
-Josh

cubee101.gif


PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
haha funny Cube/Josh. I got what I needed to make it work just fine thanks! Just for fun I think I'll use your msgbox in one of my apps and see what happens.



Thanks!
Barb E.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top