เริ่มต้นใช้งาน Visual Basic 2008

Posted by Unknown Friday, August 31, 2012 0 comments

เริ่มต้นใช้งาน Visual Basic 2008




หลักการเขียนโปรแกรมด้วย Visual Basic 2008
1.เป็นการเขียนโปรแกรมแบบ Event Driven Programming
2.การเขียนคำสั่งกำหนดให้โปรแกรมทำงานในสิ่งที่เราต้องการตามเหตุการณ์ (Event) ที่เกิดขึ้น
3.การมองแต่ละส่วนของโปรแกรมเป็นออบเจ็กต์ (Object)
4.ออ บเจ็กต์แต่ละตัวมีคุณสมบัติหรือพร็อพเพอร์ตี้ (Property) เป็นของตัวเอง ซึ่งแต่ละคุณสมบัติสามารถกำหนดค่าให้ได้ เช่น สีโปรแกรม สีของเมนู
5.ออบเจ็กต์แต่ละตัวมีความสามารถหรือเมธอด(Method)เป็นของตัวเอง เช่น โปรแกรม Calculator สามารถ บวก ลบ คูณ หาร ได้
6.ออบเจ็กต์สามารถเกิดเหตุการณ์ต่างๆ หรือ Event เกิดขึ้นได้ เช่น การคลิก ป้อนข้อมูล หรือเลือกข้อมูล
7.ใน Visual Basic 2008 มีออบเจ็กต์ให้ใช้งานอยู่ 2 ประเภท คือ
คอนโทรล(Control)เป็นออบเจ็กต์ที่สามารถมองเห็นได้ เช่น ปุ่มกด(Button) กรอกข้อความ(Textbox)
คอมโพเนนต์(Component)เป็นออบเจ็กต์ที่เรามองไม่เห็นเวลาที่แอพพลิเคชั่นทำงาน (ทำงานอยู่เบื้องหลัง) เช่น ตัวจัดการด้านเวลา(Timer)

การสร้างแอพพลิเคชั่นด้วยฟอร์ม (Visual Basic 2008)

Posted by Unknown 0 comments


1.ออกแบบให้มีฟอร์มและวางคอนโทรลต่างๆ ไว้ดังนี้


2.ใน Form Designer ดับเบิลคลิกที่ฟอร์มเพื่อเขียนโค้ดกำหนดการทำงานที่ Event Load โดยใช้เขียนข้อความต้อนรับเมื่อเริ่มใช้งาน



3.ดับ เบิลคลิกที่ปุ่ม เปลี่ยนข้อความ เพื่อเขียนโค้ดที่ Event Click โดยเขียนให้เปลี่ยนข้อความที่แถบด้านบนของฟอร์ม ตามข้อความที่ปรากฏในช่องรับข้อความ



4.ดับเบิลคลิกที่ RadioBotton แต่ละตัวแล้วเขียนโค้ดให้มีการเปลี่ยนสีพื้นของฟอร์ม


5.ดับ เบิลคลิกปุ่ม จบการทำงาน แล้วเขียนโค้ดที่เรียกใช้เมธอด Close เพื่อจบการทำงานของฟอร์มนี้ซึ่งก็คือ จบการทำงานของแอพพลิเคชั่นนั่นเอง(เพราะแอพพลิเคชั่นนีมีแค่ฟอร์มเดียว)



6.ทดสอบการทำงานของแอพพลิเคชั่น จะได้ผลดังนี้


เริ่มต้นทักทาย กดปุ่ม OK






กรอกข้อความ แล้วกดปุ่ม เปลี่ยนข้อความ ข้อความ รักเมืองไทย จะแสดงในแถบด้านบน


คลิกเปลี่ยนสีพื้น
บทความข้างต้นนี้เป็นเพียงพื้นฐาน เป็น basic สำหรับผู้ที่เริ่มต้น สามารถนำไปประยุกต์และทำการดัดแปลงได้อีกมาก visual basic ไม่ได้ยากอย่างที่คิด

ตัวอย่างการใช้งาน ตัวดำเนินการทางคณิตศาสตร์ (Visual Basic 2008)

Posted by Unknown 0 comments


