1 / 12

? ARRAY คืออะไร

? ARRAY คืออะไร. วิธีการเขียนโปรแกรมเพื่อทำงานกับข้อมูล โดยที่ข้อมูลนั้นจะต้อง เป็นประเภทเดียวกัน | ตัวเลข , ตัวอักษร มีขนาด เท่ากัน. ? วิธีการประกาศตัวแปร. Dim ชื่ออะเรย์ ( ขนาดอะเรย์ ) As ชนิด ข้อมูล. Dim SCORE As INTEGER. Dim SCORE ( 5 ) As INTEGER. 1.Array กำหนดค่าตัวแปร.

erica
Télécharger la présentation

? ARRAY คืออะไร

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. ? ARRAY คืออะไร วิธีการเขียนโปรแกรมเพื่อทำงานกับข้อมูล โดยที่ข้อมูลนั้นจะต้อง เป็นประเภทเดียวกัน | ตัวเลข , ตัวอักษร มีขนาดเท่ากัน

  2. ? วิธีการประกาศตัวแปร Dimชื่ออะเรย์(ขนาดอะเรย์) Asชนิดข้อมูล DimSCOREAsINTEGER DimSCORE(5) AsINTEGER

  3. 1.Arrayกำหนดค่าตัวแปร Dim ชื่อตัวแปรอะเรย์() AS ชนิดตัวแปร = { ข้อมูล1,ข้อมูล2,……ข้อมูลสุดท้าย} DimNUM() AsINTEGER = {10,20,30} DimDay( ) AsSTRING = { Monday , Tuesday , Wednesday , Thursday , Friday , Saturday , Sunday }

  4. 2.Arrayไม่กำหนดตัวแปร Dim ชื่อตัวแปรอะเรย์(ขนาดของอะเรย์) AS ชนิดตัวแปร DimNUM(10) AsINTEGER DimDay(7) AsSTRING

  5. ? ส่วนประกอบของ ARRAY index ตัวแปรสำหรับเก็บค่า ตัวแปรชี้ตำแหน่ง num Dim num(5) as Integer Dim index as integer 0 1 2 3 4

  6. ? ส่วนประกอบของ ARRAY index 3. เครื่องมือที่ใช้ในการวน Loop Array For … Next num Dim num(5), index as integer For Index = 0 To 4 str = “ลำดับที่” & num(index) lst.items.add(str) Next 0 1 2 3 4 Array จะต้องมีตัวแปรชี้ตำแหน่ง ใช้ index บอกตำแหน่ง

  7. การใช้ Array – 1. เพื่อแสดงผล 1.จงเขียนโปรแกรมแสดงตัวเลขจำนวนเต็ม 5 จำนวนจากอะเรย์ Dim num( ) as integer = {0,1,2,3,4} Dim i as integer Dim Str as string For i = 0 to 4 Str = “ลำดับที่” & num(index) lstbox.items.add(Str) Next i i i i i 0 1 2 3 4

  8. การใช้ Array – 2. นำ Array มาคำนวณ 2.จงเขียนโปรแกรมในการแสดงตัวเลขจำนวนเต็ม 10 ค่าจากอะเรย์ และแสดงผลรวมของจำนวนทั้งหมด Dim num( ) as integer = {0,1,2,3,4,5,6,7,8,9} Dim Index,Total as integer Dim Str as string For index = 0 to 9 Total = total + num(index) Str = “ลำดับที่” & num(index) lstbox.items.add(Str) Next Txt1.text = Total

  9. ใช้ Inputboxในการรับค่า การใช้ Array – 3. รับค่ามาใส่ใน Array Dim num(5) as integer Dim Index as integer Dim Str as string For Index = 0 to 4 num(Index) = inputbox (“กรอกจำนวน”,”กรอกข้อมูล”) Str = “ลำดับที่” & Index & “มีค่า” & num(index) lstbox.items.add(Str) Next Dim num(5) as integer Dim Index as integer Dim Str as string For Index = 0 to 4 num(Index) = inputbox (“กรอกจำนวน”,”กรอกข้อมูล”) Next For Index = 0 to 4 Str= “ลำดับที่” & Index & “มีค่า” & num(index) lstbox.items.add(Str) Next

  10. แบบทดสอบ Array 1.จงเขียนโปรแกรมโดยใช้อะเรย์ในการรับตัวเลขจำนวนเต็ม 10 ค่า เพื่อแสดงจำนวนเต็มที่มีค่าน้อยกว่าค่าเฉลี่ยออกทางจอภาพ

  11. แบบทดสอบก่อน Midterm จงออกแบบโปรแกรมคิดเงินเดือนพนักงาน โดยแบ่งระดับการคิดเงินเดือนออกเป็นออกเป็น 3 กลุ่มดังนี้ ผู้บริหาร หัวหน้างาน พนักงาน โดยคิดออกแบบให้รับจำนวนวันทำงานในแต่ละเดือนจำนวน 12 เดือน หากเป็นพนักงานในระดับผู้บริหารจะทำงานได้เงินวันละ 500 บาท หากเป็นพนักงานในระดับหัวหน้างานจะทำงานได้วันละ 400 บาท หากเป็นพนักงานธรรมดาจะทำงานได้เงินวันละ 250 บาท จงคำนวณหาเงินเดือนของพนักงานใน 1 ปีพร้อมแสดงจำนวนเงินออกทางหน้าจอ

  12. Dim index As Integer = 1 Dim total, day, index, choice, wage As Integer Dim str As String choice = Val(Me.rbl1.Text) If choice = 1 Then wage = 500 ElseIf choice = 2 Then wage = 400 Else wage = 250 End If Do While index <= 12 day = InputBox("กรอกจำนวนวัน", "กรอกข้อมูล") total = wage * day str = "จำนวนวัน" & day & " ได้เงิน " & total lst1.Items.Add(str) index += 1 Loop

More Related