麻辣家族討論版版's Archiver

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

[b]回復 [url=http://forum.twbts.com/redirect.php?goto=findpost&pid=118719&ptid=23643]1#[/url] [i]074063[/i] [/b]

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

[attach]34817[/attach]

singo1232001 發表於 2022-4-30 02:58

[i=s] 本帖最後由 singo1232001 於 2022-4-30 02:59 編輯 [/i]

[b]回復 [url=http://forum.twbts.com/redirect.php?goto=findpost&pid=118719&ptid=23643]1#[/url] [i]074063[/i] [/b]

頁: [1]

麻辣家族討論版版為 麻辣學園 網站成員  由 昱得資訊工作室 © Since 1993 所提供