ตัวอย่างแอพพลิเคชั่นง่ายๆ โดยใช้โปรแกรม visual basic 2008 ที่มีการใช้งานตัวดำเนินการทางคณิตศาสตร์แต่ละตัว โดยพิจารณาจากข้อมูล และผลลัพธ์ที่เกิดขึ้น

1.ออกแบบหน้าตาแอพพลิเคชัน และตั้งชื่อคอนโทรลต่างๆ
โดยใช้
โปรแกรม Visual Basic 2008
2. ดับเบิลคลิกปุ่ม ประมวลผล แล้วเขียนโค้ดดังนี้


3. ทดสอบการทำงานของแอพพลิเคชันที่ออกแบบและเขียนโค้ดโดยโปรแกรม visual basic 2008 ได้ผลดังรูป

การทำ Login ด้วย Visual Basic 2008

Posted by Unknown 0 comments


ออกแบบและเขียนโค้ดด้วยโปรแกรม Visual Basic 2008



1.สร้าง Form1 ขึ้นมา ตั้งชื่อ Form ว่า Login และออกแบบดังรูป





2. กำหนดคุณสมบัติ ของ Textbox ที่จะพิมพ์ Password ลงไป ดังรูป





3. ทำการสร้าง Form2 ขึ้นมา แล้วตั้งชื่อว่า welcome แล้วพิมพ์ข้อความ "ยินดีต้อนรับเข้าสู่ระบบ"





4. ทำการเขียนโค้ดลงไปใน Form1 โดยดับเบิลคลิกที่ปุ่ม Login แล้วทำการเขียนโค้ดดังนี้







Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click



If TextBox1.Text = "Admin" And TextBox2.Text = "1234" Then



Form2.Show()

Else

MsgBox("Username และ Password ของคุณไม่ถูกต้อง", MsgBoxStyle.OkOnly, "ไม่ถูกต้อง")



End If

End Sub

การทำ Windows Media Player จาก Visual Basic 2008

Posted by Unknown 0 comments


Windows Media Player จาก Visual Basic 2008

1.สร้าง Form ขึ้นมา 1 Form จากนั้นตั้งชื่อ Form ว่า Windows Media Player
2.คลิกขวา BindingSource แล้วเลือก Choose Items... ดังรูป

3.จะได้หน้าต่าง Choose Toolbox Items ขึ้นมา จากนั้นทำการเลือก windows media player ดังรูป


4.windows media player จะมาปรากฏใน Toolbox จากนั้นทำการลากมาวางที่ Form แล้วทำการปรับขนาด และเพิ่มปุ่ม Song จะได้ดังนี้


5.คลิกลาก OpenFileDailog มาวางใน Form ได้ดังนี้


6.ทำการเขียนโค้ดลงในปุ่ม Song โดยดับเบิลคลิกที่ปุ่ม Song แล้วเขียนโค้ดดังนี้

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

OpenFileDialog1.ShowDialog()
AxWindowsMediaPlayer1.URL = OpenFileDialog1.FileName

End Sub


7.ทำการทดสอบโปรแกรม
- คลิกที่ปุ่ม Song จะปรากฏหน้าต่าง Open แล้วเลือกเพลงหรือวีดีโอที่ต้องการเปิด



- เราก็จะสามารถฟังเพลง ดูหนัง ได้



ตัวดำเนินการทางคณิตศาสตร์ (Arithmetic Operator)

Posted by Unknown 0 comments
ตัวดำเนินการทางคณิตศาสตร์ (Arithmetic Operator) เป็นตัวดำเนินการที่มีการใช้งานบ่อยมาก และเป็นตัวดำเนินการที่ผู้สนใจการเขียนโปรแกรม Visual Basic 2008 จะต้องศึกษาและทำความเข้าใจ เพราะจะช่วยให้การเขียนโปรแกรม Visual Basic 2008 มีประสิทธิภาพมากขึ้น


ตัวดำเนินการทางคณิตศาสตร์ในโปรแกรม visual basic 2008

การเชื่อมต่อฐานข้อมูล Access มาใช้ใน Visual Basic 2008

Posted by Unknown 0 comments



