textbox.......
-
what coding do i do so that my textbox take values only between two integers say 0 to 45, any value other than this range gives error.. thanks
Try a NumericUpDown control. If that's not an option you could do this a few ways. For one, in the validating event you could check the value to see if it's okay. Unless you want to disable copy/paste you'll probably have to validate the entry here anyway. The other option would be in the keypress event. You could check if the keypress was a number, if it's not you wouldn't allow it. Secondly, if it's a digit and the current contents including the new digit is > 45 you could dissallow it. If you prevent '-', this would take care of anything less then 0 so you wouldn't really need to worry about it.
-
what coding do i do so that my textbox take values only between two integers say 0 to 45, any value other than this range gives error.. thanks
Hi You Can Use This Code. (Text1 is your TextBox) Private Sub Text1_Change() If Val(Text1.Text) > 45 Then Text1.Text = 45: MsgBox "Please Enter A Number Between 0 to 45", vbCritical End Sub Private Sub Text1_KeyPress(KeyAscii As Integer) Select Case KeyAscii Case 48 To 57: '0 To 9 Case 8: 'Back Space Case 13: 'Enter Case Else: 'Other Keys KeyAscii = 0 End Select End Sub Good Luck Mogtabam
-
Hi You Can Use This Code. (Text1 is your TextBox) Private Sub Text1_Change() If Val(Text1.Text) > 45 Then Text1.Text = 45: MsgBox "Please Enter A Number Between 0 to 45", vbCritical End Sub Private Sub Text1_KeyPress(KeyAscii As Integer) Select Case KeyAscii Case 48 To 57: '0 To 9 Case 8: 'Back Space Case 13: 'Enter Case Else: 'Other Keys KeyAscii = 0 End Select End Sub Good Luck Mogtabam