In: Computer Science
Dim Digit1 As Double Dim Digit2 As Double Dim Digit3 As Double Dim Digit4 As Double Dim Digit5 As Double Digit1 = ((txtboxInput.Text) Mod 100000) / 10000 Digit2 = ((txtboxInput.Text) Mod 10000) / 1000 Digit3 = ((txtboxInput.Text) Mod 1000) / 100 Digit4 = ((txtboxInput.Text) Mod 100) / 10 Digit5 = (txtboxInput.Text Mod 10) lblDigit1.Text = Math.Truncate(Digit1) lblDigit2.Text = Math.Truncate(Digit2) lblDigit3.Text = Math.Truncate(Digit3) lblDigit4.Text = Math.Truncate(Digit4) lblDigit5.Text = Math.Truncate(Digit5) End Sub Private Sub txtboxInput_TextChanged(sender As Object, e As EventArgs) Handles txtboxInput.TextChanged lblDigit1.Text = "" lblDigit2.Text = "" lblDigit3.Text = "" lblDigit4.Text = "" lblDigit5.Text = ""
I have to put were letters can be put in textbox. Its throwing an exception on Mod. I cant figure out what I need to do so when you input letters it does not throw error.
Dear Student ,
As per the requirement submitted above , kindly find the below solution.
NOTE :This application is designed for demonstration purpose only make changes as per requirement.
Here a new Windows Forms Application in VB is created using Visual Studio.Below are the forms
1.Form1.vb[Design]
2.Form1.vb
'VB class
Public Class Form1
'When text in the textbox is changed then clear labels
Private Sub txtboxInput_TextChanged(sender As Object, e As
EventArgs) Handles txtboxInput.TextChanged
lblDigit1.Text = ""
lblDigit2.Text = ""
lblDigit3.Text = ""
lblDigit4.Text = ""
lblDigit5.Text = ""
End Sub
'Button click event
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
Dim Digit1 As Double
Dim Digit2 As Double
Dim Digit3 As Double
Dim Digit4 As Double
Dim Digit5 As Double
Dim Digit As Double
'checking number using TryParse
If (Integer.TryParse(txtboxInput.Text, Digit)) Then
'if numeric number is entered then do this
Digit1 = ((txtboxInput.Text) Mod 100000) / 10000
Digit2 = ((txtboxInput.Text) Mod 10000) / 1000
Digit3 = ((txtboxInput.Text) Mod 1000) / 100
Digit4 = ((txtboxInput.Text) Mod 100) / 10
Digit5 = (txtboxInput.Text Mod 10)
lblDigit1.Text = Math.Truncate(Digit1)
lblDigit2.Text = Math.Truncate(Digit2)
lblDigit3.Text = Math.Truncate(Digit3)
lblDigit4.Text = Math.Truncate(Digit4)
lblDigit5.Text = Math.Truncate(Digit5)
Else
'When non numeric number is entered
MessageBox.Show("No alphabets are allowed")
End If
End Sub
End Class
======================================================
Output : Run application using F5 and will get the screen as shown below
Screen 1 :
Screen 2:Screen when non numeric numbers are entered
Screen 3:Screen when numeric number is entered
NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.