Page 1 Basic - Visual Basic Foxpro 1.1. Preliminary Microsoft Visual Foxpro is a software that is saplikasi business orientation, particularly those using the database (data processing) for which data is quite a lot. Microsoft Visual Foxpro is a database management system (database management system, DBMS) that enables the creation of object-oriented applications powerful database quickly and easily. Ease of application development using Visual Foxpro, among others, because Visual Foxpro programming as well as procedural and object-oriented (object oriented programming, OOP), which go hand in hand and intertwined. A procedural programming worked together with object-oriented programming and design features Interactive Visual Foxpro make much used by the current Windows programmer. Broadly speaking, includes a database application development process as follows: Plan or design application Creating a Database (table, view, table relationships). Creating a class (event, property, method). Provide access to utility (form, menu, toolbar). Providing access to information (query, report, graph). Testing and debuging. Database design, determination of need functional Making the database: Table, View, Relation Table Page 1 of 82 Basic - Visual Basic Foxpro 4/26/2012 http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1
Basic - Visual Basic Foxpro
1.1. PreliminaryMicrosoft Visual Foxpro is a software that is saplikasi business orientation,
particularly those using the database (data processing) for which data is quite a lot.Microsoft Visual Foxpro is a database management system (database
management system, DBMS) that enables the creation of object-orientedapplicationspowerful database quickly and easily.
Ease of application development using Visual Foxpro, among others, becauseVisual Foxpro programming as well as procedural and object-oriented (objectorientedprogramming, OOP), which go hand in hand and intertwined. A proceduralprogrammingworked together with object-oriented programming and design featuresInteractive Visual Foxpro make much used by the current Windows programmer.
Broadly speaking, includes a database application development process as follows:Plan or design applicationCreating a Database (table, view, table relationships).Creating a class (event, property, method).Provide access to utility (form, menu, toolbar).Providing access to information (query, report, graph).Testing and debuging.
Provision of Accessfunctional for the user:Form, Menu, Toolbar
Provision of AccessInformation for the user:Query, Report, Graph
Testing and debuging
Application
Database Application Process Diagram
Page 2
1.2. Starting Visual FoxproThere are several ways to start the software Visual Foxpro, namely:A. Starting Visual Foxpro via the Start menu - Programs - MicrosoftVisual Foxpro.2. Starting Visual Foxpro Visual Foxpro via shortcuts.
1.3. Main Display Visual Foxpro1.3.1. Window of Microsoft Visual Foxpro
When the Microsoft Visual Foxpro is run, a window will appear as images of workbelow.
1.3.3. ToolBarToolbar, as shown below, contains icons that serve mepersingkatcommand on the Menu Bar.
1.3.4 Project Manager Window
Project Manager window shows the active project and filefiles making up the project.
Page 3
1.3.5 Properties WindowProperties window is used to modify the properties of an object.Property settingsin the Properties window can be done in various ways:
• By typing the desired value(Example: Caption property, Width).
• Choosing a value already exists (for example:Style properties, alignment).
• Selecting an existing sample (eg, propertyBackColor, ForeColor).
property can also be done through the programthrough the lines listing.
1.4. Basic Elements of Visual FoxproVisual Foxpro basic elements of data type (Data Type), Operator, Function / Procedure
and orders.1.4.1. Data Types
In making the program can not be separated from the formula and the formula yanng form of expression.In Visual Foxpro expression or formula should not be the type of data (data type) mixed.
Data types available in Visual Foxpro is a character, binary characters, numericand fractions, integers, fractions double, money numbers, date, dateplus hours, the logic (L) and memo (M).
Character TypesType the characters is a string data type in the form of sequences of characters of the alphabet, from A to Z, andnumbers 0-9 are dingggap character.Type the characters are made using the (enclosed) quotessingle or double quotation marks elbow.Example:
Binary character typeBinary character types such as regular character data type, but is permanent.
Numeric Types and fractionsNumeric type (float) is a type of fractional numbers or numbers that have a range of-0.999999999E +20 0.999999999E +19 up to.
Page 4
Integer TypeType integer is the number of data types that have a range between-2147483647up to 2147483646.
Multiple types of fractionsType multiple fractions (larger than the float type) is the type of numbers or fractional numberswhich has a range of + /-4.94065645841247E-324 to + /-8.9884656743115E307.
Numbers of type MoneyType of money is the number of data types to form the data that have a range of money-922337203685477.5808 To 922337203685477.5807. To express numbersform of money we have to use the symbol $ (default form).
Type DateType the date data type to data form the date of (date). The default format isthe shape of U.S. dates, the format mm / dd / yy (if SET CENTURY OFF).To facilitate ourestablish a specific date format, note the table below:Arrangement Format SET CENTURY OFF time
AMERICAN mm / dd / yyANSI yy.mm.ddBRITISH / FRENCH dd / mm / yy
GERMAN dd.mm.yyITALIAN dd-mm-yy
JAPAN / TAIWAN yy / mm / ddUSA mm-dd-yyMDY mm / dd / yy
DMY dd / mm / yyYmd yy / mm / dd
Type Logic (L)Logic type (L) is a data type to a form of logic TRUE (true), can use the symbol T, t, Yor FALSE (one) can use the symbol F, f, N, n.
Type of MemoMemo type is the type of data to be used as characters in length, and only appliesfor the field is not variable.Memo size is not fixed, such as characters and stored inthe file. FPT.
General type (G)Ordinary common data types can be used to store data OLE (Object Linking Embedded),such as spreadsheets, graphics, sounds created from other applications.
1.4.2. OperatorOperators are symbols that are used for a specific operation, usually used in the expression
or a specific formula.Examples of symbol - a symbol of the operator as in the following table:Operator Usefulness For the data type= Testing the similarity All types
+ Addition Numeric, Character, Date, DateTime! or NOT Negation (opposite) Logical*, / Multiplication / division Numeric
^ Perpangkat Numerical
Note: In a variable expression must have the same data type, if not the samedata type must be converted first.
1.4.3. Function / ProcedureFunction or procedure is a set of specific instructions are given for specific purposes
name, so if you want to use only the function name only.
1.5. Basic commands Foxpro
SET DEFAULT TO <path-drive>Used to activate / change the working drive.Example: SET DEFAULT TO C: \ Foxpro ?Š
CLOSE ALLUsed to close all active windows.QUITCommand to exit from Visual Foxpro.
1.6. With the application of FormForm is an object in Visual Foxpro is used to process data
table or as a basis for the design of display applications.
table or as a basis for the design of display applications.To create a form we can do with three ways:A. With the help of the Wizard2. Design3. Programming
Page 6
Form Design and Modification FormOnce we can create a form with the Wizard, and it appears there was weakness.Then forthat we must use the second way is to design the Form itself. Steps to
make / medesain form according to his own wishes as follows:In the Command Window, type the command:CREATE FORM <nama-form> orselect the menu FILE - NEW - FORM - NEW FILE, so the dialog boxappears:
Properties windowProperties window is used to modify the propertiesan object. Setting properties in the Properties windowcan be done in various ways:• By typing the desired value (for example:
Caption property, Width).• Choosing a value already exists (example: property Style,
Alignment).• Selecting an existing sample (eg BackColor property,
Activate / execute FormTo run / activate a pace that is on Commad Form Windowtype the command: DO FORM <nama-form> orSelect Menu Program - Do - <nama-file-fom> or
On the Toolbar, click the button or on the keyboard press CTRL + E.
Add / designing Control FormTo add a new control on a form, how is the click of a
controls that we want from the Form Control Toolbar, then Dilam designe Form window,Drag and Drop mouse pointer to create a grid control that we want. Somecommonly used types of controls are:
Page 7
Toolbar Name Function
LabelUsed to make a comment or descriptionon Form
TextboxA control that can contain a data field or amemory variables.
EditBoxA control that can contain a data field or amemory variables and have a scrolling bar.
Commad ButtonUsed to execute a commanda particular program.
OptionUsed to provide some choice / optionthat can only be selected one.
CheckBoxUsed to provide a choice / option that can bein select more than one.
ComboBoxUsed to input data at once canused for the selection of specific data.
Grid Used to display data from a table.
ImageIts function is to accommodate the image that usually
A. Do it yourself design the form below so that the results are as below. ThenFielding's name FORM1A.SCX store premises.
Type in the Form object InitProcedure andClick Command1 ObjeckProcedure.Thisform.text1.Value = ""Thisform.text2.Value = 0Thisform.text3.Value = 0Thisform.text4.Value = 0Thisform.text1.SetFocus ()
Type Procedure Click on the Object Command2.THISFORM.RELEASE ()
Type in Object text3 Valid ProcedureA = Thisform.text2.valueB = Thisform.text3.valueC = A * BThisform.text4.value = C
Page 8
TASK Practicum II
A. Create a program to calculate addition, subtraction, multiplication anddivision of two numbers with a design output as follows:
Conditional branching processFrom the previous meeting, a program that we make is a program that is
sequence / sequences means that the process starts from the first instruction line and continues untillast instruction in sequence. If an instruction to jump or doan instruction with a specific requirement, we need a command repetition andbranching orders.
Branching StructureConditional branching allows us to check a condition, then
based on the results of different forming operations. There are two commands inVisual Foxpro is used to create conditional branching.IF logic commands
This command conditionally executes a set of commands based on the valuelogical expression.In general, conditional branching commands commonly used amongother:• IF ... ENDIF• IF ... ELSE ... ENDIF
IF ... ENDIF commandThe syntax of this command is:
IF <kondisi>...................................................... Part of a program that is run when........................... Events are met / true
ENDIF
IF ... ELSE ... commands ENDIFThe syntax of this command is:IF <kondisi>
<Bagian Program to be executed if the condition benar>ELSE
<Bagian Program to be executed if the condition salah>ENDIF
DO CASE command ... endcaseThis command executes a number of the first order condition expression value
True (. T).The syntax of this command is:DO CASE
CASE <expresi-1><Bagian Program that will run when kondisi-1 benar>
CASE <expresi-2><Bagian Program that will run when kondisi-2 benar>
...CASE <expresi-n>
<Bagian Program that will run when kondisi-n benar>Otherwise
<Bagian Program to be executed when all conditions salah>Endcase
Make a sample form with a layoutas follows:The provisions of:Alphabeticalvalue >>> 85 alphabet A76-85 alphabet B66-75 alphabet C56-65 alphabet D<55 alphabet E
Specification >>If nilai_akhir> 55, PassedIf nilai_akhir <55, Not Passed
• In the Command1 object (the new data), enter the procedure code in the programClick.thisform.text1.value = ""thisform.text2.value = ""thisform.optiongroup1.value = 1thisform.text3.value = 0thisform.text4.value = ""thisform.text5.value = ""thisform.text1.setfocus
• On the object Command2 (Exit button), enter the code in the procedure Clickprogram.THISFORM.RELEASE
Page 13
TASK IV Practicum
A. Work on the form below to enter the list of purchasing a computer and itsperipherals.Then save it as FORM2A.SCX
Program Provisions:Types of rooms offered: ECONOMIC, BUSINESS EXECUTIVE, SWEETROOMName Guest, Visitor Type, Tariff / day, Date Entry, Exit Date and Other expenses ininputkanStaying a long time, tourism tax, the total cost of stay and pay automatically displayed.Older Staying Calculated from the date out - Check-in:Overnight fee shown is based on room type selectedRoom Types The cost of staying / day
ECONOMY 150 000BUSINESS 300 000
EXECUTIVE 600 000SWEETROOM 850 000
Tourism tax is calculated from the 10% of the cost to StayTotal Pay is calculated from (* Fee Stay Long Stay) + Other Expenses + TaxTour
2. Save the Form with the name FORM2C.SCX
Page 17
The logic of repetition / looping
Repeating the processThe loop allows us to execute one or more lines of code as much as
we want. There are three commands in Visual Foxpro used for iteration, namely:DO WHILE command - EndDoThis command executes the commands that are in the loop conditional.Iterationbe done continuously during the conditions are met (. T. or right).
File) and BOF () (Begin Of File).Functionality will provide the logic function. T. whenpointer has been at the end of the file.Form of repetition to process the data file up:
DO WHILE.NOT.EOF ().................................................. Parts of the program will be repeated.........................
EndDo
FOR command. . . EndforThis loop will execute the commands as much as we specify. Value
we specify a fixed value / constant.Repetition of the command syntax is:
FOR <var> = <nilai_awal> TO <nilai_akhir>.................................................. Parts of the program will be repeated.........................
Endfor
Example:FOR v_angka = 1 TO 10
? v_angkaEndfor
SCAN command. . . ENDSCANThese commands move the record pointer past the table being selected and
execute a command every time a record block qualified defined conditions.Repetition of the command syntax is:
SCAN [FOR <kondisi1>] [WHILE <kondisi2>]
.........................
......................... Parts of the program will be repeated
A. Make a looping program to display the numbers 1 through circuitry 10use functions and do while loop circuitry for output like the following design.Thensave the form by name FORM3A.SCX
2.Then fill the program code in accordance with the objects and events yanng required, among other things:• For button on an object, click the Click event, place the following program listing:
FOR i = 1 TO 10Thisform. List1. AddListItem ('Value For All ='+ ALLTRIM (STR (i)))Endfor
• Do While on the object key, click the Click event, place the following program listing:
i = 1DO WHILE i <= 10
thisform. List1. AddListItem ('Value Do While to=' + ALLTRIM (STR (i)))i = i +1
EndDo• Delete button on the object, click the Click event, place the following program listing:
thisform. List1. Clear• Exit button on the object, click the Click event, place the following program listing:
Functions include conversion functions, string functions, date functions, andtime etc..
4.1.1 Conversion Functions
This function is useful for changing the data elements from one type to another.Functions include:
VAL (alphanumeric string)To change the number to string numerical value
DTOC (date)To change the date field content (date) to the character
CTOD (alphanumeric string)To change the alphanumeric string into date form.
4.1.2 Functions Date And TimeTIME () Displays the time indicated at the time of the computer system
right now.DATE () Display the current dateCDOW (date) Indicate the name day of the date indicated.CMONTH (date) Indicates the name of the month indicated date.DOW (date) Show name day in
UPPER <alphanumerik>: Changing the text / letters to uppercase.LOWER <alphanumerik>: Changing the text / letters to lowercase.TRIM <alphanumerik>: To remove / cut spaces.LTRIM <aplanumerik>: To remove the spaces from the left.RTRIM <alphanumerik>: to remove the spaces from the right.Substr <alphanumerik>: to take a character / word of a sentence /word.LEFT <alpanumerik>: to take a character from the left.RIGHT <alphanumerik>: to take a character from the right.LEN <alphanumerik>: to count the number of characters.ASC <alphanumerik>: to produce a numerical value of the ASCIIcharacter
Dialog box is used to notify the information to the user / users,for example, displaying an error message.In addition, the messagebox dialog box alsoused to confirm to the user, such as confirmation of YES and NO.Mesagebox syntax:
Messagebox ("message", <tipe_kotak_dialog>, <title>)The second and third arguments can also be excluded.Example of use:
Value The selected button1 Ok2 Cancel3 Abort4 Retry5 Ignore6 Yes7 No
To state that the button is selected, it can use DO IF or CASE statements.Example of use:
Answer = MessageBox ("Are you sure you will close the program?", 4+16 + "Confirmation")IF Answer = 6 && YES if the button is selected then exit the program
THISFORM.RELEASEENDIF
Page 27
SETTING PROPERTIES AND EVENT OBJECT
Object InformationName Provide the name of an objectCaption Give the title on an objectText Almost the same as the captionFontname Determine the type of letterBackcolor Specifies the background colorForeColor Specifies the text color or font
ForeColor Specifies the text color or fontEnabled Set the control that is not accessibleVisible Hide objectsHeight Determine the height of an objectWidth Specifies the width of an objectTop Determine the position of the object from aboveLeft Determine the position of the object from the leftTabindex Menentuka order pemfocusanDragmode Set the control's behavior during dragand dropMousepointer Allows the mouse to change shape as it passes through
objectAutoSize Arranged to adjust the width of an object with a width
objectFontBold Arranged for the object in Bold / boldBackStyle Arrange for a transparent object or not.
Types of Event
Click Occurs when pressing and releasing the left mouse buttonthe object
DblClick Pressing the left button on an object x 2DragDrop Holding down the left and drag tombok objects from one place to
Another tmptActivate Occurs when an object is activeDeActiave The opposite of activateGotFocus Occurs when an object becomes the sole focusLostFocus Occurs when an object loses FocusLoad Occurs when a form is opened or invokedUnload Occurs when a form is closedInit Initial value in a formValid Provide validation of the objectKeyPress Occurred when receiving input from the keyboardInteractive Change Occurs when an object changes the value of
5.1. PreliminaryIn Visual Foxpro program we should make the program begins with a
a project, because the whole program, forms, database, report, view, query and otherlocated in the project. This will help us organize. In the projectthere are several databases that can be interconnected. Meanwhile, in the databasethere can be multiple tables, each table can be connected by a key.
5.2. ProjectProject is a place to put the data, documents, class, code / program, and
the others. To create a project there are 2 ways:A. Through the menu2. Through Visual Foxpro command (on command window)
5.2.1. Creating a Project Through the MenuTo make the Project through a menu, perform the following stepsthis:
A. On the menu, choose File> New2. Then select the option Project3. Click on New
5.2.2. Creating a Visual Foxpro Project Through CommandsTo create a Project via Visual Foxpro commands, we can mengetikkam command onjedela Command Window. The syntax is:
Create Project [namaproject]
5.3. DatabaseUnderstanding the Visual FoxPro database is different from understanding the Foxpro databaseversei before, which means the table.In Visual Foxpro, is what one type of database filewhich is extensinya. DBC. Database is a collection of tables. Create a table indatabase, has several advantages, among others:
• Determine the type of primary key or candidate• Create a permanent relationship (Persitant Relation) between tables
• Create a permanent relationship (Persitant Relation) between tables• Creating Caption (title) field for the title of Grid• Defining a long name for the field• Specifies the default value field
Page 29
• Determining the Input Mask (Format enter the field)• Make Tingger• Creating a stored procedure (Stored Procedure)• Creating a File View• Make rules and Field Level Record Level• Provide comments to the table, field checkers database.
5.3.1. Creating a DatabaseTo create a database in a project, it can be done two ways:
Creating a Database Through the Project ManagerUntuk membuat database lewat project manager, lakukan :
• Di project manager, pilih halaman Data > Database > New
Membuat Database Lewat Perintah Visual FoxproUntuk membuat database lewat perintah visual foxpro, kita dapat mengetikkan perintah berikutpada jendela Command Window :
Create Database [namadatabase]
5.4. TableTabel merupakan tempat kita meletakkan record atau data. Nama file perluasan
(Extention) file tabel adalah .DBF.5.4.1. Membuat Tabel
Cara membuat tabel ada dua cara, yaitu :• Lewat Project Manager
Untuk membuat tabel lewat project, langkahnya adalah :Pada Project Manager, pilih Data | Free Table | New
Untuk mengaktifkan tabel, maka perintahnya :USE <nama_tabel>Misalnya kita akan mengaktifkan tabel barang, maka : Use Barang
Membuka/Memodifikasi Struktur TabelPada saat tabel telah dibuat, jika terdapat kesalahan dalam pengetikan nama field, tipedata atau lebarnya dll, maka kita perlu memodifikasi struktur tabelnya tetapi harusdiaktifkan dulu nama tabelnya. Sintaknya :USE <nama_tabel> <enter>MODIFY STRUCTURE <enter>
Menampilkan struktur tabel ke layarUntuk menampilkan struktur tabel yang aktif, maka ketikkan perintah :LIST STRUCTUREDISPLAY STRUCTURE
Mengisi Data Langsung kedalam TabelUntuk memasukkan data kedalam tabel, pertama pastikan tabel tersebut sudah aktif,kemudian ketikkan perintah : APPEND <enter>
Page 32
untuk mengisi data tabel, tetapi data nya diambil dari tabel lain, langkahnya :- Aktifkan tabel yang akan diisi :
- Kemudian ketikkan perintah.APPEND FROM <nama_tabel_data> [FOR <kondisi>]
Melihat isi TabelUntuk melihat hasilnya bahwa data telah ditambahkan/dimasukkan, ketikkan perintah :BROWSE <enter>Maka akan muncul :
Mengatur Letak PointerAda beberapa perintah untuk mengatur letak pointer :- Menuju record paling atas/awal : GO TOP- Menuju record paling akhir/bawah : GO BOTTOM- Menuju record tertentu : GO <no_record>
Menghapus data dalam TabelUntuk menghapus data pada tabel, menggunakan perintah : DELETEDalam penghapusan, ada beberapa cara/teknik yaitu :
Menghapus data record ke 2, maka perintahnya :GO 2DELETEMenghapus data yang kode barangnya = B0003, maka perintahnya :DELETE FOR kode_brg='B000003'
Untuk melihat hasilnya bahwa data telah dihapus, ketikkan perintah BrowseTernyata data belum dihapus, tapi diberi tanda hitam disebelah kirinya.Karena perintahDELETE ini hanya memberi tanda pada data yang akan dihapus. Untuk melakukanpenghapusan, maka ketikkan perintah :PACK <enter>
Untuk melihat hasilnya bahwa data telah dihapus, ketikkan perintah Browse.
Mengedit data tabelUntuk mengedit/merubah data dalam tabel, kita bisa melakukan pengeditan langsungmelalui tabel, atau menggunakan perintah :EDIT [FIELDS <field1>,<field2>,…] [FOR <kondisi>]
Mengganti data dalam TabelUntuk mengganti/update/ memasukkan data pada tabel, maka digunakan perintah :REPLACE … WITH …Misalnya mengganti nama barang untuk kode barang 'B001' menjadi ”Hardiskthe command:REPLACE nama_brg WITH 'Hardisk Seagete 80 GB' FORkode_brg='B0000001'
Menutup Tabel yang sedang AktifUntuk menutup tabel yang sedang aktif, maka ketikkan perintah :CLOSE DATABASE <enter>Untuk menutup semua yang sedang aktif, maka ketikkan perintah :CLOSE ALL <enter>
Mengcopy tabel dan mengcopy struktur tabelUntuk mengcopy tabel, pertama pastikan seluruh tabel telah di tutup/nonaktif.Thenketikkan perintah :
COPY FILE <nama_tabel> TO <nama_tabel_baru> <enter>
Dengan cara ini kita telah mengcopykan struktur dan isi data tabel tersebut.Tomengcopykan struktur tabelnya, maka langkahnya :- Tutup semua tabel yang aktif
6.1. PreliminaryMemasukkan data kedalam tabel dapat dilakukan dengan beberapa cara, diantarnya
dengan langsung memasukkan kedalam tabel browse atau menggunakan Form. Formdigunakan untuk mengolah data tabel. Kita dapat menambah, mengedit/merubah, menghapusatau mencari data melalui Form yang telah kita program/rancang dengan cepat dan mudah.
A. Penyimpanan Data
Pemasukkan data pada form kemudian akan disimpan ke dalam database / tabel yang telahditentukan. Proses penyimpanan tersebut pada saat kita melakukan event pada objek padaform, misalnya pada umumnya pada objek Command button. Sintak perintah untukpenyimpanan yaitu sebagai berikut :
Replace <field_name> With <variable>
Misal Perintah dalam Pemasukkan Data Barang :Append BlankReplace kode_brg With Thisform.text1.valueReplace Nm_Brg With Thisform.text2.value. . .. . . OrAppend
Note:Perintah Append Blank digunakan apabila kita akan menambahkan data baru kedalam tabel.
Append Blank berfungsi menambahkan record kosong pada tabel. Jika penyimpanan tersebutberfungsi untuk menggantikan/replace, maka perintah Append Blank tidak digunakan.
Page 35
TUGAS PRAKTIKUM XI - 1
A. Buatlah tabel dengan struktur dibawah ini dan simpan dengan namaPEGAWAI.DBF
kemudian masukkanlah data dibawah ini :NIP NAME ADDRESS GOL TGLLAHIR JENISKE
NIP NAME ADDRESS GOL TGLLAHIR JENISKE89001 LINA JL. AHMAD YANI 2 12-02-1980 T89002 ASEP JL. ACEH RAYA 1 10-04-1981 F89003 BUDI JL. RE MARTHADINATA3 11-05-1982 F
2.Setelah data tersebut dimasukkan, kemudian buatlah desain Form dibawah ini dan simpandengan nama FORM6.SCX .
Page 36
Aturlah Properties Objek Form seperti dibawah ini:OBJECT PROPERTIES NILAI/VALUE
Ketikkan Procedure/Event pada Object dibawah ini :Form1 Procedure InitThisform.text1.Value=""Thisform.text2.Value=""Thisform.text3.Value=DATE()Thisform.text4.Value=""Thisform.text5.Value=0Thisform.combo1.Value=""Thisform.optiongroup1.Value = 1thisform.text1.SetFocus
Form1 Procedure LoadCLOSE DATABASESET TALK OFFSET ECHO OFF
Command2 Procedure ClickAPPEND BLANKreplace nip WITH thisform.text1.Valuereplace nama WITH thisform.text2.Valuereplace tgllahir WITH thisform.text3.Valuereplace alamat WITH thisform.text4.valuereplace gol WITH thisform.combo1.ValueIF thisform.optiongroup1.Value =1
replace jnske WITH .T.ELSE
replace jnske WITH .F.ENDIFreplace jamk WITH thisform.text5.Valuethisform.InitCommand3 Procedure ClickThisform.Release()
3.Kemudian masukkan data-data dibawah ini dengan menggunakan form tersebut.NIP NAME ADDRESS GOL TGLLAHIR JNSKE
89004 DONI K JL. HASANUDDIN 1 22-06-197989005 IRMAN JL. LENGKONG 1 07-07-198389006 DELLY JL. PURBARATU 3 12-07-197989007 SANDRA JL. LENGKONG 3 13-05-198089008 INDRA L JL. PANCASILA 1 01-06-198089009 MAWAR JL. AHMAD YANI 2 12-11-198089010 INDAH P JL. NATIONALITY 1 01-01-197989011 GOGON JL. PATIMURA 3 02-05-198089012 BAHRUN JL. MOH HATTA 2 14-09-198189013 VIRA JL. CICAHEUM 1 18-03-1983
Label2 Caption NameLabel3 Caption Place of birthLabel4 Caption Date of BirthLabel5 Caption EducationLabel6 Caption GenderLabel7 Caption Home AddressCombo1 RowSourceType 1 – Value
RowSource Laki-laki, PerempuanStyle 2 – DropDown List
APPEND BLANKreplace nik WITH .text1. valuereplace nama WITH .text2. valuereplace tempat_lhr WITH .text3. valuereplace tgl_lhr WITH .text4. valuereplace WITHreplace
File indeks primer atau file index utama merupakan file indeks yang tidak memperbolehkanduplikasi data kunci indeks, biasanya dipakai untuk relasi pada tabel primer (tabel satu).
b. File Indeks Kandidat (Candidate Index)File indeks kandidat merupakan file indeks seperti file indeks primer, tetapi dalam satu tabeldapat memiliki lebih dari satu file indeks kandidat.
c. File Indeks Reguler (Reguler Index)File indeks reguler merupakan file indeks yang memperbolehkan duplikasi data, biasanyadipakai pada tabel sekunder (tabel banyak).
d. File Indeks Unik (Unique Index)File indeks unik merupakan file indeks yang tidak sesuai dengan nama. File indeks ini sepertifile indeks reguler, tetapi hanya mencatat nilai kunci pertama dalam file indeks.
7.3. Membuat File IndeksUntuk membuat file index ada beberapa cara yaitu :
• Membuat File Indeks Lewat Table DesignerUntuk membuat file indeks lewat Table Designer, yaitu dengan cara berikut. PadaTableDesigner , pilih halaman Indexes .
• Membuat File Indeks Lewat Perintah Visual FoxproMembuat file indeks lewat perintah, untuk itu indeks jenis .IDX, sintaknya adalah :
Index On <field_kunci> To <FileIndeks> [Ascending|Descending]
Example:Use SiswaIndex On Nis To SiswaIdx
Page 41
7.4. Membuka File IndeksDalam Visual foxpro untuk membuka file indeks dapat dilakukan beberapa cara yaitu :
• Membuka File Indeks Lewat MenuA. Pada menu, pilih File > Open2. Pilih File of type (IDX, *.CDX), akan tampil file-file indeks3. Klik nama file indeks, kemudian klik Ok
7.7. Pencarian DataData yang kita inputkan/masukkan terkadang ingin kita lihat kembali untuk mengetahui
informasi data tersebut. Misalnya pada data pegawai, kita ingin mengetahui alamat dari pegawaiyang mempunyai NIP = “98012”. Cara pertama kita bisa melihatnya langsung ke tabel browse.Tetapi hal tersebut bisa kita lakukan mungkin untuk data yang sedikit, untuk data yang banyak,kita memerlukan waktu yang agak lama untuk pencariannya.
Cara yang cepat yaitu kita membuat Form dan merancang program untuk pencarian datathem. Proses pencarian data kita dapat menggunakan perintah :
• LOCATE <Expresi-Logika>• SEEK <var>
Misal untuk dalam pencarian data barang :Menggunakan Perintah LOCATELocate for kd_brg = Thisform.text1.valueIf Found()
*Jika diketemukan. . .
Else*Jika tidak diketemukan. . .
Endif
Menggunakan Perintah SEEKKode = Thisform.Text1.ValueSeek KodeIf Found()
A.Buatlah Form dibawah ini yang digunakan untuk mengedit/merubah data dan menghapusdata dari hasil pencarian berdasarkan NIP. Simpan form tersebut dengan nama
FORM7.SCX .
Aturlah Properties Objek Form seperti dibawah ini:OBJECT PROPERTIES NILAI/VALUE
Ketikkan Procedure/Event pada Object dibawah ini :Form1 Procedure Init*MENGOSONGKAN SEMUA OBJEK FORMThisform.text1.Value=""Thisform.text2.Value=""Thisform.text3.Value=DATE()Thisform.text4.Value=""Thisform.text5.Value=0Thisform.combo1.Value=""Thisform.optiongroup1.Value = 1
replace nip WITH thisform.text1.Valuereplace nama WITH thisform.text2.Valuereplace tgllahir WITH thisform.text3.Valuereplace alamat WITH thisform.text4.valuereplace gol WITH thisform.combo1.ValueIF thisform.optiongroup1.Value =1
replace jnske WITH .T.ELSE
replace jnske WITH .F.ENDIFreplace jamk WITH thisform.text5.ValueThisform.Init
8.1 MENGGUNAKAN OBJECT GRID, LISTBOX DAN PAGEFRAME
8.1.1. Object GridObject Grid merupakan salah satu object dalam pembuatan suatu program aplikasi yang
dapat digunakan untuk menampilkan data dari tabel atau juga dapat digunakan dalampemasukkan data kedalam tabel. Cara pembuatan Object Grid :a. Aktifkan/klik object Grid pada tollbal Form Controlsb. Kemudian Drag & Drop pada form designer, sehingga
tampilannya seperti disamping :
c. Kemudian aturlah beberapa properties Grid diantaranya:Properties Function
AllowAddNew Untuk mengaktifkan grid supaya dapat menambahrecord. [.T. Or .F.]
ColumnCount Menentukan/membuat jumlah kolom yang diperlukandidalam grid.
DeleteMark Untuk menampilkan atau menghilangkan tanda padasaat penghapusan (DELETE) pada Grid. [.T. Or .F.]
GridLine Untuk mengatur line/garis pembatas baris/kolom.ReadOnly Mengatur agar data didalam Grid hanya dapat dibaca.RecordMark Untuk menampilkan atau menghilangkan tanda pointer
didalam Grid.RecordSource Menentukan sumber data/tabel yang akan ditampilkan
didalam Grid.RecordSourceType Menentukan jenis pemanggilan sumber data tabel.
Setelah pengaturan Object Grid, kemudian atur juga properties tiap-tiap kolom didalam griddiantaranya Caption Header tiap-tiap column yang ada didalam Grid.
8.1.2.ObjectListBoxObject ListBox merupakan object yang fungsinya hampir sama dengan object Grid yaitudapat menampilkan data dari tabel atau menampilkan data yang kita atur sendiri padaproperties RowSource dan RowSourceType. Tetapi object ListBox ini tidak dapat berfungsisebagai input data kedalam tabel seperti halnya object Grid.
Page 48
Cara pembuatan Object ListBox :
a. Aktifkan/klik Toolbar ListBox pada Toolbar Form Controlsb. Kemudian Drag & Drop Object tersebut pada Form Designer sehingga
akan tampil object ListBox pada Form seperti gambar :
c. Aturlah Propertiesnya.Properties Function
RowSource Menetukan Sumber DataRowSourceType Menentukan/mengatur jenis/tipe
ditampilkan kedalam object ListBox.
8.1.3. Object PageFrame
Object PageFrame merupakan object yang berfungsi untuk membagi tampilan menjadibeberapa frame/bagian. Jadi dalam suatu form dapat dibuat menjadi beberapa page/halamanyang terpisah menggunakan object PageFrame.Langkah pembuatan PageFrame :
a. Aktifkan/Klik object PageFrame pada Toolbar Form Controlsb. Kemudian Drag & Drop object tersebut pada Form Designer
sehingga tampilan object tersebut seperti gambar.
c. Aturlah beberapa propertiesnya.
Properties FunctionPageCount Menentukan jumlah Page/halaman yang diperlukanTabStyle Mengatur bentuk tampilan perataan Tab/frame
Kemudian atur juga properties Tiap Page dalam PageFrame tersebut diantaranya Captionuntuk tiap – tiap Page.
Page 49
TUGAS PRAKTIKUM XIII
A.Pindah kan drive kerja ke drive kerja masing-masing dengan perintah SET DEFAULT TO.2. Bukalah kembali form FORM6.SCX . Kemudian aturlah kembali tampilanform tersebut dantambahkan object Grid sehingga tampilannya seperti dibawah ini :
Aturlah Properties Objek Grid seperti dibawah ini:
Tambahkan isi Procedure/Event pada Object dibawah ini :
Command1 Procedure Click (Tombol simpan)APPEND BLANKreplace nip WITH thisform.text1.Valuereplace nama WITH thisform.text2.Valuereplace tgllahir WITH thisform.text3.Valuereplace alamat WITH thisform.text4.valuereplace gol WITH thisform.combo1.ValueIF thisform.optiongroup1.Value =2
replace jeniske WITH .T.ELSE
replace jeniske WITH .F.ENDIFreplace jamk WITH thisform.text5.ValueThisform.Grid1.Refreshthisform.Init
Grid1 Procedure AfterRowColChangewith thisform
.text1.value=nip
.text2.value=nama
Page 50
.text3.value=tgllahir
.text4.value=alamat
.combo1.value=golif jnske
.optiongroup1.value=2else
.optiongroup1.value=1endif.text5.value=jamk
Endwith
3. Setelah Form tersebut selesai, jalankan Form dan lihatlah hasil didalam Grid.4.
9.1. PreliminaryDalam database yang kompleks dan besar, penggunaan file tabel data sering dipakai
lebih dari satu tabel. Sementara secara standar file tabel hanya bisa digunakan satu buah padasaat yang sama. Untuk menggunakan lebih dari satu tabel pada waktu yang bersamaandigunakan perintah SELECT .Bentuk dari perintah SELECT ini adalah :
SELECT <daerah-kerja>
Contoh : untuk membuat program yang menggunakan 2 file data GAJI.DBF denganPEGAWAI.DBF, kita dapat melakukan perintah dibawah ini :
SELECT 1 SELECT AUSE Pegawai Or USE PegawaiSELECT 2 SELECT BUSE Gaji USE Gaji
Perintah Untuk Menangani Pengolahan Banyak FileFile-file yang telah dibuka di daerah kerja masing-masing/berbeda dapat dihubungkan satu samalain dengan menggunakan perintah khusus, diantaranya perintah :
SET RELATION TO
Perintah SET RELATION TOPerintah ini digunakan untuk menghubungkan / mengaitkan file tabel database aktif dengan filedatabase yang berada di daerah kerja lain, berdasarkan suatu Field kunci tertentu.
Sintaknya :
SET RELATION TO <Field-kunci> INTO <Alias>
Note:Field kunci harus terdapat dalam kedua file tersebut.Field kunci yang dikaitkan harus telah di Index berdasarkan Field kunci.
A.Pindah kan drive kerja ke drive kerja masing-masing dengan perintah SET DEFAULT TO.2. Buatlah tabel dibawah ini untuk menampung data transaksi penjualan barang.Withstruktur seperti dibawah ini :
TRANSAKSI.DBF
Field Name Type Width DecimalNo_tran Character 5 -
Tgl_tran Date 8 -Kode_lang Character 5 -Total_byr Numeric 10 0
DETILTRAN.DBFField Name Type Width Decimal
No_tran Character 5 -
Kode_brg Character 5 -Jml_beli Numeric 3 0
3.Buatlah form untuk pengolahan data transaksi penjualan barang. Simpan form tersebtdnegan nama TRANSAK.SCX . Kemudian aturlah kembali tampilan
form tersebut dantambahkan object Grid sehingga tampilannya seperti dibawah ini :
.grid1.column5.text1.value=.grid1.column3.text1.value*.grid1.column4.text1.valueSUM temp.jml_byr TO .text5.value
ENDWITH
Text6.InteractiveChangeWITH thisform
.text7.value=.text6.value-.text5.valueENDWITH
Command1.ClickWITH thisform
IF ! EMPTY(.text1.value)SELECT 3*cari no.tran pada tabel transaksiSEEK ALLTRIM(.text1.value)IF ! FOUND()
*simpan ke tabel transaksiAPPEND BLANKreplace no_tran WITH .text1.valuereplace tgl_tran WITH .text2.valuereplace kode_lang WITH .text3.valuereplace total_byr WITH .text5.value
*simpan data pada grid ke tabel detiltranSELECT tempGO topDO while ! EOF()
IF ! EMPTY(temp.kode_brg)SELECT 4APPEND BLANKreplace no_tran WITH .text1.valuereplace kode_brg WITH temp.kode_brgreplace jml_beli WITH temp.jml_beli
10.1. PreliminaryHampir 70 persen konsentrasi pengembang (programmer) dalam membuat atau
mengembangkan sistem atau program adalah pembuatan laporan (report). Tujuan akhir sistematau program hampir dapat dipastikan adalah laporan (pencetakan) ke kertas. Inpembuatan report, pengembang harus membuat report mendekati bentuk laporan manual.Pengaturan printer yang dimilikinya juga membutuhkan waktu yang banyak, untuk itulahprogrammer harus berkonsentrasi pada laporan.
10.2. Bentuk LaporanUntuk memahami cara membuat laporan (report) di Visual Foxpro, kita harus memahami
bentuk laporan (layout), yaitu sebagi berikut :• Title , merupakan judul
laporan, yang akanmuncul pada awal laporan.• Page
Header ,dipakai untuk judul field-field (atribut) pada
dipakai untuk judul field-field (atribut) padalaporan.
• Group Header ,merupakan judul group,ditampilkan untuk mengklasifikasi record,berdasarkan group tertentu pada field.
• Detail , merupakan bagianuntuk menampilkanrecord data yang berulang.
• Group Footer , dipakai untuk meletakkan subtotal group record tertentu danletaknyabelow.
• Page Footer , merupakan catatan di bawah halaman, ditampilkan sekali akhirhalaman.• Summary , merupakan ringkasan yang akan ditampilkan diakhir report.
10.3. Objek-Objek Pembentuk LaporanDalam pembuatan report di Visual Foxpro, kita banyak menggunakan objek-
pembentuk report. Kelompok objek pada Toolbar Control Report ( ReportControl Toolbar ),seperti gambar dibawah ini :
Page 59
Icon Name FunctionSelectObject
Digunakan untuk memilih objek/mengaktifkan suatu objek didalamlaporan (memindahkan atau menghapus objek).
LabelUntuk membuat seperti Judul laporan, informasi/keterangan padalaporan.
FieldUntuk menampilkan data dari tabel dan sering diletakkan padabagian Detail pada laporan.
Line Untuk membuat garis pada desain laporan.
PictureDigunakan untuk menampilkan picture (bisa berupa logoperusahaan) pada desain laporan.
10.4. PembuatanReport SecaraWizardSama halnya dalam pembuatan Form, dalam pembuatan Report/laporan juga kita dapatmenggunakan fasilitas Wizard. Dengan menggunakan wizard, kita dapat membuat laporandengan mudah dan cepat dengan cara mengikuti langkah-langkahnya.Langkah Pembuatan Laporan secara Wizard :A. Pilih menu File – New – Report – Wizard
Pada kotak dialog Wizard Selection , Pilih :One-to-Many Report Wizard untuk membuatlaporan yang datanyalebih dari satu tabel.Report Wizard untuk membuat laporan dari satutabel.
2. Step 1, memilih Field yang akan ditampilkan pada laporan. Urutannya :Pilih tabel yang akan dibuat laporan.Pilih beberapa/seluruh field yang akan ditampilkanpada laporan.
Untuk memilih Beberapa Field satu Persatu
Untuk Memilih Seluruh Field Tabel
Klik tombol Next>
3. Step 2, menentukan apakah kita akan melakukan Grouping Record.4. Step 3, Tentukan Style laporan yang kita ingin inginkan.5.Step 4, Tentukan bentuk laporan (Column atau Row), jumlah kolom dan posisi kertas.6. Step 5, Tentukan apakah kita akan melakukan pengurutan data.7. Step 6, Tentukan Judul untuk laporan tersebut.8. Kemudian klik FINISH, simpan laporan tersebut.
Untuk memilih tabel
Page 60
Menampilkan Field Data pada laporan secara cepat :A. Pilih Quick Report dari menu Report2. Pilih nama tabel sumber data3.
10.5. Memanggil LaporanSetelah kita rancang/desain laporan sesuai dengan keinginan kita, kita tinggal
menampilkan laporan tersebut dan melakukan pencetakan ke media kertas atau printer.Tomenampilkan hasil desain laporan dari Report Desiger , kita tinggal pilih PrintPreview pada menuFile untuk melihat dilayar monitor atau pilih Print untuk mencetak ke printer.
Tetapi untuk memanggil laporan tersebut dari sebuah form yang telah kita buatsebelumnya, kita memerlukan perintah untuk menampilkan laporan tersebut.Perintah Untuk memanggil/menampilkan Laporan :
REPORT FORM <nama-file-lap.> PREVIEW Untuk mencetak ke LayarREPORT FORM <nama-file-lap.> TO PRINTER Untuk mencetak ke printer
Perintah tersebut kita ketikkan pada Command Button yang sebelumnya kita buat padaProcedure Click .
TUGAS PRAKTIKUM XXI
A. Buatlah laporan data pegawai dari tabel Pegawai.DBF dengan menggunakancara Wizard.Kemudian simpan file laporan tersebut dengan nama LAPPEG.FRX .2.Field tabel yang ditampilkan pada laporan yaitu : NIP,NAMA,TGLLAHIR,ALAMAT,GOL.3. Lakukan Peng-Group-an berdasarkan GOL.4. Pilihlah Style laporan sesuai dengan keinginan.5. Lakukan Pengurutan berdasarkan field NIP secara Ascending.6. Berilah Judul laporan LAPORAN DATA PEGAWAI7. Lihatlah hasil laporan tersebut.
A.Buatlah laporan dengan Report Designer dari tabel Pegawai.DBF dengan perintahCREATEREPORT . Rancanglah desain laporan dengan menggunakan Report Controls
Toolbar, sehinggatampilannya seperti dibawah ini.
2.Kemudian setelah laporan tersebut didesain, simpanlah laporan tersebut dengan namaLAPPEG1.FRX .3. Lihatlah hasil laporan tersebut dengan cara PRINT PREVIEW .4. Bukalah kembali File Form INPUTPEG.SCX dan tambahkan satu tombol lagipada formthem.
Aturlah Properties Command Button Tersebut :Caption : \<LAPORAN
Kemudian pada Commad Button tambahkan Procedure Click . Untukmemanggil laporanLAPPEG1.FRX dari form tersebut.
REPORT FORM LAPPEG1.FRX PREVIEW
5.Kemudian jalankan Form tersebut, cobalah untuk mengklik tombol LAPORAN untukmenampilkan laporan yang telah kita rancang/desain.6. Simpan kembali form tersebut.
TUGAS PRAKTIKUM XXIII
A.Buatlah Form dibawah ini yang digunakan untuk memanggil laporan LAPPEG1.FRX untukdicetak dilayar dan dicetak ke printer.
11.1. PreliminaryAgar program yang dibuat lebihmudah dipakai, pengembang perlu membuat menu.Menumerupakan salah satu objek Visual Foxpro. Dengan menu, pemakai akhir (end user) hanya
memilih menu untuk menjalankan aplikasi tertentu. File menu di Visual Foxpro mempunyaiextensi file .MNX dan file memonya .MPR.
11.2. Merancang MenuPerencanaan menu yang tepat sangat penting untuk meyakinkan bahwa semua fungsi
dalam aplikasi yang kita buat akan dimanfaatkan oleh pemakai secara maksimal dan tidahconfusing. Pada saat merancang menu pertimbangkan pedoman berikut ini :
Organisasikan sistem menurut tugas yang akan dilakukan user, bukan menurut hirarkiprogram dalam aplikasi.
program dalam aplikasi.Berikan judul yang memiki arti yang jelas dan mudah bagi setiap menu.Organisasikan item-item menu menurut frekuensi penggunaannya.Buat garis pemisah diantara kelompok ke kelompok item menu.Batasi jumlah item dimenu pada saat satu layar komputerJuka panjangnya melebih panjang layar komputer.Jika jumlahnya melebihi panjang layar, buatlah submeu untuk menu item yang sesuaiPilih tombol akses dan shortcut keyboard bagi menu dan item menuGunakan kata yang jelas makanya bagi2 item-item menu.Gunakan kombinasi huruf besar dan huruf kecil pada item menu.
Untuk menyajikan semua fasilitas seperti diatas, misalnya dibuatlah rancangan menuas follows:
Main Menu Submenu
File Input Data PegawaiEdit & Hapus Data Pegawai
Pencarian Data PegawaiKeluar
Report Laporan Pegawai keseluruhanLaporan Pegawai Per Golongan
Information Tentang Program
Page 64
11.3. Membuat MenuUntuk membuat menu di Visual Foxpro ada beberapa cara yang bisa kita lakukan, yaitu
include:11.3.1 Membuat Menu Lewat Menu UtamaUntuk membuat menu lewat menu tama, caranya adalah :• Dari menu utama, pilih File > New• Pilih File Type nya > Menu• Klik New File
11.3.2 Membuat MenuLewat Quick MenuUntuk membuat menu lewat Quick Menu,langkahnya adalah :• Di Project Manager, pilih tab Other > Menus• Klik tombol New• Pada kotak dialog New
Menu , klik Menu sehinggatampil Menu Designer
11.3.3 Men-generate MenuUntuk menjalankan menu harus di generate dahulu, sehingga menjadi file berekstensi.MPR .cara men-generate menu sebagai berikut :A. Di Project Manager , pilih tab Other > Menus2. Pilih Menu3. Pilih Menu > Generate ... > Generate4. Tentukan nama file menu tersebut.
11.3.4 Membuat Menu SDI ( Single-document Interface )
Menu SDI adalah menu yang tampil pada window inSingle-Document Interface (SDI). Untuk membuat menuSDI, kita harus menandai bahwa menu tersebut akandigunakan pada form SDI saat kita merancang menuthem.Untuk membuat menu SDI, pada saat menudesigner tampil :- Pilih menu View – General Options- Aktifkan tanda cek Top-Level Form
TUGAS PRAKTIKUM XXV
A. Buatlah sebuah menu dengan rancangan seperti dibawah ini :
Main Menu SubmenuFile Input Data Pegawai
Edit & Hapus Data PegawaiPencarian Data PegawaiKeluar
Report Laporan Pegawai keseluruhanLaporan Pegawai Per Golongan
Information Tentang Program
Untuk membuat submenu, pilih Result > Submenu , kemudian klik tombolEdit .
Untuk mengisi perintah pada tombol keluar, pilih Result > Procedure ,kemudian klik Edit .Kembali lagi ke pilihan Menu Bar, pilih pada Menu Level .
Ketikkan Procedure pada object FormForm1 Procedure Active
Do menu.mpr with thisform,.t.
3. Jalankan form tersebut dan lihatlah hasilnya.
Page 67
11.3.5 Kompilasi Project
Pada waktu kita membuat program, mungkin ada kesalahan yang terjadi.Tomemudahkan kita mengetahui kesalahan dan lokasi kesalahan, kita perlu men-debug kesalahan
programs.Jika ingin mendistribusikan program ke komputer lain, kita perlu mengkompilasi.Program yang telah dikompilasi dapat dipakai pada komputer yang tidak ada sistem VisualFoxpro.
Membuat File EXE dari Project pegawai :A. Buatlah program utama dan beri nama file dengan Prgutama.prg . Pada tabCode , pilihPrograms , kemudian klik New . Kemudian ketikkan listing perintah
didalamnya sepertidibawah ini :
2. Jadikan Prgutama.prg menjadi Set Main , dengan mengklik kanan padaPrgutama dan pilihSet Main .3. Di Project Manager , pilih Build... , muncul kotak Build Option .
4. Pilih Win32 Executable/COM server (exe) di Build Action5. Pilih Option > Recompile All Files , untuk mengkompilasi seluruh perintahyang pernahdikompilasi.