ในการเขียนโปรแกรมประยุกต์ ในบางครั้งก็จำเป็นที่จะต้องมีการติดต่อฐานข้อมูล เพื่อใช้ในการบันทึก จัดเก็บหรือนำข้อมูลในฐานข้อมูลมาทำการนำเสนอ visual basic ก็เป็นหนึ่งโปรแกรมที่สามารถทำการเรียกใช้ฐานข้อมูลได้หลากหลายประเภท เช่น microsoft access ,microsoft SQL หรือ Oracle
ก็สามารถทำได้

ตัวอย่างการเชื่อมต่อฐานข้อมูล access มายัง visual basic 2008
ขั้นแรก ให้เข้าไปที่ เมนูบาร์ Data เลือก Add New Data Source ดังรูป


1

จะ ปรากฎหน้าต่างดังรูปเป็นการเลือกชนิดของ Database ที่จะนำเข้ามาเชื่อมต่อ เราจะทำการเชื่อมต่อฐานข้อมูล Access ก็ทำการเลือกชนิดเป็น Database และทำการ Next ไป

2

จากนั้นคลิกเลือก New Connection ในส่วนของ Data Source กดเลือก Change
ใน หน้าต่าง Change Data Source ให้ทำการเลือกฐานข้อมูลเป็น Microsoft Access Database File และส่วนของ Data Provider เลือกเป็น .NET Framework Data Provider for OLE DB

4

จากนั้นคลิกปุ่ม Browse เพื่อทำการเลือกไฟล์ฐานข้อมูล Access ที่จะนำมาใช้
5

แล้วลองทำการ Test Connection เมื่อเชื่อมต่อได้จะขึ้นหน้าต่างเตือนดังข้างล่าง

6

เมื่อกดตกลงและกด Next จะขึ้นหน้าต่างว่า visual basic จะทำการ copy file กด Yes เพื่อยอมรับ

7

ถัดไปให้กด Next เพื่อบันทึกการตั้งค่าการเชื่อมต่อฐานข้อมูล

8

หน้าต่างนี้จะเป็นการเลือกว่าเราต้องการให้แสดงอะไรบ้างใน visual basic ในที่นี้ให้ทำการเลือกทั้งหมด


9

เชื่อมต่อฐานข้อมูลเรียบร้อยแล้วครับ จะเห็นได้ว่ามีฐานข้อมูลที่เราเลือกอยู่ทางด้านขวามือในส่วนของ Data Sources
10

วิธีการแสดงผลฐานข้อมูลเบื้องต้นให้เราทำการลากตารางฐานข้อมูลที่ต้องการมาวางในฟอร์มของ visual basic จะได้ Data Grid View เป็นการแสดงฐานข้อมูล สามารถกำหนดได้ว่าจะเลือก ให้คอลัมน์ใดบ้างที่จะให้แสดงแต่ถ้าไม่ได้กำหนดจะเป็นการแสดงทั้งหมด
11

เมื่อกำหนดขนาดความกว้าง ของตารางฐานข้อมูลที่จะแสดงแล้ว กด Start Debugging จะได้ผลลัพธ์ดังรูป

12

www.w3schools.com เว็บประจำกายโปรแกรมเมอร์

Posted by Unknown 0 comments

www.w3schools.com เว็บประจำกายโปรแกรมเมอร์

w3 w3schools.com เป็นเว็บไซต์ที่รวมรวมความรู้ ตัวอย่างการเขียนโปรแกรม การเรียกใช้งานฟังก์ชั่นต่างๆของโปรแกรม ไม่ว่าจะเป็น HTML CSS XML JAVASCRIPT ASP PHP SQL และอื่น ๆ เป็นการเรียนแบบออนไลน์ไม่ต้องติดตั้งโปรแกรมสามารถทำการรันโค้ดโปรแกรมได้เลย

result

image

เสีย ค่าใช้จ่ายแต่อย่างใด มีแบบทดสอบหลังการเรียนให้ทดสอบความสามารถของผู้ที่เข้ามาศึกษา หรือท่านใดต้องการใบเกียรติบัตรหรือใบรับรองว่าผ่านการทดสอบจาก w3schools.com ก็สามารถทำได้แต่ต้องเสียค่าสอบประมาณ 95 ดอลล่าร์ ประมาณ สองพันกว่าบาท การสอบจะสอบออนไลน์ผู้ที่จะผ่านการทดสอบ จะต้องได้คะแนน มากว่า 70 เปอร์เซ็นต์ขึ้นไป จึงจะได้รับใบรับรอง สนใจทดสอบคลิกที่นี่

