1 / 24

ARRAY

ARRAY . BY : SITI MARIYAH, SST. 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”)}. DIMENSION COMMAND.

chill
Download Presentation

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 BY : SITI MARIYAH, SST

  2. ARRAY Contoh array 1 dimensi: kelasku(1,5) = {“1A”, “1B”, “1C”, “1D”, “1E”} Data 5 kelasdimasukkandalamsatu array yang bernamakelas. Contoh array 2 dimensi : kelasku(2, 3) = {(“1A”, “1B”, “1C”),(“1E”, “1F”, “1G”)} DIMENSION COMMAND Logic : DIMENSION ArrayName1(nRows1 [, nColumns1]) [AS Type] [, ArrayName2(nRows2 [,nColumns2])]

  3. PARAMETER • ArrayName1  namaarray Kita bisamembuat multiple array dengansatudimensihanyadenganmenambahkannama array. Contoh: DIMENSION arrayName..,arrayName2…,arrayName3… • nRows1 [,nColumns1]  jumlahbarisdankolom array Contoh: DIMENSION arraySatu(10)  array 1 dimensidengan 10 barisdan 1 kolom DIMENSION arraySatu(2,4)  array 2 dimensidengan 2 barisdan 4 kolom

  4. DEKLARASI ARRAY Contohdeklarasi : DIMENSION arraySatu(10), arrayDua[2,4], arrayTiga(3,3) DIMENSION arraySatu[10], arrayDua(2,4), arrayTiga[3,3] Ukuran array tergantungpadabanyaknyaelemen yang disimpandalam array tersebut. Elemen array dapatmemilikitipe data apasajadandiinisialisasi False (.F.) untukpertama kali.

  5. OPERASI ARRAY STORE TO : Untukmenginisialisasisemuaelemendengannilaiyang sama. Contoh: DIMENSION arraySatu(10,3) STORE “initial” TO arraySatu Logic di atasuntukmenyimpan string initial kearraySatu. Sehingga initial menjadielemenpertama (baris1,kolom1) arraySatu

  6. OPERASI ARRAY(2) Array Subscript : digunakanuntukmengaksesdanmanipulasielemen array. • Selain array subscript bisajugamenggunakannama array danindeks. • Pada array 1 dimensi, subscript digunakanuntukmengidentifikasinomorbaris array. Contoh, subscript untukelemen yang berada di barisketigaadalah 3 • Pada array 2 dimensi, subscript digunakanuntukmengidentifikasielemen array. Subscript yang pertamamenyatakanbaris, subscript keduamenyatakankolom DIMENSION arrayName[5,2] arrayName[1,2] = 966789

  7. DECLARE Command • Creates a one- or two-dimensional array. • Visual FoxPro arrays are one-based

  8. DIMENSION Command • DIMENSION is identical in operation and similar in syntax to the DECLARE command

  9. ACOPY( ) Function • Copies elements from one array to another array.

  10. ADEL( ) Function • Deletes an element from a one-dimensional array, or a row or column from a two-dimensional array.

  11. APPEND FROM ARRAY Command • 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.

  12. COPY TO ARRAY Command • Copies data from the currently selected table to an array.

  13. DO CASE ... ENDCASE Command • Executes the first set of commands whose conditional expression evaluates to true (.T.).

  14. 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

  15. DO WHILE ... ENDDO Command • Executes a set of commands within a conditional loop. EXIT Command • Exits a DO WHILE, FOR, SCAN, or TRY…CATCH…FINALLY structure.

  16. Contoh CLOSE DATABASES OPEN DATABASE (HOME(2) + 'Data\testdata') 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

  17. FOR EACH ... ENDFOR Command • Executes a set of commands for each element in a Visual FoxPro array or collection.

  18. Contoh DIMENSION cMyArray(3) cMyArray[1] = 'A' cMyArray[2] = 'B' cMyArray[3] = 'C' FOR EACH cMyVar IN cMyArray ? cMyVar ENDFOR

  19. FOR ... ENDFOR Command • Executes a set of commands a specified number of times. Contoh FOR gnCount = 1 TO 10 ? gnCount ENDFOR

  20. Contoh OPEN DATABASE (HOME(2) + 'Data\TestData') USE Customer FOR gnCount = 1 TO 10 STEP 2 GOTO gnCount DISPLAY Company ENDFOR

  21. IF ... ENDIF Command • Conditionally executes a set of commands based on the value of a logical expression.

  22. 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

  23. LOOP Command • Returns program control directly to the beginning of a looping structure.

  24. SCAN ... ENDSCAN Command • Moves the record pointer through the currently selected table and executes a block of commands for each record that meets the specified conditions.

More Related