إمكانية إختصار هذا الكود بدالة - ahmedfa71 - 16-04-17
السلام عليكم ورحمة الله وبركاته أعضاء المنتدي
لدي هذا الكود وأريد إختصاره في دالة إن أمكن
PHP كود :
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim ZC, ZE As Integer Try ZC = Integer.Parse(CboZCAT.Text) ZE = Integer.Parse(CBoze.Text)
If ZC = 1 And ZE = 1 Then Txtone.Text = (1500 * 35) / 100.ToString ElseIf ZC = 1 And ZE = 2 Then Txtone.Text = (1520 * 35) / 100.ToString ElseIf ZC = 1 And ZE = 3 Then Txtone.Text = (1540 * 35) / 100.ToString ElseIf ZC = 2 And ZE = 1 Then Txtone.Text = (1560 * 35) / 100.ToString ElseIf ZC = 2 And ZE = 2 Then Txtone.Text = (1580 * 35) / 100.ToString ElseIf ZC = 2 And ZE = 3 Then Txtone.Text = (1600 * 35) / 100.ToString ElseIf ZC = 3 And ZE = 1 Then Txtone.Text = (1620 * 35) / 100.ToString ElseIf ZC = 3 And ZE = 2 Then Txtone.Text = (1640 * 35) / 100.ToString ElseIf ZC = 3 And ZE = 3 Then Txtone.Text = (1660 * 35) / 100.ToString ElseIf ZC = 4 And ZE = 1 Then Txtone.Text = (1680 * 35) / 100.ToString ElseIf ZC = 4 And ZE = 2 Then Txtone.Text = (1700 * 35) / 100.ToString ElseIf ZC = 4 And ZE = 3 Then Txtone.Text = (1745 * 35) / 100.ToString ElseIf ZC = 5 And ZE = 1 Then Txtone.Text = (1790 * 35) / 100.ToString ElseIf ZC = 5 And ZE = 2 Then Txtone.Text = (1850 * 35) / 100.ToString ElseIf ZC = 5 And ZE = 3 Then Txtone.Text = (1910 * 35) / 100.ToString ElseIf ZC = 6 And ZE = 1 Then Txtone.Text = (1970 * 35) / 100.ToString ElseIf ZC = 6 And ZE = 2 Then Txtone.Text = (2040 * 35) / 100.ToString ElseIf ZC = 6 And ZE = 3 Then Txtone.Text = (2100 * 35) / 100.ToString ElseIf ZC = 7 And ZE = 1 Then Txtone.Text = (2170 * 35) / 100.ToString ElseIf ZC = 7 And ZE = 2 Then Txtone.Text = (2240 * 35) / 100.ToString ElseIf ZC = 7 And ZE = 3 Then Txtone.Text = (2300 * 35) / 100.ToString ElseIf ZC = 8 And ZE = 1 Then Txtone.Text = (2380 * 35) / 100.ToString ElseIf ZC = 8 And ZE = 2 Then Txtone.Text = (2460 * 35) / 100.ToString ElseIf ZC = 8 And ZE = 3 Then Txtone.Text = (2530 * 35) / 100.ToString ElseIf ZC = 9 And ZE = 1 Then Txtone.Text = (2610 * 35) / 100.ToString ElseIf ZC = 9 And ZE = 2 Then Txtone.Text = (2700 * 35) / 100.ToString ElseIf ZC = 9 And ZE = 3 Then Txtone.Text = (2780 * 35) / 100.ToString ElseIf ZC = 10 And ZE = 1 Then Txtone.Text = (2850 * 35) / 100.ToString ElseIf ZC = 10 And ZE = 2 Then Txtone.Text = (2920 * 35) / 100.ToString ElseIf ZC = 10 And ZE = 3 Then Txtone.Text = (2990 * 35) / 100.ToString ElseIf ZC = 10 And ZE = 4 Then Txtone.Text = (3060 * 35) / 100.ToString ElseIf ZC = 11 And ZE = 1 Then Txtone.Text = (3070 * 35) / 100.ToString ElseIf ZC = 11 And ZE = 2 Then Txtone.Text = (3130 * 35) / 100.ToString ElseIf ZC = 11 And ZE = 3 Then Txtone.Text = (3190 * 35) / 100.ToString ElseIf ZC = 11 And ZE = 4 Then Txtone.Text = (3250 * 35) / 100.ToString ElseIf ZC = 12 And ZE = 1 Then Txtone.Text = (3320 * 35) / 100.ToString ElseIf ZC = 12 And ZE = 2 Then Txtone.Text = (3380 * 35) / 100.ToString ElseIf ZC = 12 And ZE = 3 Then Txtone.Text = (3450 * 35) / 100.ToString ElseIf ZC = 12 And ZE = 4 Then Txtone.Text = (3530 * 35) / 100.ToString ElseIf ZC = 13 And ZE = 1 Then Txtone.Text = (3540 * 35) / 100.ToString ElseIf ZC = 13 And ZE = 2 Then Txtone.Text = (3640 * 35) / 100.ToString ElseIf ZC = 13 And ZE = 3 Then Txtone.Text = (3730 * 35) / 100.ToString ElseIf ZC = 13 And ZE = 4 Then Txtone.Text = (3830 * 35) / 100.ToString ElseIf ZC = 14 And ZE = 1 Then Txtone.Text = (3920 * 35) / 100.ToString ElseIf ZC = 14 And ZE = 2 Then Txtone.Text = (4000 * 35) / 100.ToString ElseIf ZC = 14 And ZE = 3 Then Txtone.Text = (4080 * 35) / 100.ToString ElseIf ZC = 14 And ZE = 4 Then Txtone.Text = (4160 * 35) / 100.ToString ElseIf ZC = 14 And ZE = 5 Then Txtone.Text = (4240 * 35) / 100.ToString ElseIf ZC = 15 And ZE = 1 Then Txtone.Text = (4340 * 35) / 100.ToString ElseIf ZC = 15 And ZE = 2 Then Txtone.Text = (4430 * 35) / 100.ToString ElseIf ZC = 15 And ZE = 3 Then Txtone.Text = (4520 * 35) / 100.ToString ElseIf ZC = 15 And ZE = 4 Then Txtone.Text = (4620 * 35) / 100.ToString ElseIf ZC = 15 And ZE = 5 Then Txtone.Text = (4720 * 35) / 100.ToString ElseIf ZC = 16 And ZE = 1 Then Txtone.Text = (4820 * 35) / 100.ToString ElseIf ZC = 16 And ZE = 2 Then Txtone.Text = (4920 * 35) / 100.ToString ElseIf ZC = 16 And ZE = 3 Then Txtone.Text = (5020 * 35) / 100.ToString ElseIf ZC = 16 And ZE = 4 Then Txtone.Text = (5120 * 35) / 100.ToString ElseIf ZC = 16 And ZE = 5 Then Txtone.Text = (5220 * 35) / 100.ToString ElseIf ZC = 17 And ZE = 1 Then Txtone.Text = (5340 * 35) / 100.ToString ElseIf ZC = 17 And ZE = 2 Then Txtone.Text = (5450 * 35) / 100.ToString ElseIf ZC = 17 And ZE = 3 Then Txtone.Text = (5560 * 35) / 100.ToString ElseIf ZC = 17 And ZE = 4 Then Txtone.Text = (5690 * 35) / 100.ToString ElseIf ZC = 17 And ZE = 5 Then Txtone.Text = (5810 * 35) / 100.ToString ElseIf ZC = 18 And ZE = 1 Then Txtone.Text = (5930 * 35) / 100.ToString ElseIf ZC = 18 And ZE = 2 Then Txtone.Text = (6060 * 35) / 100.ToString ElseIf ZC = 18 And ZE = 3 Then Txtone.Text = (6190 * 35) / 100.ToString ElseIf ZC = 18 And ZE = 4 Then Txtone.Text = (6320 * 35) / 100.ToString ElseIf ZC = 18 And ZE = 5 Then Txtone.Text = (6450 * 35) / 100.ToString ElseIf ZC = 19 And ZE = 1 Then Txtone.Text = (6580 * 35) / 100.ToString ElseIf ZC = 19 And ZE = 2 Then Txtone.Text = (6720 * 35) / 100.ToString ElseIf ZC = 19 And ZE = 3 Then Txtone.Text = (6860 * 35) / 100.ToString ElseIf ZC = 19 And ZE = 4 Then Txtone.Text = (7000 * 35) / 100.ToString ElseIf ZC = 19 And ZE = 5 Then Txtone.Text = (7140 * 35) / 100.ToString ElseIf ZC = 20 And ZE = 1 Then Txtone.Text = (7300 * 35) / 100.ToString ElseIf ZC = 20 And ZE = 2 Then Txtone.Text = (7460 * 35) / 100.ToString ElseIf ZC = 20 And ZE = 3 Then Txtone.Text = (7620 * 35) / 100.ToString ElseIf ZC = 20 And ZE = 4 Then Txtone.Text = (7780 * 35) / 100.ToString ElseIf ZC = 20 And ZE = 5 Then Txtone.Text = (7940 * 35) / 100.ToString ElseIf ZC = 0 And ZE = 0 Then Txtone.Text = 0.ToString End If Catch ex As Exception End Try End Sub
RE: إمكانية إختصار هذا الكود بدالة - islamf3thy - 17-04-17
PHP كود :
Public Sub Name_(TXtone As String, CboZCAT As String, CBoze As String) Dim ZC, ZE As Integer Try ZC = Integer.Parse(CboZCAT) ZE = Integer.Parse(CBoze)
If ZC = 1 And ZE = 1 Then TXtone = (1500 * 35) / 100.ToString ElseIf ZC = 1 And ZE = 2 Then TXtone = (1520 * 35) / 100.ToString ElseIf ZC = 1 And ZE = 3 Then TXtone = (1540 * 35) / 100.ToString ElseIf ZC = 2 And ZE = 1 Then TXtone = (1560 * 35) / 100.ToString ElseIf ZC = 2 And ZE = 2 Then TXtone = (1580 * 35) / 100.ToString ElseIf ZC = 2 And ZE = 3 Then TXtone = (1600 * 35) / 100.ToString ElseIf ZC = 3 And ZE = 1 Then TXtone = (1620 * 35) / 100.ToString ElseIf ZC = 3 And ZE = 2 Then TXtone = (1640 * 35) / 100.ToString ElseIf ZC = 3 And ZE = 3 Then TXtone = (1660 * 35) / 100.ToString ElseIf ZC = 4 And ZE = 1 Then TXtone = (1680 * 35) / 100.ToString ElseIf ZC = 4 And ZE = 2 Then TXtone = (1700 * 35) / 100.ToString ElseIf ZC = 4 And ZE = 3 Then TXtone = (1745 * 35) / 100.ToString ElseIf ZC = 5 And ZE = 1 Then TXtone = (1790 * 35) / 100.ToString ElseIf ZC = 5 And ZE = 2 Then TXtone = (1850 * 35) / 100.ToString ElseIf ZC = 5 And ZE = 3 Then TXtone = (1910 * 35) / 100.ToString ElseIf ZC = 6 And ZE = 1 Then TXtone = (1970 * 35) / 100.ToString ElseIf ZC = 6 And ZE = 2 Then TXtone = (2040 * 35) / 100.ToString ElseIf ZC = 6 And ZE = 3 Then TXtone = (2100 * 35) / 100.ToString ElseIf ZC = 7 And ZE = 1 Then TXtone = (2170 * 35) / 100.ToString ElseIf ZC = 7 And ZE = 2 Then TXtone = (2240 * 35) / 100.ToString ElseIf ZC = 7 And ZE = 3 Then TXtone = (2300 * 35) / 100.ToString ElseIf ZC = 8 And ZE = 1 Then TXtone = (2380 * 35) / 100.ToString ElseIf ZC = 8 And ZE = 2 Then TXtone = (2460 * 35) / 100.ToString ElseIf ZC = 8 And ZE = 3 Then TXtone = (2530 * 35) / 100.ToString ElseIf ZC = 9 And ZE = 1 Then TXtone = (2610 * 35) / 100.ToString ElseIf ZC = 9 And ZE = 2 Then TXtone = (2700 * 35) / 100.ToString ElseIf ZC = 9 And ZE = 3 Then TXtone = (2780 * 35) / 100.ToString ElseIf ZC = 10 And ZE = 1 Then TXtone = (2850 * 35) / 100.ToString ElseIf ZC = 10 And ZE = 2 Then TXtone = (2920 * 35) / 100.ToString ElseIf ZC = 10 And ZE = 3 Then TXtone = (2990 * 35) / 100.ToString ElseIf ZC = 10 And ZE = 4 Then TXtone = (3060 * 35) / 100.ToString ElseIf ZC = 11 And ZE = 1 Then TXtone = (3070 * 35) / 100.ToString ElseIf ZC = 11 And ZE = 2 Then TXtone = (3130 * 35) / 100.ToString ElseIf ZC = 11 And ZE = 3 Then TXtone = (3190 * 35) / 100.ToString ElseIf ZC = 11 And ZE = 4 Then TXtone = (3250 * 35) / 100.ToString ElseIf ZC = 12 And ZE = 1 Then TXtone = (3320 * 35) / 100.ToString ElseIf ZC = 12 And ZE = 2 Then TXtone = (3380 * 35) / 100.ToString ElseIf ZC = 12 And ZE = 3 Then TXtone = (3450 * 35) / 100.ToString ElseIf ZC = 12 And ZE = 4 Then TXtone = (3530 * 35) / 100.ToString ElseIf ZC = 13 And ZE = 1 Then TXtone = (3540 * 35) / 100.ToString ElseIf ZC = 13 And ZE = 2 Then TXtone = (3640 * 35) / 100.ToString ElseIf ZC = 13 And ZE = 3 Then TXtone = (3730 * 35) / 100.ToString ElseIf ZC = 13 And ZE = 4 Then TXtone = (3830 * 35) / 100.ToString ElseIf ZC = 14 And ZE = 1 Then TXtone = (3920 * 35) / 100.ToString ElseIf ZC = 14 And ZE = 2 Then TXtone = (4000 * 35) / 100.ToString ElseIf ZC = 14 And ZE = 3 Then TXtone = (4080 * 35) / 100.ToString ElseIf ZC = 14 And ZE = 4 Then TXtone = (4160 * 35) / 100.ToString ElseIf ZC = 14 And ZE = 5 Then TXtone = (4240 * 35) / 100.ToString ElseIf ZC = 15 And ZE = 1 Then TXtone = (4340 * 35) / 100.ToString ElseIf ZC = 15 And ZE = 2 Then TXtone = (4430 * 35) / 100.ToString ElseIf ZC = 15 And ZE = 3 Then TXtone = (4520 * 35) / 100.ToString ElseIf ZC = 15 And ZE = 4 Then TXtone = (4620 * 35) / 100.ToString ElseIf ZC = 15 And ZE = 5 Then TXtone = (4720 * 35) / 100.ToString ElseIf ZC = 16 And ZE = 1 Then TXtone = (4820 * 35) / 100.ToString ElseIf ZC = 16 And ZE = 2 Then TXtone = (4920 * 35) / 100.ToString ElseIf ZC = 16 And ZE = 3 Then TXtone = (5020 * 35) / 100.ToString ElseIf ZC = 16 And ZE = 4 Then TXtone = (5120 * 35) / 100.ToString ElseIf ZC = 16 And ZE = 5 Then TXtone = (5220 * 35) / 100.ToString ElseIf ZC = 17 And ZE = 1 Then TXtone = (5340 * 35) / 100.ToString ElseIf ZC = 17 And ZE = 2 Then TXtone = (5450 * 35) / 100.ToString ElseIf ZC = 17 And ZE = 3 Then TXtone = (5560 * 35) / 100.ToString ElseIf ZC = 17 And ZE = 4 Then TXtone = (5690 * 35) / 100.ToString ElseIf ZC = 17 And ZE = 5 Then TXtone = (5810 * 35) / 100.ToString ElseIf ZC = 18 And ZE = 1 Then TXtone = (5930 * 35) / 100.ToString ElseIf ZC = 18 And ZE = 2 Then TXtone = (6060 * 35) / 100.ToString ElseIf ZC = 18 And ZE = 3 Then TXtone = (6190 * 35) / 100.ToString ElseIf ZC = 18 And ZE = 4 Then TXtone = (6320 * 35) / 100.ToString ElseIf ZC = 18 And ZE = 5 Then TXtone = (6450 * 35) / 100.ToString ElseIf ZC = 19 And ZE = 1 Then TXtone = (6580 * 35) / 100.ToString ElseIf ZC = 19 And ZE = 2 Then TXtone = (6720 * 35) / 100.ToString ElseIf ZC = 19 And ZE = 3 Then TXtone = (6860 * 35) / 100.ToString ElseIf ZC = 19 And ZE = 4 Then TXtone = (7000 * 35) / 100.ToString ElseIf ZC = 19 And ZE = 5 Then TXtone = (7140 * 35) / 100.ToString ElseIf ZC = 20 And ZE = 1 Then TXtone = (7300 * 35) / 100.ToString ElseIf ZC = 20 And ZE = 2 Then TXtone = (7460 * 35) / 100.ToString ElseIf ZC = 20 And ZE = 3 Then TXtone = (7620 * 35) / 100.ToString ElseIf ZC = 20 And ZE = 4 Then TXtone = (7780 * 35) / 100.ToString ElseIf ZC = 20 And ZE = 5 Then TXtone = (7940 * 35) / 100.ToString ElseIf ZC = 0 And ZE = 0 Then TXtone = 0.ToString End If Catch ex As Exception End Try End Sub
RE: إمكانية إختصار هذا الكود بدالة - عبـدالله - 17-04-17
يمكن اختصار أكثر من ذلك
PHP كود :
Function GetTone(ZC As Integer, ZE As Integer) As Double If (ZC < 1 Or ZC > 20) Or (ZE < 1 Or ZE > 5) Then Return 0
Dim arr(,) As Integer = { {1500, 1520, 1540, 0, 0}, {1560, 1580, 1600, 0, 0}, {1620, 1640, 1660, 0, 0}, {1680, 1700, 1745, 0, 0}, {1790, 1850, 1910, 0, 0}, {1970, 2040, 2100, 0, 0}, {2170, 2240, 2300, 0, 0}, {2380, 2460, 2530, 0, 0}, {2610, 2700, 2780, 0, 0}, {2850, 2920, 2990, 3060, 0}, {3070, 3130, 3190, 3250, 0}, {3320, 3380, 3450, 3530, 0}, {3540, 3640, 3730, 3830, 0}, {3920, 4000, 4080, 4160, 4240}, {4340, 4430, 4520, 4620, 4720}, {4820, 4920, 5020, 5120, 5220}, {5340, 5450, 5560, 5690, 5810}, {5930, 6060, 6190, 6320, 6450}, {6580, 6720, 6860, 7000, 7140}, {7300, 7460, 7620, 7780, 7940} }
Dim tone As Double = (arr((ZC - 1), (ZE - 1)) * 35) / 100
Return tone
End Function
RE: إمكانية إختصار هذا الكود بدالة - ahmedfa71 - 17-04-17
بارك الله فيكم علي الردود
ولكن على ما أضن أن رد الأخ عبد الله في GetTone
ليس بلغة vb net
RE: إمكانية إختصار هذا الكود بدالة - Anas Mahmoud - 17-04-17
(17-04-17, 11:51 AM)ahmedfa71 كتب : بارك الله فيكم علي الردود
ولكن على ما أضن أن رد الأخ عبد الله في GetTone
ليس بلغة vb net
كود الاخ عبد الله صحيح وبلغة vb.net ، ولكن السطر لم يكفي عندما قام بنسخ الكود الى الرد
على العموم اذا اضفنا _ الى نهاية كل سطر ستحل المشكلة
كود :
Function GetTone(ByVal ZC As Integer, ByVal ZE As Integer) As Double
If (ZC < 1 Or ZC > 20) Or (ZE < 1 Or ZE > 5) Then Return 0
Dim arr(,) As Integer = { _
{1500, 1520, 1540, 0, 0}, {1560, 1580, 1600, 0, 0}, {1620, 1640, 1660, 0, 0}, {1680, 1700, 1745, 0, 0}, _
{1790, 1850, 1910, 0, 0}, {1970, 2040, 2100, 0, 0}, {2170, 2240, 2300, 0, 0}, {2380, 2460, 2530, 0, 0}, _
{2610, 2700, 2780, 0, 0}, {2850, 2920, 2990, 3060, 0}, {3070, 3130, 3190, 3250, 0}, _
{3320, 3380, 3450, 3530, 0}, {3540, 3640, 3730, 3830, 0}, {3920, 4000, 4080, 4160, 4240}, _
{4340, 4430, 4520, 4620, 4720}, {4820, 4920, 5020, 5120, 5220}, {5340, 5450, 5560, 5690, 5810}, _
{5930, 6060, 6190, 6320, 6450}, {6580, 6720, 6860, 7000, 7140}, {7300, 7460, 7620, 7780, 7940}}
Dim tone As Double = (arr((ZC - 1), (ZE - 1)) * 35) / 100
Return tone
End Function
RE: إمكانية إختصار هذا الكود بدالة - silverlight - 17-04-17
بالإضافة للكود الذي كتبه لك الأخوة الأفاضل
هذا حل أخر ......
PHP كود :
Private Function CalculateTone(key As Integer, index As Integer) As Double ' لو ان البيانات المراد قرائتها مهمة ' من الأفضل قراءة هذه البيانات من ملف ' بحيث أن الأرقام لا تظهر داخل الكود الخاص بك Dim bucket As Dictionary(Of Integer, Integer()) = New Dictionary(Of Integer, Integer())() From { {1, {1500, 1520, 1540, 0, 0}}, {2, {1560, 1580, 1600, 0, 0}}, {3, {1620, 1640, 1660, 0, 0}}, {4, {1680, 1700, 1745, 0, 0}}, {5, {1790, 1850, 1910, 0, 0}}, {6, {1970, 2040, 2100, 0, 0}}, {7, {2170, 2240, 2300, 0, 0}}, {8, {2380, 2460, 2530, 0, 0}}, {9, {2610, 2700, 2780, 0, 0}}, {10, {2850, 2920, 2990, 3060, 0}}, {11, {3070, 3130, 3190, 3250, 0}}, {12, {3320, 3380, 3450, 3530, 0}}, {13, {3540, 3640, 3730, 3830, 0}}, {14, {3920, 4000, 4080, 4160, 4240}}, {15, {4340, 4430, 4520, 4620, 4720}}, {16, {4820, 4920, 5020, 5120, 5220}}, {17, {5340, 5450, 5560, 5690, 5810}}, {18, {5930, 6060, 6190, 6320, 6450}}, {19, {6580, 6720, 6860, 7000, 7140}}, {20, {7300, 7460, 7620, 7780, 7940}}}
Dim tones As Integer() = Nothing bucket.TryGetValue(CInt(Math.Truncate(If(key > 20, 20, (If(key < 1, 1, key))))), tones) Dim tone As Integer = tones(CInt(Math.Truncate(If(index > 4, 4, (If(index < 0, 0, index)))))) Return tone * 35 / 100
End Function
الاستخدام
ملحوظة الدالة سوف تعود بقيمة مهما كانت المدخلات لأنني قمت بعمل Clamp لكل من Key و Index
PHP كود :
Dim tone As Double = CalculateTone(2, 0)
RE: إمكانية إختصار هذا الكود بدالة - ahmedfa71 - 18-04-17
بارك الله في كل الإخوة على الردود المفيدة
الكود الذي كتبته في بداية المشاركتي شغال
لدي في الفورم 2 كومبوبوكس
وتيكست بوكس 1
PHP كود :
Dim ZC, ZE As Integer ZC = Integer.Parse(CboZCAT.Text) ZE = Integer.Parse(CBoze.Text)
عند التغيير في قيمة الكومبوبوكس الأول CboZCAT.Text والثاني CBoze.Text حسب العملية الحسابية
تظهر النتيجة في التكست بوكس Txtone.text
ولذلك أن جربت كود الأخ عبد الله بعد تعديله قمت بتجربته لكن لم تظهر القيمة في التكست بوكس
وبارك الله لكل الإخوة على الردود
أشكر صبركم معي والسلام عليكم ورحمة الله وبركاته
RE: إمكانية إختصار هذا الكود بدالة - عبـدالله - 18-04-17
لا تقم بالتعديل على الدالة،
PHP كود :
Txtone.text=GetTone(Val(CboZCAT.Text),Val(CBoze.Text))
RE: إمكانية إختصار هذا الكود بدالة - ahmedfa71 - 18-04-17
بارك الله فيك أخي عبدالله
دالة شغالة
شكرا جزيلا لك
تقبل تحياتي
|