You are on page 1of 11

ชนิดของตัวแปร

• Byte มีค่าตั้งแต่ 0-255


• Integer ใช้เก็บเลขจำนวนเต็ม
• Long ใช้เก็บเลขจำนวนเต็ม
• Single ใช้เก็บเลขจำนวนจริ งมีจุดทศนิยม
• Double ใช้เก็บเลขจำนวนจริ งมีจุดทศนิยม
ตัวแปร (Variable)
• เมื่อมีขอ้ มูลแล้ว ก็ตอ้ งมีที่เก็บข้อมูล
• ตัวแปรคือ “ที่เก็บข้อมูล”
• เมื่อเราสร้างตัวแปร จะมีการจองพื้นที่ในหน่วยความจำ
• รู ปแบบการประกาศตัวแปร Dim ชื่อตัวแปร as ชนิดตัวแปร
• เช่น Dim a as Integer
• เช่น Dim b as String
• เช่น Dim c as Double
• ตัวที่อยูข่ า้ งหลังคือ ชนิดตัวแปร
• Dim ชื่อตัวแปร [as ชนิดตัวแปร]
• เช่น Dim Circle as Single
• Dim Score1 as Integer
สูตร พื้นที่วงกลม = r2
Object Properties ค่ าที่กำหนด
Textbox1 Name Radius
Textbox 2 Name Area
Enabled False
Command1 Name OKButton
Command2 Name CancelButton
Command3 Name AboutButton
ประกาศตัวแปรและค่าคงที่ ในส่วน General

Constant ชื่อตัวแปร = ค่ าที่ต้องการ


เขียนโปรแกรมเพือ่ หา พืน้ ทีร่ ู ปสี่ เหลียมผืนผ้ า

สู ตรสี่ เหลีย่ มผืนผ้ า


กว้ าง*ยาว
Object Property ค่าทีกำ
่ หนด
Label1 Caption ความกว้างของสี่เหลียม
Label2 Caption ความยาวของสี่เหลี่ยม
Label3 Caption พื้ นที่ของรูปสี่เหลี่ยมผืนผ้า
Text1 Name Widthness
Text ลบ Text1 ทิ้งแล้วว่างไว้
Text2 Name Length
Text ลบ Text2 ทิ้งแล้วว่างไว้
Text3 Name Area
Text ลบ Text3 ทิ้งแล้วว่างไว้
Command1 Name Okbotton
Caption ตกลง
Command2 Name Cancelbotton
Caption ยกเลิก
เขียนโปรแกรมดังนี้
• Private Sub Okbutton_Click()
Area.Text = Format((Val(Widthness.Text) *
Val(Length.Text)), "#,###,##0.00")
End Sub
• Private Sub Cancelbutton_Click()
End
End Sub

You might also like