组合框不会更新我的文本框. [英] Combobox won't update my textboxes.
问题描述
打招呼,我几乎完成了我的IT项目,但是我的代码有一个小问题,使代码无法完成.我正在尝试创建一个发票程序,我已经做了几乎所有的事情,但是问题是当我更改我的值时 项(在我的情况下为食品)的文本框值(成本)不会自动更新.我需要更改数量,以便它可以自我更新.这是代码,请提前感谢:
Greetings, I have almost finished my IT project but I am having a little problem with the code which keeps from getting it done. I am trying to create an invoice program and I have done pretty much everything but the problem is when I change my values of items (in my case foods) the textbox values (cost) wont automatically update itself. I need to change the quantiny so that it would update itself. Here is the code,thanks in advance:
Public Class Form2
Public price1 As Double
Public price2 As Double
Public price3 As Double
Public price4 As Double
Public subtotal As Double
Public tax1 As Double
Public tax2 As Double
Public total As Double
Public foodPrice1 As Double
Public foodPrice2 As Double
Public foodPrice3 As Double
Public foodPrice4 As Double
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
If ComboBox1.Text = "Pizza($10)" Then
foodPrice1 = 10
ElseIf ComboBox1.Text = "Hamburger($6)" Then
foodPrice1 = 6
ElseIf ComboBox1.Text = "Wrap($3)" Then
foodPrice1 = 3
ElseIf ComboBox1.Text = "Coke($2)" Then
foodPrice1 = 2
ElseIf ComboBox1.Text = "Lemonade($1)" Then
foodPrice1 = 1
End If
TextBox1.Text = price1
End Sub
Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox2.SelectedIndexChanged
If ComboBox2.Text = "Pizza($10)" Then
foodPrice2 = 10
ElseIf ComboBox2.Text = "Hamburger($6)" Then
foodPrice2 = 6
ElseIf ComboBox2.Text = "Wrap($3)" Then
foodPrice2 = 3
ElseIf ComboBox2.Text = "Coke($2)" Then
foodPrice2 = 2
ElseIf ComboBox2.Text = "Lemonade($1)" Then
foodPrice2 = 1
End If
TextBox2.Text = price2
subtotalBox.Text = subtotal
bmtBox.Text = tax1
ittBox.Text = tax2
totalBox.Text = total
End Sub
Private Sub ComboBox3_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox3.SelectedIndexChanged
If ComboBox3.Text = "Pizza($10)" Then
foodPrice3 = 10
ElseIf ComboBox3.Text = "Hamburger($6)" Then
foodPrice3 = 6
ElseIf ComboBox3.Text = "Wrap($3)" Then
foodPrice3 = 3
ElseIf ComboBox3.Text = "Coke($2)" Then
foodPrice3 = 3
ElseIf ComboBox3.Text = "Lemonade($1)" Then
foodPrice3 = 1
End If
TextBox3.Text = price3
subtotalBox.Text = subtotal
bmtBox.Text = tax1
ittBox.Text = tax2
totalBox.Text = total
End Sub
Private Sub ComboBox4_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox4.SelectedIndexChanged
If ComboBox4.Text = "Pizza($10)" Then
foodPrice4 = 10
ElseIf ComboBox4.Text = "Hamburger($6)" Then
foodPrice4 = 6
ElseIf ComboBox4.Text = "Wrap($3)" Then
foodPrice4 = 4
ElseIf ComboBox4.Text = "Coke($2)" Then
foodPrice4 = 4
ElseIf ComboBox4.Text = "Lemonade($1)" Then
foodPrice4 = 1
End If
TextBox4.Text = price4
subtotalBox.Text = subtotal
bmtBox.Text = tax1
ittBox.Text = tax2
totalBox.Text = total
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
TextBox1.Text = price1
End Sub
Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
TextBox2.Text = price2
End Sub
Private Sub TextBox3_TextChanged(sender As Object, e As EventArgs) Handles TextBox3.TextChanged
TextBox3.Text = price3
End Sub
Private Sub TextBox4_TextChanged(sender As Object, e As EventArgs) Handles TextBox4.TextChanged
TextBox4.Text = price4
End Sub
Private Sub ComboBox11_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox11.SelectedIndexChanged
price1 = foodPrice1 * ComboBox11.Text
TextBox1.Text = price1
subtotal = price1 + price2 + price3 + price4
subtotalBox.Text = subtotal
tax1 = subtotal / 10
bmtBox.Text = tax1
tax2 = subtotal / 20
ittBox.Text = tax2
total = subtotal + tax1 + tax2
totalBox.Text = total
End Sub
Private Sub ComboBox12_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox12.SelectedIndexChanged
price2 = foodPrice2 * ComboBox12.Text
TextBox2.Text = price2
subtotal = price1 + price2 + price3 + price4
subtotalBox.Text = subtotal
tax1 = subtotal / 10
bmtBox.Text = tax1
tax2 = subtotal / 20
ittBox.Text = tax2
total = subtotal + tax1 + tax2
totalBox.Text = total
End Sub
Private Sub ComboBox13_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox13.SelectedIndexChanged
price3 = foodPrice3 * ComboBox13.Text
TextBox3.Text = price3
subtotal = price1 + price2 + price3 + price4
subtotalBox.Text = subtotal
tax1 = subtotal / 10
bmtBox.Text = tax1
tax2 = subtotal / 20
ittBox.Text = tax2
total = subtotal + tax1 + tax2
totalBox.Text = total
End Sub
Private Sub ComboBox14_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox14.SelectedIndexChanged
price4 = foodPrice4 * ComboBox14.Text
TextBox4.Text = price4
subtotal = price1 + price2 + price3 + price4
subtotalBox.Text = subtotal
tax1 = subtotal / 10
bmtBox.Text = tax1
tax2 = subtotal / 20
ittBox.Text = tax2
total = subtotal + tax1 + tax2
totalBox.Text = total
End Sub
Private Sub subtotalBox_TextChanged(sender As Object, e As EventArgs) Handles subtotalBox.TextChanged
subtotal = price1 + price2 + price3 + price4
subtotalBox.Text = subtotal
End Sub
Private Sub bmtBox_TextChanged(sender As Object, e As EventArgs) Handles bmtBox.TextChanged
tax1 = subtotal / 10
bmtBox.Text = tax1
End Sub
Private Sub ittBox_TextChanged(sender As Object, e As EventArgs) Handles ittBox.TextChanged
tax2 = subtotal / 20
ittBox.Text = tax2
End Sub
Private Sub totalBox_TextChanged(sender As Object, e As EventArgs) Handles totalBox.TextChanged
total = subtotal + tax1 + tax2
totalBox.Text = total
End Sub
Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click
End Sub
Private Sub Label2_Click(sender As Object, e As EventArgs) Handles Label2.Click
End Sub
Private Sub Label3_Click(sender As Object, e As EventArgs) Handles Label3.Click
End Sub
Private Sub Label8_Click(sender As Object, e As EventArgs) Handles Label8.Click
End Sub
Private Sub Label12_Click(sender As Object, e As EventArgs) Handles Label12.Click
End Sub
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub Label13_Click(sender As Object, e As EventArgs) Handles Label13.Click
End Sub
Private Sub Label10_Click(sender As Object, e As EventArgs) Handles Label10.Click
End Sub
Private Sub Label14_Click(sender As Object, e As EventArgs) Handles Label14.Click
End Sub
End Class
推荐答案
我正在尝试创建发票程序,并且我已经完成了几乎所有的工作,但是问题是当我更改项目的值时(在我的情况下为食品)文本框值(费用)不会自动更新.我需要更改数量,以便 它会自我更新.这是代码,请提前感谢:
I am trying to create an invoice program and I have done pretty much everything but the problem is when I change my values of items (in my case foods) the textbox values (cost) wont automatically update itself. I need to change the quantiny so that it would update itself. Here is the code,thanks in advance:
选择一个组合框作为示例.说明选择组合框时应更新哪个文本框.使用代码中显示的控件名称,而不是通用说明.
Choose one of the comboboxes as an example. Explain which text box should update when the combobox selection is made. Use the names of the controls as they appear in the code, not generic descriptions.
这篇关于组合框不会更新我的文本框.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!