Board logo

標題: TextBox 自動計算問題 [打印本頁]

作者: 074063    時間: 2022-4-27 21:25     標題: TextBox 自動計算問題

' #################################################################################
Private Sub TextBox1_Change()
    If TextBox1.Text = "" Or TextBox11.Text = "" Then TextBox21.Text = ""
    If TextBox1 <> "" Then TextBox21 = Val(TextBox1.Text) - Val(TextBox11)
End Sub
Private Sub TextBox11_Change()
    If TextBox1.Text = "" Or TextBox11.Text = "" Then TextBox21.Text = ""
    If TextBox1 <> "" Then TextBox21 = Val(TextBox1.Text) - Val(TextBox11)
End Sub

Private Sub TextBox2_Change()
    If TextBox2.Text = "" Or TextBox12.Text = "" Then TextBox22.Text = ""
    If TextBox2 <> "" Then TextBox22 = Val(TextBox2.Text) - Val(TextBox12)
End Sub
Private Sub TextBox12_Change()
    If TextBox2.Text = "" Or TextBox12.Text = "" Then TextBox22.Text = ""
    If TextBox2 <> "" Then TextBox22 = Val(TextBox2.Text) - Val(TextBox12)
End Sub

Private Sub TextBox3_Change()
    If TextBox3.Text = "" Or TextBox13.Text = "" Then TextBox23.Text = ""
    If TextBox3 <> "" Then TextBox23 = Val(TextBox3.Text) - Val(TextBox13)
End Sub
Private Sub TextBox13_Change()
    If TextBox3.Text = "" Or TextBox13.Text = "" Then TextBox23.Text = ""
    If TextBox3 <> "" Then TextBox23 = Val(TextBox3.Text) - Val(TextBox13)
End Sub

Private Sub TextBox4_Change()
    If TextBox4.Text = "" Or TextBox14.Text = "" Then TextBox24.Text = ""
    If TextBox4 <> "" Then TextBox24 = Val(TextBox4.Text) - Val(TextBox14)
End Sub
Private Sub TextBox14_Change()
    If TextBox4.Text = "" Or TextBox14.Text = "" Then TextBox24.Text = ""
    If TextBox4 <> "" Then TextBox24 = Val(TextBox4.Text) - Val(TextBox14)
End Sub

Private Sub TextBox5_Change()
    If TextBox5.Text = "" Or TextBox15.Text = "" Then TextBox25.Text = ""
    If TextBox5 <> "" Then TextBox25 = Val(TextBox5.Text) - Val(TextBox15)
End Sub
Private Sub TextBox15_Change()
    If TextBox5.Text = "" Or TextBox15.Text = "" Then TextBox25.Text = ""
    If TextBox5 <> "" Then TextBox25 = Val(TextBox5.Text) - Val(TextBox15)
End Sub

Private Sub TextBox6_Change()
    If TextBox6.Text = "" Or TextBox16.Text = "" Then TextBox26.Text = ""
    If TextBox6 <> "" Then TextBox26 = Val(TextBox6.Text) - Val(TextBox16)
End Sub
Private Sub TextBox16_Change()
    If TextBox6.Text = "" Or TextBox16.Text = "" Then TextBox26.Text = ""
    If TextBox6 <> "" Then TextBox26 = Val(TextBox6.Text) - Val(TextBox16)
End Sub

Private Sub TextBox7_Change()
    If TextBox7.Text = "" Or TextBox17.Text = "" Then TextBox27.Text = ""
    If TextBox7 <> "" Then TextBox27 = Val(TextBox7.Text) - Val(TextBox17)
End Sub
Private Sub TextBox17_Change()
    If TextBox7.Text = "" Or TextBox17.Text = "" Then TextBox27.Text = ""
    If TextBox7 <> "" Then TextBox27 = Val(TextBox7.Text) - Val(TextBox17)
End Sub

Private Sub TextBox8_Change()
    If TextBox8.Text = "" Or TextBox18.Text = "" Then TextBox28.Text = ""
    If TextBox8 <> "" Then TextBox28 = Val(TextBox8.Text) - Val(TextBox18)
End Sub
Private Sub TextBox18_Change()
    If TextBox8.Text = "" Or TextBox18.Text = "" Then TextBox28.Text = ""
    If TextBox8 <> "" Then TextBox28 = Val(TextBox8.Text) - Val(TextBox18)
End Sub

Private Sub TextBox9_Change()
    If TextBox9.Text = "" Or TextBox19.Text = "" Then TextBox29.Text = ""
    If TextBox9 <> "" Then TextBox29 = Val(TextBox9.Text) - Val(TextBox19)
End Sub
Private Sub TextBox19_Change()
    If TextBox9.Text = "" Or TextBox19.Text = "" Then TextBox29.Text = ""
    If TextBox9 <> "" Then TextBox29 = Val(TextBox9.Text) - Val(TextBox19)
End Sub

' #################################################################################

請問以上程式碼能如何精簡, 另外再問 TextBox1~9 求平均值要怎麼寫
作者: lee88    時間: 2022-4-29 16:14

回復 1# 074063

用物件模駔 簡化程式碼
試試看

[attach]34817[/attach]
作者: singo1232001    時間: 2022-4-30 02:58

本帖最後由 singo1232001 於 2022-4-30 02:59 編輯

回復 1# 074063




歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)