Does anyone know what type of character a decimal is? I'm working on something for VB, and I need to allow a text box to accept only numbers, control characters, and decimals, but I can't figure out what a decimal is classified as.
Thanks.
Does anyone know what type of character a decimal is? I'm working on something for VB, and I need to allow a text box to accept only numbers, control characters, and decimals, but I can't figure out what a decimal is classified as.
Thanks.
Under the Patronage of Leonidas the Lion|Patron of Imperator of Rome - Dewy - Crazyeyesreaper|American and Proud
Use a KeyPress event, like this one:
Code:PrivateSub txtOrder_KeyPress(ByVal sender AsObject, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtOrder.KeyPress Dim keyInput AsString = e.KeyChar.ToString() If[Char].IsDigit(e.KeyChar) Then ' Digits are OK ElseIf e.KeyChar = vbBack Then 'Backspace is OK ElseIf e.KeyChar = "."Then 'Period is OK Else e.Handled = True 'cancel input EndIf EndSub
Ah, so I can define strings with the e.KeyChar? Very nice! Thanks!
Under the Patronage of Leonidas the Lion|Patron of Imperator of Rome - Dewy - Crazyeyesreaper|American and Proud
With that particular event you can. Each event defines specific arguments that can be checked for conditions.
Thats what this line defines, obviously the part that matters is KeyPressEventArgs and that is assigned to the variable e:
The "sender AsObject" part of that line returns the object that called the event as a variable named sender. So for example if you had multiple buttons firing the same event (using AddHandler) then you would know exactly which object called the event, and can then manipulate things based on that object.PrivateSub txtOrder_KeyPress(ByVal sender AsObject, ByVal e As System.Windows.Forms.KeyPressEventArgs
For example, a form with 2 green buttons on it and this code:
Code:PrivateSub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click MsgBox(sender.name) If sender.backcolor = Color.Green Then sender.backcolor = Color.Red ElseIf sender.backcolor = Color.Green Then sender.backcolor = Color.Green EndIf EndSub