image

image

สร้าง Search ด้วย Visual Basic 2008

Posted by Unknown 0 comments




1.สร้าง form ขึ้นมา 1 form และออบแบบตามรูปด้านล่าง





2.เขียนโค้ดลงในปุ่ม Search Google (Button 1) และ Search Youtube (Button 2) ดังนี้




Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click



Process.Start("iexplore", "http://www.google.com/search?hl=en&q=" + TextBox1.Text + "&aq=f&oq=")



End Sub



Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click



Process.Start("iexplore", "http://www.youtube.com/results?search_type=&search_query=" + TextBox1.Text + "&aq=f")



End Sub





3.ทดสอบโปรแกรม


- การ Search Google เพิ่มข้อความที่ต้องการค้นหาลงใน Textbox แล้วคลิกปุ่ม Search Google











-การ Search Youtube เพิ่มข้อความที่ต้องการค้นหาลงใน Textbox แล้วคลิกปุ่ม Search Youtube





โปรแกรมคำนวณดัชนีมวลกาย(BMI) ด้วยโปรแกรม visual basic

Posted by Unknown 1 comments


1. สร้าง form ขึ้นมาด้วยโปรแกรม visual basic แล้วทำออกแบบ ดังรูป



visual basic รูป 1 ออกแบบ form





2. เขียนโค้ดลงในปุ่ม คำนวณดัชนีมวลกาย(BMI) โดยดับเบิ้ลคลิกที่ปุ่ม แล้วทำการเขียนโค้ดเพื่อคำนวณค่าออกมา ดังนี้




Private Sub Button_BMI_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_BMI.Click




Dim High As Double "ประกาศตัวแปร"

Dim result As Double "ประกาศตัวแปร"

Dim BMI As Double "ประกาศตัวแปร"





High = Val(TextBox_High.Text) / 100






result = High * High

BMI = Val(TextBox_Weight.Text) / result



Label_result_BMI.Text = Format(BMI, "#0.00")





If Label_result_BMI.Text < 18.5 Then

Label_result.Text = "ผอมเกินไป"

Label_result_counsel.Text = "ต้องเพิ่มน้ำหนัก และรับประทานอาหารที่มีประโยชน์"



ElseIf Label_result_BMI.Text > 18.5 And Label_result_BMI.Text < 25 Then

Label_result.Text = "น้ำหนักปกติ"

Label_result_counsel.Text = "ต้องเริ่มควบคุมน้ำหนัก ควบคุมอาหาร และออกกำลังกาย"



ElseIf Label_result_BMI.Text >= 25 And Label_result_BMI.Text < 30 Then

Label_result.Text = "น้ำหนักเกิน"

Label_result_counsel.Text = "ต้องลดน้ำหนัก ออกกำลังกายอย่างจริงจัง และเข้มงวด"



ElseIf Label_result_BMI.Text >= 30 And Label_result_BMI.Text < 40 Then

Label_result.Text = "อ้วน"

Label_result_counsel.Text = "ต้องลดน้ำหนัก ออกกำลังกายอย่างจริงจัง และเข้มงวด"



ElseIf Label_result_BMI.Text >= 40 Then

Label_result.Text = "อ้วนมาก"

Label_result_counsel.Text = "ต้องลดน้ำหนัก ออกกำลังกายอย่างจริงจัง และเข้มงวด"



Else



End If



End Sub





3. เขียนโค้ดลงในปุ่ม ดัชนีมวลกายที่แพทย์แนะนำ โดยดับเบิ้ลคลิกที่ปุ่ม แล้วทำการเขียนโค้ดเพื่อแสดงค่าดัชนีมวลกายในช่วงที่เหมาะสมออกมา ดังนี้




Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button.Click



