Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27554

VS 2010 Hello, Trying to Stop my calculations in Textbox when Error Messgae is Triggered

$
0
0
For example, when I enter a non numeric number in the input box or when qtysold is < and i get the error, my textboxes still do their calculations when I dont want them to. How would i fix this?

This is what I have.

Public Class Form1
Dim FLAG As String
Dim loc, qtysold, invalidboxes As Integer
Dim ordertotal, price, totalprice As Single
Dim expshipping As Single
Dim orders As Single
Dim salestax As Single
Dim shipping As Single

Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click

End Sub

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


Dim i As Integer
FLAG = "no"
For i = 0 To 10
If TextBox1.Text = ComboBox4.Items(i) Then
FLAG = "yes"
loc = i
End If
Next
MsgBox(ComboBox3.Items(loc))
If FLAG = "yes" Then
Call qtycheck()
Else
MsgBox("Error")


End If

salestax = 0.0825




totalprice = Val(qtysold) * ComboBox2.Items(loc)
TextBox2.Text = totalprice.ToString("C")

ordertotal = totalprice + ordertotal
TextBox3.Text = ordertotal.ToString("C")


orders = orders + 1








If CheckBox1.Checked = True Then
expshipping = 5
End If




If CheckBox2.Checked = True Then
salestax = ordertotal * salestax
TextBox4.Text = salestax.ToString("C")
Else
salestax = 0
End If



If ordertotal <= 100 Then
shipping = 4.99
ElseIf ordertotal <= 250 Then
shipping = 3.49
ElseIf ordertotal <= 500 Then
shipping = 2.29
End If

TextBox5.Text = shipping.ToString("C")
TextBox3.Text = (ordertotal + shipping + salestax + expshipping).ToString("C")



End Sub
Sub qtycheck()


Try
qtysold = InputBox("How Many Boxes?")


If ComboBox1.Items(loc) > qtysold Then
ComboBox1.Items(loc) = ComboBox1.Items(loc) - qtysold
MsgBox("items sold")




ElseIf ComboBox1.Items(loc) < qtysold Then

invalidboxes = MsgBox("error", vbRetryCancel)


End If

Catch ex As Exception
IsNumeric(qtysold)
MsgBox("Error")
End Try


End Sub




Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox2.SelectedIndexChanged

End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Form2.textbox1.text = orders
Form2.textbox2.text = ordertotal.ToString("C")
Form2.textbox3.text = (ordertotal / orders).ToString("C")

Me.Hide()
Form2.Show()
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs)


TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
TextBox5.Clear()

ComboBox1.SelectedIndex = -1

End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

End Sub
End Class

Viewing all articles
Browse latest Browse all 27554

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>