1 / 15

Control Statements

Control Statements. Select ..Case. คำสั่ง Select Case เป็น คำสั่งสำหรับสร้างเงื่อนไขการ ทำงาน มีการทำงานเหมือน กับคำสั่ง if แต่จะมีการเปรียบเทียบข้อมูลที่เจาะจง. Select Case ตัวแปร Case เงื่อนไข 1 คำสั่ง Case เงื่อนไข 2 …….

Download Presentation

Control Statements

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Control Statements

  2. Select ..Case คำสั่ง SelectCaseเป็นคำสั่งสำหรับสร้างเงื่อนไขการทำงานมีการทำงานเหมือนกับคำสั่ง if แต่จะมีการเปรียบเทียบข้อมูลที่เจาะจง Select Case ตัวแปร Case เงื่อนไข 1 คำสั่ง Case เงื่อนไข 2 ……. Case Else ‘– Case Else จะมีหรือไม่มีก็ได้ คำสั่งสำหรับกรณีอื่นๆ End Select

  3. Select ..Case ตัวอย่าง 1 Dim a as String a=“T” Select Case a Case “T” MessageBox.Show(“T”) Case “B” MessageBox.Show(“B”) Case Else MessageBox.Show(“Not T B”) End Select

  4. Select ..Case ตัวอย่าง 2 Dim a as String a=“T” Select Case a Case “T”,”Z”,”X” MessageBox.Show(“T Z X”) Case “B” MessageBox.Show(“B”) Case Else MessageBox.Show(“Not T Z X B”) End Select

  5. Select ..Case ตัวอย่าง 3 Dim a as Integer a=70 Select Case a Case Is >=80 MessageBox.Show(“A”) Case Is >=70 MessageBox.Show(“B”) Case Else MessageBox.Show(“F”) End Select

  6. Select ..Case ตัวอย่าง 3 Dim a as Integer a=12 Select Case a Case 0 To 2 MessageBox.Show(“วัยทารก”) Case 3To 12 MessageBox.Show(“วัยเด็ก”) Case Else MessageBox.Show(“วัยรุ่น”) End Select

  7. คำสั่ง For For เป็นคีย์เวิร์ดสำหรับกำหนดการทำงานแบบวงรอบหรือลูป จากค่าเริ่มต้น จนถึงค่าสุดท้ายขอตัวที่ใช้เป็นตัวนับ โดยที่ตัวนับไม่จำเป็นต้องเริ่มต้นจาก 0 และอาจเป็นการนับแบบเพิ่มค่าหรือลดค่าก็ได้รูปแบบคือ For ตัวนับ = ค่าเริ่มต้น To ค่าสุดท้าย คำสั่ง Next

  8. คำสั่ง For ตัวอย่าง Dim i, sum as integer For i=1 To 10 sum+=i MessageBox.Show(i) Next

  9. คำสั่ง For ตัวอย่างการเพิ่มลดค่า Dim i, sum as integer For i=10 To 100Step 10 sum+=i MessageBox.Show(i) Next

  10. คำสั่ง For ตัวอย่างการเพิ่มลดค่า Dim i, sum as integer For i=100 To 10Step -10 sum+=i MessageBox.Show(i) Next

  11. คำสั่ง While While เป็นคีย์เวิร์ดสำหรับกำหนดการทำงานแบบวงรอบหรือลูป โดยค่าเริ่มต้น จะถูกส่งเพียงครั้งเดียว แล้วทำตามเงื่อนไขของ while ซึ่งการทำงานจะถูกตรวจสอบก่อนถ้าตรงตามเงื่อนไขถึงให้ทำงานได้ Whileเงื่อนไข คำสั่ง End While

  12. คำสั่ง While ตัวอย่าง Dim n As Integer =0 While (n<=10) n+=1 MessageBox.Show(n) End While

  13. คำสั่ง Do..While Do While เป็นคีย์เวิร์ดสำหรับกำหนดการทำงานแบบวงรอบหรือลูป โดยค่าเริ่มต้น จะถูกส่งเพียงครั้งเดียว แล้วทำตามเงื่อนไขของ while ซึ่งการทำงานจะถูกตรวจสอบหลังจากการทำงานแล้ว จากนั้นจึงตรวจสอบเงื่อนไข ถ้าผ่านถึงให้ทำงานต่อได้ Do คำสั่ง Loop While เงื่อนไข

  14. คำสั่ง Do While ตัวอย่าง Dim n As Integer =0 do n+=1 MessageBox.Show(n) Loop While (n<=10)

  15. คำสั่ง IsNumeric() คำสั่งในการตรวจสอบตัวเลข Dim n As Integer if(IsNumeric(TextBox1.Text)) Then n=TextBox1.Text MessageBox.Show(“OK”) Else MessageBox.Show(“NO”) End if

More Related