1 / 11

Lab 8 ตัวแปรและชนิดข้อมูล

Lab 8 ตัวแปรและชนิดข้อมูล. ทฤษฎีที่เกี่ยวข้อง. การประกาศตัวแปรระดับ Form. เป็นการประกาศตัวแปรให้สามารถเรียกใช้ได้จากทุก ๆ ส่วนในโปรแกรม ตัวอย่าง การประกาศตัวแปรระดับฟอร์ม. การกำหนดค่าเริ่มต้นให้กับตัวแปรระดับ Form. ตัวอย่าง. รูปแบบ : ชื่อตัวแปร = Expression

lynley
Download Presentation

Lab 8 ตัวแปรและชนิดข้อมูล

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. Lab 8 ตัวแปรและชนิดข้อมูล ทฤษฎีที่เกี่ยวข้อง

  2. การประกาศตัวแปรระดับ Form • เป็นการประกาศตัวแปรให้สามารถเรียกใช้ได้จากทุก ๆ ส่วนในโปรแกรม • ตัวอย่าง การประกาศตัวแปรระดับฟอร์ม

  3. การกำหนดค่าเริ่มต้นให้กับตัวแปรระดับ Form • ตัวอย่าง รูปแบบ: ชื่อตัวแปร = Expression ***Expression หมายถึงค่าที่ได้จากการคำนวณ ค่าคงที่ หรือตัวแปรอื่น ๆ

  4. การเพิ่มข้อมูลลงใน ListBox • ตัวอย่าง:เมื่อกดปุ่ม cmdAddList จะเป็นการเพิ่มข้อมูลดังกล่างลงใน list ชื่อ lstScore ชื่อ List ข้อความที่ต้องการเพิ่มเข้าไปใน list คำสั่ง

  5. การเคลียร์ค่าใน ListBox • ใช้คำสั่ง lstScore.Clear • เมื่อ lstScore คือ ชื่อ ListBox • การเคลียร์ค่าใน TextBox???  สอนแล้ว

  6. การแปลงข้อมูลจาก TextBox เป็นตัวเลข • เป็นการแปลงข้อมูลจาก String เป็น Number • ใช้คำสั่ง: เช่น • CInt(Textbox.Text) เพื่อแปลงไปเป็นจำนวนเต็ม (Integer) • CDbl(Textbox.Text) เพื่อแปลงไปเป็นจำนวนจริง (Double) • หรือ CDbl(Integer) เป็นการแปลง Integer ไปเป็น Double CInt(Double) เป็นการแปลง Double ไปเป็น Integer • Str(Integer หรือ Double) เพื่อแปลงตัวเลขเป็นข้อความ • ตัวอย่าง:intSum = intSum + CInt(txtScore.Text)

  7. การเปลี่ยน Caption ที่ Label • ใช้คำสั่ง:ldbOrder.Caption = “นักเรียนคนที่ 1” • ldbOrderหมายถึง ชื่อ Label • “นักเรียนคนที่ 1” หมายถึง ข้อความที่ต้องการให้ปรากฏ

  8. คำสั่งที่ใช้ในการเรียก Form อื่น ๆ • ตัวอย่าง เรียก Form2 เมื่อกดปุ่ม CmdStart

  9. เฉลย Lab 8

  10. ตัวอย่าง Form1

  11. ตัวอย่าง Form2

More Related