[b][red]This message was edited by curtw at 2006-9-23 23:21:50[/red][/b][hr]
I am new to Visual Basic and I know what I want to do, but do not know how to achieve it. I would like to know if I can set a restriction on a textbox where its value cannot be negative. For instance, like a checking account where the balance cannot be negative.
Comments
: I am new to Visual Basic and I know what I want to do, but do not know how to achieve it. I would like to know if I can set a restriction on a textbox where its value cannot be negative. For instance, like a checking account where the balance cannot be negative.
-----------------------------------------------------------------------
Hi,
[code]
Private Sub Text1_Change()
If Val(Text1) < 0.01 Then Text1 = "0.00"
End Sub
[/code]
You can't enter a negative number with the above code. ;-) :-)
[b][blue]
I've just discovered that once the textbox is "0.00" you have to
use the arrow keys to get past the decimal point to enter anything between 0.01 and 1.00
[/blue][/b]
Regards,
Dr M.
: : I am new to Visual Basic and I know what I want to do, but do not know how to achieve it. I would like to know if I can set a restriction on a textbox where its value cannot be negative. For instance, like a checking account where the balance cannot be negative.
:
: -----------------------------------------------------------------------
: Hi,
:
: [code]
: Private Sub Text1_Change()
: If Val(Text1) < 0.01 Then Text1 = "0.00"
: End Sub
: [/code]
:
: You can't enter a negative number with the above code. ;-) :-)
: [b][blue]
: I've just discovered that once the textbox is "0.00" you have to
: use the arrow keys to get past the decimal point to enter anything between 0.01 and 1.00
: [/blue][/b]
:
:
: Regards,
:
: Dr M.
:
:
:
:
you may be better using the lostfocus event, that way editting the textbox is not weird - and use the Sgn (sign) and Abs (absolute value) funcs. to force and negative number to be positive.
[code]
Private Sub Text1_LostFocus()
If IsNumeric(Me.Text1.Text) Then
If Sgn(Me.Text1.Text) = -1 Then Me.Text1.Text = Abs(Me.Text1.Text)
End If
End Sub
[/code]