ความรู้พื้นฐาน Visual Basic
If...Then...Else ตัดสินใจสองทางเลือก
รูปแบบ
if<ทดสอบเงื่อนไข> Thenทำงาน
Else
ทำงาน
End if
เช่น Private Sub mcd OK_Click()
Dim salary As Integer
salary = Clng(txt Salary.Text)
if salary >10000 Then
MsgBox " ข้อความ",vbOK Only + vb Exclamation,"ข้อความ"
Else
MsgBox
End if
End Sub
Select...Case ตัดสินใจมากกว่าสองทางเลือก
Privatee Sub cmdOK_Click()
Dim age As Integer
age = Clnt(txtAge.Tex)
Salect Case age
Case 1 to 2
MsgBox "ข้อความ", Vb OK Only + Vb Information","
Case Else
End Select
การประกาศตัวแปร
รูปแบบ
Dim ชื่อตัวแปร As ชนิดตัวแปร,ชื่อตัวแปร As ชนิดตัวแปร
เช่น
Dim staVar As Tsting, intVar As Integer , IngVar As Long
staVar = 1
intVar = 127
ingVar = 8000
การวนซ้ำ (Iteration) For....Next
รูปแบบ
for ตัวแปรใช้นับจำนวนรอบ = จำนวนรอบเริ่มต้นTo จำนวนรอบสุดท้าย
เช่น
Private Sub cmd Start_ Click()
Dim num As Integer
num = Clnt(TxtInput. Text)
if num <1 or num > 9 Then
MsgBox "ข้อความ", vb OkOnly + vbExclamation,"ข้อความ"
Exit Sub
Else
TxtResult.Text = ""
for i=1 To num
for j=1 To
txt Rusult = txtResult & CStr(i) &""
Next j
txtResult = txtResult + vbCrLf
Next i
Enf If
Ebd Sub
![]()