05-02-23, 06:31 PM
(05-02-23, 10:22 AM)danti كتب : السلام عليكم ورحمة الله وبركاته
أرجو أن تكون بأتم صحة وعافية..
هل يوجد كود يختصر عليك كتابة الأكواد المتكررة..
مثال.. عندي 20 ليبل وجميعها بنفس الاسم بخلاف تغيير الرقم:-
كود :
If Lbl_S_1.Text = "8" Then
Txt_MU.Text = "1"
End If
If Lbl_S_2.Text = "8" Then
Txt_MU.Text = "1"
End If
If Lbl_S_3.Text = "8" Then
Txt_MU.Text = "1"
End If
If Lbl_S_4.Text = "8" Then
Txt_MU.Text = "1"
End If
If Lbl_S_5.Text = "8" Then
Txt_MU.Text = "1"
End If
If Lbl_S_6.Text = "8" Then
Txt_MU.Text = "1"
End If
If Lbl_S_7.Text = "8" Then
Txt_MU.Text = "1"
End If
If Lbl_S_8.Text = "8" Then
Txt_MU.Text = "1"
End If
If Lbl_S_9.Text = "8" Then
Txt_MU.Text = "1"
End If
If Lbl_S_10.Text = "8" Then
Txt_MU.Text = "1"
End If
If Lbl_S_11.Text = "8" Then
Txt_MU.Text = "1"
End If
If Lbl_S_12.Text = "8" Then
Txt_MU.Text = "1"
End If
If Lbl_S_13.Text = "8" Then
Txt_MU.Text = "1"
End If
If Lbl_S_14.Text = "8" Then
Txt_MU.Text = "1"
End If
If Lbl_S_15.Text = "8" Then
Txt_MU.Text = "1"
End If
If Lbl_S_16.Text = "8" Then
Txt_MU.Text = "1"
End If
If Lbl_S_17.Text = "8" Then
Txt_MU.Text = "1"
End If
If Lbl_S_18.Text = "8" Then
Txt_MU.Text = "1"
End If
If Lbl_S_19.Text = "8" Then
Txt_MU.Text = "1"
End If
If Lbl_S_20.Text = "8" Then
Txt_MU.Text = "1"
End If
Txt_Total.Text = Val(Txt_NF.Text) + Val(Txt_ED.Text) + Val(Txt_NS.Text) + Val(Txt_MU.Text)
هل هناك كود يختصر كل هذه الأكواد المكررة؟
وأيضاً كما في المثال التالي:-
كود :
If Lbl_S_1.Text = "7" Or Lbl_S_1.Text = "9" Or Lbl_S_1.Text = "10" Or Lbl_S_1.Text = "11" Or Lbl_S_1.Text = "12" Then
Txt_ED.Text = "1"
End If
If Lbl_S_2.Text = "7" Or Lbl_S_2.Text = "9" Or Lbl_S_2.Text = "10" Or Lbl_S_2.Text = "11" Or Lbl_S_2.Text = "12" Then
Txt_ED.Text = Val(Txt_ED.Text) + 1
End If
If Lbl_S_3.Text = "7" Or Lbl_S_3.Text = "9" Or Lbl_S_3.Text = "10" Or Lbl_S_3.Text = "11" Or Lbl_S_3.Text = "12" Then
Txt_ED.Text = Val(Txt_ED.Text) + 1
End If
If Lbl_S_4.Text = "7" Or Lbl_S_4.Text = "9" Or Lbl_S_4.Text = "10" Or Lbl_S_4.Text = "11" Or Lbl_S_4.Text = "12" Then
Txt_ED.Text = Val(Txt_ED.Text) + 1
End If
If Lbl_S_5.Text = "7" Or Lbl_S_5.Text = "9" Or Lbl_S_5.Text = "10" Or Lbl_S_5.Text = "11" Or Lbl_S_5.Text = "12" Then
Txt_ED.Text = Val(Txt_ED.Text) + 1
End If
If Lbl_S_6.Text = "7" Or Lbl_S_6.Text = "9" Or Lbl_S_6.Text = "10" Or Lbl_S_6.Text = "11" Or Lbl_S_6.Text = "12" Then
Txt_ED.Text = Val(Txt_ED.Text) + 1
End If
If Lbl_S_7.Text = "7" Or Lbl_S_7.Text = "9" Or Lbl_S_7.Text = "10" Or Lbl_S_7.Text = "11" Or Lbl_S_7.Text = "12" Then
Txt_ED.Text = Val(Txt_ED.Text) + 1
End If
If Lbl_S_8.Text = "7" Or Lbl_S_8.Text = "9" Or Lbl_S_8.Text = "10" Or Lbl_S_8.Text = "11" Or Lbl_S_8.Text = "12" Then
Txt_ED.Text = Val(Txt_ED.Text) + 1
End If
If Lbl_S_9.Text = "7" Or Lbl_S_9.Text = "9" Or Lbl_S_9.Text = "10" Or Lbl_S_9.Text = "11" Or Lbl_S_9.Text = "12" Then
Txt_ED.Text = Val(Txt_ED.Text) + 1
End If
If Lbl_S_10.Text = "7" Or Lbl_S_10.Text = "9" Or Lbl_S_10.Text = "10" Or Lbl_S_10.Text = "11" Or Lbl_S_10.Text = "12" Then
Txt_ED.Text = Val(Txt_ED.Text) + 1
End If
Txt_Total.Text = Val(Txt_NF.Text) + Val(Txt_ED.Text) + Val(Txt_NS.Text) + Val(Txt_MU.Text)
لأني سوف أستخدم أكثر من 40 Label
أرجو أن تكون الفكرة وصلت.. كما أعتقد أن هناك حل.. ولكن قلة خبرتي تجعلني أبذل جهداً ووقتاً في البرمجة.
فعلاً كما يقول المثل الشعبي ( أهل العقول في راحه )
سؤال قد يفتح لك بابا للتفكير الصحيح
من أين تاتي بالبيانات لتضعها في كل هذه الليبليبليبليبليبلات (جمعLabel)؟
اتمنى انك فهمت المقصود والا ...........!

