Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need help modifying visual basic code. I need to add an if statement to this pro

ID: 648544 • Letter: N

Question

Need help modifying visual basic code. I need to add an if statement to this program so it can check and see if entered numbers are only positive and cannot be negative or non-numeric. Here is my code I have so far. Any help is appreciated.

Public Class Form1


Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

Dim a As Integer

a = InputBox("Enter the snowfall totals month by month: ")
  
ListBox1.Items.Add(a)

End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

Dim Total As Integer
For Each Str As String In ListBox1.Items
Total = Total + CInt(Str)
Next
TextBox1.Text = Total
End Sub
End Class

Public Class Form1


Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

Dim a As Integer

a = InputBox("Enter the snowfall totals month by month: ")
  
ListBox1.Items.Add(a)

End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

Dim Total As Integer
For Each Str As String In ListBox1.Items
Total = Total + CInt(Str)
Next
TextBox1.Text = Total
End Sub
End Class

Explanation / Answer

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

Dim a As Integer

Dim numeric As Boolean

a = InputBox("Enter the snowfall totals month by month: ")

numeric=IsNumeric(a)

If numeric=True Then

If a>0 Then
  
ListBox1.Items.Add(a)

End If

End If

End Sub

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote