PDA

View Full Version : مدیریت شرطها



xrezax
جمعه 05 آذر 1389, 11:48 صبح
بچه ها من تمام شرطام اینن ، می خوام وقتی کاربر کلمه ای بغیر از (12و13و14و15و16و17و18و19) بزنه برنامه یه msgbox "error" نشون بده


If InStr(1, GetPM.Text, "12", vbTextCompare) > 0 Then
Command2_Click
End If

If InStr(1, GetPM.Text, "13", vbTextCompare) > 0 Then
Command3_Click
End If

If InStr(1, GetPM.Text, "14", vbTextCompare) > 0 Then
Command4_Click
End If

If InStr(1, GetPM.Text, "15", vbTextCompare) > 0 Then
Command5_Click
End If

If InStr(1, GetPM.Text, "16", vbTextCompare) > 0 Then
Command6_Click
End If

If InStr(1, GetPM.Text, "17", vbTextCompare) > 0 Then
Command7_Click
End If

If InStr(1, GetPM.Text, "18", vbTextCompare) > 0 Then
Command8_Click
End If

If InStr(1, GetPM.Text, "19", vbTextCompare) > 0 Then
Command9_Click
End If

xxxxx_xxxxx
جمعه 05 آذر 1389, 15:08 عصر
سلام،
برای اینکه کدتون کوتاه تر بشه، از ساختار Select Case استفاده کنید. یا Command ها رو آرایه کنید.

اما اگر به همین شکلی که هست می خواید باشه باید از IF .. Then .. ElseIF .. Else استفاده کنید.

xrezax
جمعه 05 آذر 1389, 15:45 عصر
سلام،
برای اینکه کدتون کوتاه تر بشه، از ساختار Select Case استفاده کنید. یا Command ها رو آرایه کنید.

اما اگر به همین شکلی که هست می خواید باشه باید از IF .. Then .. ElseIF .. Else استفاده کنید.


میشه برای Select Case با سورس یه مثالی بزنی ؟؟؟ ( IF .. Then .. ElseIF .. Else هم توش بکار برده باشه .) :قلب:

javadt
جمعه 05 آذر 1389, 17:55 عصر
شكلي كلي select case به اين صورت هست:

k = "2"
Select Case k
Case 1:
MsgBox "one"
Case 2:
MsgBox "two"
Case 12:
MsgBox "twelve"
End Select

mohsen_archi
جمعه 05 آذر 1389, 22:38 عصر
میشه برای Select Case با سورس یه مثالی بزنی ؟؟؟ ( IF .. Then .. ElseIF .. Else هم توش بکار برده باشه .)

دلیلی نداره هر دو بکار بره
شکل کلی IF .. Then .. ElseIF .. Else هم به صورت زیر هست:



k = 2
If k = 1 Then
MsgBox "one"
ElseIf k = 2 Then
MsgBox "two"
ElseIf k = 3 Then
MsgBox "three"
ElseIf k = 12 Then
MsgBox "twelve"
End If

pcdownload.bloghaa.com
شنبه 06 آذر 1389, 00:54 صبح
کد زیر کاری را که آقای xrezax خواستند را به صورت Real-time انجام می دهد.


Dim cm, cc As Boolean
Private Sub Text1_Change()
If Right(Text1, 1) = "1" And cm = False Then
cm = True
ElseIf cm = True And Val(Right(Text1, 1)) <= 9 And Val(Right(Text1, 1)) > 1 Then
cm = False
Select Case Right(Text1, 1)
Case 2
Command2_Click
Case 3
Command3_Click
Case 4
Command4_Click
Case 5
Command5_Click
Case 6
Command6_Click
Case 7
Command7_Click
Case 8
Command8_Click
Case 9
Command9_Click
Else
MsgBox "Error"
cm = False
Text1 = Mid(Text1, 1, Len(Text1) - 1)
Text1.SelStart = Len(Text1)
End If
End Sub