MessageBox.Show(" ค่าดัชนีมวลกายที่แพทย์แนะนำ อยู่ที่ 18.00 - 19.00" & & ControlChars.CrLf & " น้ำหนักที่เหมาะสมคือ 39.96 - 42.18 กิโลกรัม", "ค่าดัชนีมว

ลกาย(BMI)", MessageBoxButtons.OK, MessageBoxIcon.Information)




End Sub





4. เขียนโค้ดลงในปุ่ม Clear โดยดับเบิ้ลคลิกที่ปุ่ม แล้วทำการเขียนโค้ดเพื่อทำการลบข้อมูลเดิม แล้วทำการคำนวณดัชนีมวลกายใหม่




Private Sub ClearButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearButton.Click



TextBox_Weight.Text = ""

TextBox_High.Text = ""

Label_result_BMI.Text = ""

Label_result.Text = ""

Label_result_counsel.Text = ""



End Sub





4. เขียนโค้ดลงในปุ่ม ออกจากโปรแกรม โดยดับเบิ้ลคลิกที่ปุ่ม แล้วทำการเขียนโค้ดเพื่อออกจากโปรแกรมเมื่อคำนวณเสร็จแล้ว




Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Exit.Click


End



End Sub





5. ทดสอบโปรแกรม





- กรอก น้ำหนัก และส่วนสูงของเราลงไป จากนั้นทำการคลิกที่ปุ่ม คำนวณดัชนีมวลกาย(BMI)




visual basic รูป 2 แสดงผลการคำนวณ





- ถ้าต้องการดูดัชนีมวลกายที่เหมาะสม ให้ทำการคลิกที่ปุ่ม ดัชนีมวลกายที่แพทย์แนะนำ จะมี MessageBox ขึ้นมาให้ดู




visual basic รูป 3 แสดงผลดัชนีมวลกายที่เหมาะสม

โปรแกรมสั่งซื้อหนังสือง่ายๆ ด้วย visual basic

Posted by Unknown 1 comments


1 สร้าง form 1 ด้วยโปรแกรม visual basic ขึ้น มา แล้วทำการตั้งชื่อ (AMARIN BOOKS STORE) แล้วทำการออกแบบตามต้องการ จะมีปุ่ม 2 ปุ่ม คือ 1 ปุ่มดูสินค้า/สั่งสินค้า 2 ปุ่มออกจากระบบ


2 เขียนโค้ดลงใน ปุ่มดูสินค้า/สั่งสินค้า และปุ่มออกจากระบบ ตามลำดับ ดังนี้

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Hide() "ทำการซ่อนหน้า AMARIN BOOKS STORE"
Product.Show() "ให้แสดงหน้า Product ขึ้นมา"
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
End "ปิดโปรแกรม"
End Sub

3 สร้าง form 2 ด้วยโปรแกรม visual basic ขึ้นมา แล้วทำการตั้งชื่อ (Product) แล้วทำการออกแบบให้เหมาะสมและใช้งานง่าย


4 เขียนโค้ดลงใน ปุ่มสั่งซื้อหนังสือ ปุ่มย้อนกลับ ปุ่มล้างข้อมูล ตามลำดับ ดังนี้

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

'บันทึกรายการที่สั่ง

If CheckBox1.Checked = True Then

If TextBox1.Text = "" Then
MessageBox.Show("คุณไม่ได้ใส่จำนวนที่ซื้อค่ะ", "แจ้งข้อผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
Calculate.output.Items.Add(" " & "ต้องสงสัย (Eyes of a Child)" & ControlChars.Tab & ControlChars.Tab & Val(TextBox1.Text) & ControlChars.Tab & 220 * Val(TextBox1.Text))
End If

End If

If CheckBox2.Checked = True Then

If TextBox2.Text = "" Then
MessageBox.Show("คุณไม่ได้ใส่จำนวนที่ซื้อค่ะ", "แจ้งข้อผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
Calculate.output.Items.Add(" " & "มหัศจรรย์นิรันดร์รัก " & ControlChars.Tab & ControlChars.Tab & ControlChars.Tab & Val(TextBox2.Text) & ControlChars.Tab & 250 * Val(TextBox2.Text))
End If

End If

If CheckBox3.Checked = True Then

If TextBox3.Text = "" Then
MessageBox.Show("คุณไม่ได้ใส่จำนวนที่ซื้อค่ะ", "แจ้งข้อผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
Calculate.output.Items.Add(" " & "สาส์นลับที่สาบสูญ (The Lost Symbol)" & ControlChars.Tab & Val(TextBox3.Text) & ControlChars.Tab & 269 * Val(TextBox3.Text))
End If
End If

If CheckBox4.Checked = True Then
If TextBox4.Text = "" Then
MessageBox.Show("คุณไม่ได้ใส่จำนวนที่ซื้อค่ะ", "แจ้งข้อผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
Calculate.output.Items.Add(" " & "รหัส 3" & ControlChars.Tab & ControlChars.Tab & ControlChars.Tab & ControlChars.Tab & Val(TextBox4.Text) & ControlChars.Tab & 200 * Val(TextBox4.Text))
End If
End If

If CheckBox5.Checked = True Then
If TextBox5.Text = "" Then
MessageBox.Show("คุณไม่ได้ใส่จำนวนที่ซื้อค่ะ", "แจ้งข้อผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
Calculate.output.Items.Add(" " & "จินตนาการไม่รู้จบ" & ControlChars.Tab & ControlChars.Tab & ControlChars.Tab & Val(TextBox5.Text) & ControlChars.Tab & 179 * Val(TextBox5.Text))
End If
End If

If CheckBox6.Checked = True Then
If TextBox6.Text = "" Then
MessageBox.Show("คุณไม่ได้ใส่จำนวนที่ซื้อค่ะ", "แจ้งข้อผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
Calculate.output.Items.Add(" " & "ปริศนาในป่าลึก (Reality Check)" & ControlChars.Tab & Val(TextBox6.Text) & ControlChars.Tab & 210 * Val(TextBox6.Text))
End If
End If

If CheckBox7.Checked = True Then
If TextBox7.Text = "" Then
MessageBox.Show("คุณไม่ได้ใส่จำนวนที่ซื้อค่ะ", "แจ้งข้อผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
Calculate.output.Items.Add(" " & "เซนจูรี่ เล่ม 2 ดาวแห่งศิลา" & ControlChars.Tab & ControlChars.Tab & Val(TextBox7.Text) & ControlChars.Tab & 169 * Val(TextBox7.Text))
End If
End If

If CheckBox8.Checked = True Then
If TextBox8.Text = "" Then
MessageBox.Show("คุณไม่ได้ใส่จำนวนที่ซื้อค่ะ", "แจ้งข้อผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
Calculate.output.Items.Add(" " & "ตำนานแห่งซิลมาริล" & ControlChars.Tab & ControlChars.Tab & ControlChars.Tab & Val(TextBox8.Text) & ControlChars.Tab & 200 * Val(TextBox8.Text))
End If
End If

If CheckBox9.Checked = True Then
If TextBox9.Text = "" Then
MessageBox.Show("คุณไม่ได้ใส่จำนวนที่ซื้อค่ะ", "แจ้งข้อผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
Calculate.output.Items.Add(" " & "คุ้งน้ำค้าง" & ControlChars.Tab & ControlChars.Tab & ControlChars.Tab & ControlChars.Tab & Val(TextBox9.Text) & ControlChars.Tab & 190 * Val(TextBox9.Text))
End If
End If

If CheckBox10.Checked = True Then
If TextBox10.Text = "" Then
MessageBox.Show("คุณไม่ได้ใส่จำนวนที่ซื้อค่ะ", "แจ้งข้อผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
Calculate.output.Items.Add(" " & "ตะวันเบิกฟ้า" & ControlChars.Tab & ControlChars.Tab & ControlChars.Tab & Val(TextBox10.Text) & ControlChars.Tab & 189 * Val(TextBox10.Text))
End If
End If

If CheckBox11.Checked = True Then
If TextBox11.Text = "" Then
MessageBox.Show("คุณไม่ได้ใส่จำนวนที่ซื้อค่ะ", "แจ้งข้อผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
Calculate.output.Items.Add(" " & "ลับแล แก่งคอย" & ControlChars.Tab & ControlChars.Tab & ControlChars.Tab & Val(TextBox11.Text) & ControlChars.Tab & 195 * Val(TextBox11.Text))
End If
End If

If CheckBox12.Checked = True Then
If TextBox12.Text = "" Then
MessageBox.Show("คุณไม่ได้ใส่จำนวนที่ซื้อค่ะ", "แจ้งข้อผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
Calculate.output.Items.Add(" " & "ภาพรักในฝัน" & ControlChars.Tab & ControlChars.Tab & ControlChars.Tab & Val(TextBox12.Text) & ControlChars.Tab & 220 * Val(TextBox12.Text))
End If
End If

If CheckBox13.Checked = True Then
If TextBox13.Text = "" Then
MessageBox.Show("คุณไม่ได้ใส่จำนวนที่ซื้อค่ะ", "แจ้งข้อผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
Calculate.output.Items.Add(" " & "คันไซ...ไม่ต้องเกา" & ControlChars.Tab & ControlChars.Tab & ControlChars.Tab & Val(TextBox13.Text) & ControlChars.Tab & 200 * Val(TextBox13.Text))
End If
End If

If CheckBox14.Checked = True Then
If TextBox14.Text = "" Then
MessageBox.Show("คุณไม่ได้ใส่จำนวนที่ซื้อค่ะ", "แจ้งข้อผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
Calculate.output.Items.Add(" " & "เทพและเทพีอียิปต์" & ControlChars.Tab & ControlChars.Tab & ControlChars.Tab & Val(TextBox14.Text) & ControlChars.Tab & 240 * Val(TextBox14.Text))
End If
End If

If CheckBox15.Checked = True Then
If TextBox15.Text = "" Then
MessageBox.Show("คุณไม่ได้ใส่จำนวนที่ซื้อค่ะ", "แจ้งข้อผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
Calculate.output.Items.Add(" " & "ฝนกล้วยให้เป็นเข็ม" & ControlChars.Tab & ControlChars.Tab & ControlChars.Tab & Val(TextBox15.Text) & ControlChars.Tab & 210 * Val(TextBox15.Text))
End If
End If

If CheckBox16.Checked = True Then
If TextBox16.Text = "" Then
MessageBox.Show("คุณไม่ได้ใส่จำนวนที่ซื้อค่ะ", "แจ้งข้อผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
Calculate.output.Items.Add(" " & "เดินเดี่ยว เที่ยวโทรอนโต" & ControlChars.Tab & ControlChars.Tab & Val(TextBox16.Text) & ControlChars.Tab & 230 * Val(TextBox16.Text))
End If
End If


Me.Hide()
Calculate.Show()

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Hide()
Welcome.Show()
End Sub

Private Sub btnClear_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
CheckBox1.Checked = False
CheckBox2.Checked = False
CheckBox3.Checked = False
CheckBox4.Checked = False
CheckBox5.Checked = False
CheckBox6.Checked = False
CheckBox7.Checked = False
CheckBox8.Checked = False
CheckBox9.Checked = False
CheckBox10.Checked = False
CheckBox11.Checked = False
CheckBox12.Checked = False
CheckBox13.Checked = False
CheckBox14.Checked = False
CheckBox15.Checked = False
CheckBox16.Checked = False
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
TextBox7.Text = ""
TextBox8.Text = ""
TextBox9.Text = ""
TextBox10.Text = ""
TextBox11.Text = ""
TextBox12.Text = ""
TextBox13.Text = ""
TextBox14.Text = ""
TextBox15.Text = ""
TextBox16.Text = ""
End Sub

5 สร้าง form 3 ด้วยโปรแกรม visual basic ขึ้นมา แล้วทำการตั้งชื่อ (calculate) แล้วทำการออกแบบตามความเหมาะสม ให้ใช้งานง่าย


6 เขียนโค้ดลงใน ปุ่มคำนวณเงิน ปุ่มย้อนกลับ ปุ่มล้างข้อมูล และปุ่มออกจากระบบ ตามลำดับ ดังนี้

Private Sub btnCalculat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculat.Click
'คำนวนเงิน

Dim book As Integer
Dim price As Double


If Product.CheckBox1.Checked = True Then
If Product.TextBox1.Text = "" Then
bookNumber.Text = ""
result.Text = ""
Else
price += 220 * Val(Product.TextBox1.Text)
book += Val(Product.TextBox1.Text)
End If
End If


If Product.CheckBox2.Checked = True Then
If Product.TextBox2.Text = "" Then
bookNumber.Text = ""
result.Text = ""
Else
price += 250 * Val(Product.TextBox2.Text)
book += Val(Product.TextBox2.Text)
End If
End If

If Product.CheckBox3.Checked = True Then
If Product.TextBox3.Text = "" Then
bookNumber.Text = ""
result.Text = ""
Else
price += 269 * Val(Product.TextBox3.Text)
book += Val(Product.TextBox3.Text)
End If
End If

If Product.CheckBox4.Checked = True Then
If Product.TextBox4.Text = "" Then
bookNumber.Text = ""
result.Text = ""
Else
price += 200 * Val(Product.TextBox4.Text)
book += Val(Product.TextBox4.Text)
End If
End If

If Product.CheckBox5.Checked = True Then
If Product.TextBox5.Text = "" Then
bookNumber.Text = ""
result.Text = ""
Else
price += 179 * Val(Product.TextBox5.Text)
book += Val(Product.TextBox5.Text)
End If
End If

If Product.CheckBox6.Checked = True Then
If Product.TextBox6.Text = "" Then
bookNumber.Text = ""
result.Text = ""
Else
price += 210 * Val(Product.TextBox6.Text)
book += Val(Product.TextBox6.Text)
End If
End If

If Product.CheckBox7.Checked = True Then
If Product.TextBox7.Text = "" Then

bookNumber.Text = ""
result.Text = ""
Else
price += 169 * Val(Product.TextBox7.Text)
book += Val(Product.TextBox7.Text)
End If
End If

If Product.CheckBox8.Checked = True Then
If Product.TextBox8.Text = "" Then

bookNumber.Text = ""
result.Text = ""
Else
price += 200 * Val(Product.TextBox8.Text)
book += Val(Product.TextBox8.Text)
End If
End If

If Product.CheckBox9.Checked = True Then
If Product.TextBox9.Text = "" Then

bookNumber.Text = ""
result.Text = ""
Else
price += 190 * Val(Product.TextBox9.Text)
book += Val(Product.TextBox9.Text)
End If
End If

If Product.CheckBox10.Checked = True Then
If Product.TextBox10.Text = "" Then

bookNumber.Text = ""
result.Text = ""
Else
price += 189 * Val(Product.TextBox10.Text)
book += Val(Product.TextBox10.Text)
End If
End If

If Product.CheckBox11.Checked = True Then
If Product.TextBox11.Text = "" Then

bookNumber.Text = ""
result.Text = ""
Else
price += 195 * Val(Product.TextBox11.Text)
book += Val(Product.TextBox11.Text)
End If
End If

If Product.CheckBox12.Checked = True Then
If Product.TextBox12.Text = "" Then

bookNumber.Text = ""
result.Text = ""
Else
price += 220 * Val(Product.TextBox12.Text)
book += Val(Product.TextBox12.Text)
End If
End If

If Product.CheckBox13.Checked = True Then
If Product.TextBox13.Text = "" Then

bookNumber.Text = ""
result.Text = ""
Else
price += 200 * Val(Product.TextBox13.Text)
book += Val(Product.TextBox13.Text)
End If
End If

If Product.CheckBox14.Checked = True Then
If Product.TextBox14.Text = "" Then

bookNumber.Text = ""
result.Text = ""
Else
price += 240 * Val(Product.TextBox14.Text)
book += Val(Product.TextBox14.Text)
End If
End If

If Product.CheckBox15.Checked = True Then
If Product.TextBox15.Text = "" Then

bookNumber.Text = ""
result.Text = ""
Else
price += 210 * Val(Product.TextBox15.Text)
book += Val(Product.TextBox15.Text)
End If
End If

If Product.CheckBox16.Checked = True Then
If Product.TextBox16.Text = "" Then

bookNumber.Text = ""
result.Text = ""
Else
price += 230 * Val(Product.TextBox16.Text)
book += Val(Product.TextBox16.Text)
End If
End If

bookNumber.Text = book
result.Text = price.ToString("#,###")
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Hide()
Product.Show()
output.Items.Clear()
bookNumber.Text = ""
result.Text = ""
End Sub

Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
output.Items.Clear()
bookNumber.Text = ""
result.Text = ""
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
End
End Sub