hello im working on a visual studios project that has multiple forms and i have
ID: 3865899 • Letter: H
Question
hello im working on a visual studios project that has multiple forms and i have most of the project done just need to do the last instructions which i am not sure what to do or what it means.
"Prevent entering anything but numbers in all the text boxes of this assignment by coding the
KeyDown event and suppressing they key. For example you could use a select case statement
as shown below
Select Case e.KeyCode
Case Keys.NumPad0 To Keys.NumPad9
'do nothing
Case Else
Beep()
e.SuppressKeyPress = True
End Select
The above handles the numeric keypad you would still have to code the numbers on the
keyboard Keys.D0 To Keys.D9."
this is what i have for my code...
Option Strict On
Public Class MetersToEnglish
Private Sub ConvertInchesButton_Click(sender As Object, e As EventArgs) Handles ConvertInchesButton.Click
Dim Meters As Double ' To hold the meters
Dim Inches As Double ' To hold the inches
Try
' Get the meters.
Meters = CDbl(MetersText.Text)
' Convert meters to inches.
Inches = MetersToInches(Meters)
' Display the result.
AnswerLabel.Text = (Meters.ToString() & " meters equals " &
Inches.ToString() & " inches.")
Catch
' Display an error message for invalid input.
MessageBox.Show("Error: Enter a numeric value.")
End Try
End Sub
Private Sub CovertFeetButton_Click(sender As Object, e As EventArgs) Handles CovertFeetButton.Click
Dim Meters As Double ' To hold the meters
Dim Feet As Double ' To hold the feet
Try
' Get the meters.
Meters = CDbl(MetersText.Text)
' Convert meters to feet.
Feet = MetersToFeet(Meters)
' Display the result.
AnswerLabel.Text = (Meters.ToString() & " meters equals " &
Feet.ToString() & " feet.")
Catch
' Display an error message for invalid input.
MessageBox.Show("Error: Enter a numeric value.")
End Try
End Sub
Private Sub ConvertYardsButton_Click(sender As Object, e As EventArgs) Handles ConvertYardsButton.Click
Dim Meters As Double ' To hold the meters
Dim Yards As Double ' To hold the yards
Try
' Get the meters.
Meters = CDbl(MetersText.Text)
' Convert meters to yards.
Yards = MetersToYards(Meters)
' Display the result.
AnswerLabel.Text = (Meters.ToString() & " meters equals " &
Yards.ToString() & " yards.")
Catch
' Display an error message for invalid input.
MessageBox.Show("Error: Enter a numeric value.")
End Try
End Sub
Private Sub CloseButton_Click(sender As Object, e As EventArgs) Handles CloseButton.Click
' Close the form.
Me.Close()
End Sub
i am not sure what i being asked to do. Thank you so much in advance
Explanation / Answer
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub feet_Click(sender As Object, e As EventArgs) Handles feet.Click
Dim mtr As Double 'mtr variable with double datatype
Dim feet As Double 'feet variable with double datatype
If Not IsNumeric(TextBox1.Text) Then 'check whether the content of text box is numeric value
Label1.Text = "Please enter numbers only."
TextBox1.Text = "" 'empty the text box after displaying text
Else
mtr = TextBox1.Text 'store the value of text box in mtr
feet = mtr * 3.28 'convert meters to feet
Label1.Text = mtr & " meters= " & feet & " feets" 'display the answers
End If
End Sub
Private Sub Inches_Click(sender As Object, e As EventArgs) Handles Inches.Click
Dim mtr As Double
Dim inches As Double
If Not IsNumeric(TextBox1.Text) Then
Label1.Text = "Please enter numbers only."
TextBox1.Text = ""
Else
mtr = TextBox1.Text
inches = mtr * 39.37
Label1.Text = mtr & " meters= " & inches & " inches"
End If
End Sub
Private Sub Yards_Click(sender As Object, e As EventArgs) Handles Yards.Click
Dim mtr As Double
Dim yards As Double
If Not IsNumeric(TextBox1.Text) Then
Label1.Text = "Please enter numbers only."
TextBox1.Text = ""
Else
mtr = TextBox1.Text
yards = mtr * 1.09
Label1.Text = mtr & " meters= " & yards & " yards"
End If
End Sub
End Class
Use this code to accept only the numeric value from the text box . As IsNumeric() pre built function will check whether the values entered is numeric or not.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.