Pemrograman Terstruktur 4

780 views
637 views

Published on

Semoga Bermanfaat :)

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
780
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
26
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Pemrograman Terstruktur 4

  1. 1. ARRAY BY : SITI MARIYAH, SST
  2. 2. ARRAY Contoh array 1 dimensi: kelasku(1,5) = {“1A”, “1B”, “1C”, “1D”, “1E”} Data 5 kelas dimasukkan dalam satu array yang bernama kelas. Contoh array 2 dimensi : kelasku(2, 3) = {(“1A”, “1B”, “1C”),(“1E”, “1F”, “1G”)}
  3. 3. DIMENSION COMMAND Logic : DIMENSION ArrayName1(nRows1 [, nColumns1]) [AS Type] [, ArrayName2(nRows2 [,nColumns2])]
  4. 4. PARAMETER 1. ArrayName1  nama array Kita bisa membuat multiple array dengan satu dimensi hanya dengan menambahkan nama array. Contoh : DIMENSION arrayName..,arrayName2…,arrayName3…
  5. 5. PARAMETER(2) 2. nRows1 [,nColumns1]  jumlah baris dan kolom array Contoh : DIMENSION arraySatu(10)  array 1 dimensi dengan 10 baris dan 1 kolom DIMENSION arraySatu(2,4)  array 2 dimensi dengan 2 baris dan 4 kolom
  6. 6. DEKLARASI ARRAY Contoh deklarasi : DIMENSION arraySatu(10), arrayDua[2,4], arrayTiga(3,3) DIMENSION arraySatu[10], arrayDua(2,4), arrayTiga[3,3] Ukuran array tergantung pada banyaknya elemen yang disimpan dalam array tersebut. Elemen array dapat memiliki tipe data apa saja dan diinisialisasi False (.F.) untuk pertama kali.
  7. 7. OPERASI ARRAY STORE TO : Untuk menginisialisasi semua elemen dengan nilai yang sama. Contoh : DIMENSION arraySatu(10,3) STORE “initial” TO arraySatu Logic di atas untuk menyimpan string initial ke arraySatu. Sehingga initial menjadi elemen pertama (baris1,kolom1) arraySatu
  8. 8. OPERASI ARRAY(2) Array Subscript : digunakan untuk mengakses dan manipulasi elemen array.  Selain array subscript bisa juga menggunakan nama array dan indeks.  Pada array 1 dimensi, subscript digunakan untuk mengidentifikasi nomor baris array. Contoh, subscript untuk elemen yang berada di baris ketiga adalah 3  Pada array 2 dimensi, subscript digunakan untuk mengidentifikasi elemen array. Subscript yang pertama menyatakan baris, subscript kedua menyatakan kolom
  9. 9. OPERASI ARRAY(3) DIMENSION arrayName[5,2] arrayName[1,2] = 966789
  10. 10.  Creates a one- or two-dimensional array.  Visual FoxPro arrays are one-based
  11. 11.  DIMENSION is identical in operation and similar in syntax to the DECLARE command
  12. 12.  Copies elements from one array to another array.
  13. 13.  Deletes an element from a one-dimensional array, or a row or column from a two-dimensional array.
  14. 14.  Adds one record to the currently selected table for each row in an array and fills each record with data from the corresponding array row.
  15. 15.  Copies data from the currently selected table to an array.
  16. 16.  Executes the first set of commands whose conditional expression evaluates to true (.T.).
  17. 17. Contoh STORE CMONTH(DATE()) TO month DO CASE CASE INLIST(month, 'January', 'February', 'March') STORE 'first quarter' TO rpt_title CASE INLIST(month, „April', „May', „June') STORE „second quarter' TO rpt_title CASE INLIST(month, 'July', „August', „September') STORE „third quarter' TO rpt_title OTHERWISE STORE „fourth quarter' TO rpt_title ENDCASE WAIT WINDOW rpt_title NOWAIT
  18. 18.  Executes a set of commands within a conditional loop.
  19. 19.  Exits a DO WHILE, FOR, SCAN, or TRY…CATCH…FINALLY structure.
  20. 20. Contoh CLOSE DATABASES OPEN DATABASE (HOME(2) + 'Datatestdata') USE products && Opens Products table SET TALK OFF gnStockTot = 0 DO WHILE .T. && Begins loop IF EOF( ) EXIT ENDIF IF unit_price < 20 SKIP LOOP ENDIF gnStockTot = gnStockTot + in_stock SKIP ENDDO && Ends loop CLEAR ? 'Total items in stock valued over 20 dollars:' ?? gnStockTot
  21. 21.  Executes a set of commands for each element in a Visual FoxPro array or collection.
  22. 22. Contoh DIMENSION cMyArray(3) cMyArray[1] = 'A' cMyArray[2] = 'B' cMyArray[3] = 'C' FOR EACH cMyVar IN cMyArray ? cMyVar ENDFOR
  23. 23.  Executes a set of commands a specified number of times.
  24. 24. Contoh FOR gnCount = 1 TO 10 ? gnCount ENDFOR
  25. 25. Contoh OPEN DATABASE (HOME(2) + 'DataTestData') USE Customer FOR gnCount = 1 TO 10 STEP 2 GOTO gnCount DISPLAY Company ENDFOR
  26. 26.  Conditionally executes a set of commands based on the value of a logical expression.
  27. 27. Contoh USE Customer && Open customer table GETEXPR „ Enter condition to locate ' TO gcTemp; TYPE 'L' DEFAULT „ COMPANY = ""' LOCATE FOR &gcTemp && Enter LOCATE expression IF FOUND( ) && Was it found? DISPLAY && If so, display the record ELSE && If not found ? 'Condition ' + gcTemp + ' was not found ' &&Display a message ENDIF
  28. 28.  Returns program control directly to the beginning of a looping structure.
  29. 29.  Moves the record pointer through the currently selected table and executes a block of commands for each record that meets the specified conditions.

×