PDA

View Full Version : سوال: مشکل این کد چیه؟



hosein3000
یک شنبه 21 اسفند 1390, 15:40 عصر
با سلام دوستان

من از if تو در تو برای برنامه ام استفاده کردم اول شرط ها رو بخوبی بررسی می کنه ولی اومدم با else دو شرط جدید اضافه کردم اصلا اونا رو بررسی نمی کنه هر کاری هم کردم درست نشد که نشد. یعنی جاهای if ها و else ها رو عوض کردم نشد.
به عنوان نمونه کد زیر شرط اول رو بررسی می کنه میبینه درسته دیگه نمیره سراغ شرط دومی

به نظر شما چیکار کنم دومی رو هم بررسی کنه
If Combo7.Text = "other systemÇ" And Combo8.Text = "tip4" Then
Text14.Text = 0.05 * Val(Text15.Text) ^ (3 / 4)
Text13.Text = "0.15"
Text12.Text = "1"
Text11.Text = "1.75"
If "0" <= Val(Text14.Text) <= Val(Text13.Text) Then
Text10.Text = 1 + Val(Text11.Text) * (Val(Text14.Text) / Val(Text13.Text))
Option6.Value = True
End If
If Val(Text13.Text) <= Val(Text14.Text) <= Val(Text12.Text) Then

Text10.Text = Val(Text11.Text) + 1
Option5.Value = True
End If
If Val(Text14.Text) >= Val(Text12.Text) Then
Text10.Text = (Val(Text11.Text) + 1) * (Val(Text12.Text) / Val(Text14.Text)) ^ (2 / 3)
Option4.Value = True

End If
Else
If Combo1.Text = "unsafe zone" And Combo7.Text = "other system" And Combo8.Text = "tip4" Then
Text14.Text = 0.05 * Val(Text15.Text) ^ (3 / 4)
Text13.Text = "0.15"
Text12.Text = "1"
Text11.Text = "22222222222222"
If "0" <= Val(Text14.Text) <= Val(Text13.Text) Then
Text10.Text = 1 + Val(Text11.Text) * (Val(Text14.Text) / Val(Text13.Text))
Option6.Value = True
End If
If Val(Text13.Text) <= Val(Text14.Text) <= Val(Text12.Text) Then

Text10.Text = Val(Text11.Text) + 1
Option5.Value = True
End If
If Val(Text14.Text) >= Val(Text12.Text) Then
Text10.Text = (Val(Text11.Text) + 1) * (Val(Text12.Text) / Val(Text14.Text)) ^ (2 / 3)
Option4.Value = True

End If

تفاوت شرط اول با دوم در unsafe zone هست . یعنی اگر شرط اول برقرار بشه تسکت باکس ها یه مقدار خاص بگیریند ولی اگر combobox11 بشه unsafe zone مقادیر تسکت باکس ها عوض بشن
این میبینه چون شرط اولی برقراره دیگه combo11 رو چک نمی کنه

سید حمید حق پرست
یک شنبه 21 اسفند 1390, 15:57 عصر
سلام دوست عزیز
مشکل از end if که گذاشتی و مانع اجرا else میشود
کد صحیح :

If Combo7.Text = "other systemÇ" And Combo8.Text = "tip4" Then
Text14.Text = 0.05 * Val(Text15.Text) ^ (3 / 4)
Text13.Text = "0.15"
Text12.Text = "1"
Text11.Text = "1.75"
If "0" <= Val(Text14.Text) <= Val(Text13.Text) Then
Text10.Text = 1 + Val(Text11.Text) * (Val(Text14.Text) / Val(Text13.Text))
Option6.Value = True
End If
If Val(Text13.Text) <= Val(Text14.Text) <= Val(Text12.Text) Then

Text10.Text = Val(Text11.Text) + 1
Option5.Value = True
End If
If Val(Text14.Text) >= Val(Text12.Text) Then
Text10.Text = (Val(Text11.Text) + 1) * (Val(Text12.Text) / Val(Text14.Text)) ^ (2 / 3)
Option4.Value = True


Else
If Combo1.Text = "unsafe zone" And Combo7.Text = "other system" And Combo8.Text = "tip4" Then
Text14.Text = 0.05 * Val(Text15.Text) ^ (3 / 4)
Text13.Text = "0.15"
Text12.Text = "1"
Text11.Text = "22222222222222"
If "0" <= Val(Text14.Text) <= Val(Text13.Text) Then
Text10.Text = 1 + Val(Text11.Text) * (Val(Text14.Text) / Val(Text13.Text))
Option6.Value = True
End If
If Val(Text13.Text) <= Val(Text14.Text) <= Val(Text12.Text) Then

Text10.Text = Val(Text11.Text) + 1
Option5.Value = True
End If
If Val(Text14.Text) >= Val(Text12.Text) Then
Text10.Text = (Val(Text11.Text) + 1) * (Val(Text12.Text) / Val(Text14.Text)) ^ (2 / 3)
Option4.Value = True
End If
End If

موفق باشی


یا علی (ع)

ASedJavad
یک شنبه 21 اسفند 1390, 16:16 عصر
If "0" <= Val(Text14.Text) <= Val(Text13.Text) Then
این خط از کد شما هم غلطه
شما یا باید صفر رو به صورت عدد بهش بدی یا از تابع Val استفاده نکنی.

hosein3000
یک شنبه 21 اسفند 1390, 22:08 عصر
با تشکر

ولی تعداد if ها زیاده جور در نیومد اون end if رو هم حدف کردم نشد

MohammadGh2011
یک شنبه 21 اسفند 1390, 22:38 عصر
سلام عليکم
چرا از دستور Select case يا از elseif استفاده نميکنيد؟