belajar foxpro

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

Transcript of belajar foxpro

Page 1: belajar foxpro

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.

Database design,determination of need

functional

Making the database:Table, View, Relation Table

Page 1 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 2: belajar foxpro

Nova Ardiansyah, S.Kom -|1

Table, View, Relation Table

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.

Toolbar Menubar Command Window1.3.2. Menu Bar

Page 2 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 3: belajar foxpro

Nova Ardiansyah, S.Kom -|2

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

• Browsing (example: Picture property).

In addition to the properties window, setting

Page 3 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 4: belajar foxpro

Nova Ardiansyah, S.Kom -|3

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:

'Visual Foxpro'"STMIK Tasikmalaya"[Visual Foxpro Programming]

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.

Page 4 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 5: belajar foxpro

Nova Ardiansyah, S.Kom -|4

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.

Page 5 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 6: belajar foxpro

4

Page 5

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.

Page 6 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 7: belajar foxpro

Nova Ardiansyah, S.Kom -|5

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,

ForeColor).• Browsing (example: Picture property).

Form Control Toolbar

Form Designer window

Properties window

Page 7 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 8: belajar foxpro

Nova Ardiansyah, S.Kom -|6

• Browsing (example: Picture 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

Page 8 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 9: belajar foxpro

Nova Ardiansyah, S.Kom -|7

Imagetaken from a separate file.

Line Used to create a line.

TASK Practicum I

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:

Page 9 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 10: belajar foxpro

Nova Ardiansyah, S.Kom -|8

2. Keep the form with the name FORM1B.SCX

TASK Practicum III

A.Make a program to calculate the conversion from Celsius to reamur, fanrenheit andkelvin using the following formula:

Reamur = 4/5 celciusFanrenheit = 9/5 C + 32Kelvin = Celsius + 273

2. With a design like the following output:

3. Save the form circuitry name FORM1C.SCX

Page 9

Page 10 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 11: belajar foxpro

Branchinglogic

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

Page 11 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 12: belajar foxpro

Nova Ardiansyah, S.Kom -|9

Page 10

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

Page 12 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 13: belajar foxpro

Nova Ardiansyah, S.Kom -|10

Page 11

Step - Step:• To make the choice to use control subjects OptionGroup, steps:

o Add Optiongroup object of the form control to the form, then it will appear:

o To replace each option, right click on the object optiongroup,then select the Builder, it will appear:

o The Number Of Button, change to 2 (to determine the number of options /choicesOptiongroup on it). then replace each caption.

o Click the Layout tab, to set the display option.

Page 13 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 14: belajar foxpro

Nova Ardiansyah, S.Kom -|11

• To set the number format on text3 object, change the properties Value = 0.

Page 12

• At text3 object, enter the following program code in InteractiveChangeprocedure.

value = thisform.text3.valueif value> = 55

thisform.text5.value = "Passed"else

thisform.text5.value = "Not Passed"endif

do casecase the value of> 85

thisform.text4.value = "A"case the value of> 75

thisform.text4.value = "B"case the value of> 65

thisform.text4.value = "C"case the value of> 55

thisform.text4.value = "D"otherwise

thisform.text4.value = "E"endcase

Page 14 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 15: belajar foxpro

Nova Ardiansyah, S.Kom -|12

endcase

• 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

Page 15 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 16: belajar foxpro

Nova Ardiansyah, S.Kom -|13

Set the Object Properties form above:

OBJECT PROPERTIES VALUE /VALUEForm1 Caption PURCHASE FORM

AutoCenter . T. - TrueLabel1 Caption LIST PURCHASE COMPUTER

ACCESSORIESAutoSize . T. - TrueFontSize 10FontBold . T. - True

Label2 Caption NAME OF PURCHASERAutoSize . T. - True

Label3 Caption NAME OFAutoSize . T. - True

Label4 Caption UNIT PRICEAutoSize . T. - True

Label5 Caption NUMBER OF GOODSAutoSize . T. - True

Label6 Caption TOTAL PAIDAutoSize . T. - True

Label7 Caption PAIDAutoSize . T. - True

Label8 Caption SISAAutoSize . T. - True

Label9 Caption FACTSAutoSize . T. - True

Check1 Caption KeelAutoSize . T. - True

Command1 Caption \ <STARTCommand2 Caption \ <ENDS

Object OptionGroup1:Option1 Caption NAME OF PURCHASER

Page 14

Page 16 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 17: belajar foxpro

Page 14

AutoSize . T. - TrueOption2 Caption NAME OF PURCHASER

AutoSize . T. - True

Procedure Type / Object Event on the following:Form1 Init Procedure and Procedure Click Commad1

Thisform.text1.Value = ""Thisform.combo1.Value = ""Thisform.text2.Value = 0Thisform.text3.Value = 0Thisform.text4.Value = 0Thisform.text5.Value = 0Thisform.text6.Value = 0Thisform.check1.Value = 0Thisform.optiongroup1.Value = 0Thisform.text1.SetFocus ()

Click Command2 Procedure

THISFORM.RELEASE ()

Combo1 LostFocus Procedure

Code = Thisform.combo1.ValueDO Case

CASE code = "COMPUTER"HRG = 5000000

CASE code = "KEYBOARD"HRG = 25 000

CASE code = "MONITOR"HRG = 750 000

CASE code = "MOUSE"HRG = 30 000

EndcaseThisform.text2.Value = HRG

Valid Procedure text3

HRG = Thisform.text2.ValueNumber = Thisform.text3.ValueTb = HRG * AmountThisform.text4.Value = Tb

Valid Procedure Text5

Tb = Thisform.text4.ValueDbyr = Thisform.text5.ValueSs = Tb - DbyrDO

Page 17 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 18: belajar foxpro

Nova Ardiansyah, S.Kom -|14

DOCASE CASE ss = 0

Thisform.label8.Caption = "SISA"Kt1 = 1kt2_1 = 0kt2_2 = 1

Page 15

CASE ss> 0Thisform.label8.Caption = "SISA"Kt1 = 0Kt2_1 = 0Kt2_2 = 1

CASE ss <0Thisform.label8.Caption = "RETURN"Kt1 = 1Kt2_1 = 1Kt2_2 = 0

EndcaseThisform.text6.Value = ssThisform.check1.Value = kt1Thisform.optiongroup1.option1.Value = kt2_1Thisform.optiongroup1.option2.Value = kt2_2

2. Once completed, run the form and see the results.

TASK Practicum V

A.Make a program to shift the line from top to bottom and from left to right, * withdesign output like this!

2. Type the following program listing:- In the Timer1 object, click the Timer, put the program listing the following:

Set the object propertiesTimer1 and Timer2:

Interval= 100

Page 18 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 19: belajar foxpro

Nova Ardiansyah, S.Kom -|15

If Thisform.label1.top <= 250aid = thisform.label1.Topthisform.label1.Top = bantu +3

ELSEthisform.label1.Top = 0

ENDIF- Timer2 on an object, click the timer, put the program listing the following:

If Thisform.label1.left <= 350aid = thisform.label1.leftthisform.label1.left = bantu +3

ELSEthisform.label1.left = 0

ENDIF3. Keep the form with the name FORM2B.SCX

Page 16

TASK VI Practicum

A. Make an application program to calculate the total pay at a hotel below.Set the Display Properties Form and such so it looks like this:

Page 19 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 20: belajar foxpro

Nova Ardiansyah, S.Kom -|16

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

Repetition of the command syntax is:

Page 20 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 21: belajar foxpro

Nova Ardiansyah, S.Kom -|17

Repetition of the command syntax is:

DO WHILE.................................................. Parts of the program will be repeated.........................

EndDo

Repetition will be done when conditions are right.Repetition of this conditioncan also use conditions. T., namely:

DO WHILE. T................................................... Parts of the program will be repeated.........................[Loop][Exit]

EndDo

Example:x = 1DO WHILE x <= 20

? xx = x +1

EndDo

Page 18

Repetition EOF () and BOF () In Process AgainAn iterative process can be done in processing the records in a table

one by one until exhausted.To limit the repetition of commonly used function EOF () (End OfFile) and BOF () (Begin Of File).

Page 21 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 22: belajar foxpro

Nova Ardiansyah, S.Kom -|18

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

.........................[Loop][Exit]

ENDSCAN

Example:SCAN FOR city = "Tasikmalaya"

? name, departmentENDSCAN

Page 22 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 23: belajar foxpro

18

Page 19

TASK VII Practicum

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:

thisform. Release

Page 23 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 24: belajar foxpro

Nova Ardiansyah, S.Kom -|19

Page 20

TASK VIII Practice

A.Make a program to format the font with the font style, color and background with the designoutput as follows. Save the form by name FORM3B.SCX

2. Type the source code for each object:• In the object-option1 OptionGroup1, click Click event, place the following listing:

thisform. label1. ForeColor = RGB (255,0,0)

• In the object-Option2 OptionGroup1, click Click event, place the following listing:

thisform. label1. ForeColor = RGB (0,255,0)

• In the object-Option3 OptionGroup1, click Click event, place the following listing:

thisform. label1.

Page 24 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 25: belajar foxpro

Nova Ardiansyah, S.Kom -|20

thisform. label1.ForeColor = RGB(0,0,128)• In the object-Option3 OptionGroup1, click Click event, place the following listing:

thisform. label1. ForeColor = RGB (128,64,64)

• In the object-option1 OptionGroup2, click Click event, place the following listing:

thisform. label1. BackColor = RGB (255,255,255)

• In the object-Option2 OptionGroup2, click Click event, place the following listing:

thisform. label1. BackColor = RGB (0,0,0)

• In the object-Option3 OptionGroup2, click Click event, place the following listing:

thisform. label1. BackColor = RGB (255,255,0)

Page 21

• In the object-Option4 OptionGroup2, click Click event, place the following listing:

thisform. label1. BackColor = RGB (192,192,192)

• In the object-option1 OptionGroup3, click Click event, place the following listing:

thisform. label1. FontBold =. t.thisform. label1. FontUnderline =. F.thisform. label1. FontItalic =. F.

• In the object-Option2 OptionGroup3, click Click event, place the following listing:

thisform. label1. FontBold =. F.thisform. label1. FontUnderline =. F.thisform. label1. FontItalic =. T.

• In the object-Option3 OptionGroup3, click Click event, place the following listing:

thisform. label1. FontBold =. F.thisform. label1. FontUnderline =. T.thisform. label1. FontItalic =. F.

• The button on the object, click the Click event, Put the following listing:

thisform. label1. Caption = thisform. text1. Value

• Exit button on the object, click the Click event, Put the following listing:

Page 25 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 26: belajar foxpro

Nova Ardiansyah, S.Kom -|21

thisform. Release

Page 22

Conversion functions and MessageBox

4.1 FUNCTIONIn Visual foxpro provides some functions commonly used in

programming.Functions include conversion functions, string functions, date functions, andtime etc..

Page 26 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 27: belajar foxpro

Nova Ardiansyah, S.Kom -|22

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

week, 2 = Monday, 3 = Tuesday, 4 = Wednesday, 5 = Thursday, 6 = Friday 7 = Saturday4.1.3 String Functions

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

Page 23

TASK Practicum IX

Page 27 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 28: belajar foxpro

A. Work on the form below to use the command or function in foxpro.Then save the form by name FORM4A.SCX

Procedure Type / Object Event on the following:Procedure Text1 InteractiveChangeWITH thisform

xtext = ALLTRIM (. text1.Value). Text2.Value = LEFT (xtext, 3). Text3.Value = right (xtext, 3). Text4.Value = substr (xtext, 2.4). Text5.Value = Len (xtext). Text6.Value = Upper (xtext). Text7.Value = Lower (xtext). Text8.Value = Proper (xtext)

ENDWITH

Click Command1 ProcedureTHISFORM.RELEASE

3. Run the form and see the results.

Page 28 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 29: belajar foxpro

Nova Ardiansyah, S.Kom -|23

Page 24

TASK practicum X

A. Work using the form below to use the date of the operating functions.Save the form by name FORM4B.SCX

Set the following properties:Object Name Properties Value

Text1 Readonly T - TrueText3 Readonly T - TrueText4 Readonly T - TrueText5 Readonly T - TrueText6 Readonly T - TrueText7 Readonly T - TrueText8 Readonly T - TrueCommand1 Caption \ <RunCommand2 Caption \ <QuitTimer1 Interval 1000

Procedure Type / Object Event on the following:a. Form1 Init Procedure

SET CENTURY ON && display 4-digit date format

Page 29 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 30: belajar foxpro

Nova Ardiansyah, S.Kom -|24

SET CENTURY ON && display 4-digit date formatSET DATE BRITISH && date format dd / mm / yythisform.text2.Value = DATE () && text1 object to insert date

b. Timer1 Timer ProcedureThisform.text1.Value = TIME () && insert the time / clock is active

c. Click Command1 ProcedureWITH thisform

date =. Text2.valuetglke = DAY (date)

Page 25

harike = DOW (date)namahari = CDOW (date)year = YEAR (date)bulanke = MONTH (date)namabln = CMONTH (date)

. Text3.value = tglke

. Text4.value = harike

. Text5.value = namahari

. Text6.value = year

. Text7.value = bulanke

. Text8.value = namablnENDWITH

d. Command2 Procedure ClickTHISFORM.RELEASE ()

4.2. DIALOG / MESSAGEBOX

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:

Messagebox ("Sure will close programthis? ",

Page 30 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 31: belajar foxpro

Nova Ardiansyah, S.Kom -|25

this? ",4 +32+"Confirmation")

OrMessagebox ("Data entered already exists!")

This layout for the confirmation message "Yes" and "No".The table for this type of dialog box:

Value Box Type Buttons available / show0 Ok1 Ok, Cancel2 Abort, Retry, Ignore3 Yes, No, Cancel4 Yes, No5 Retry, Cancel

Page 26

Table Icon to be displayed in the dialog box:

Values Icon Picture Icon

16

32

48

64

Selected key values:Value The selected button

Page 31 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 32: belajar foxpro

Nova Ardiansyah, S.Kom -|26

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

Page 32 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 33: belajar foxpro

Nova Ardiansyah, S.Kom -|27

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

Page 28

Page 33 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 34: belajar foxpro

Page 28

Creating Project and Database

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

Page 34 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 35: belajar foxpro

Nova Ardiansyah, S.Kom -|28

• 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

• Lewat Perintah Visual Foxpro

Page 35 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 36: belajar foxpro

Nova Ardiansyah, S.Kom -|29

Untuk membuat tabel lewat perintah visual foxpro, ketikkan perintah berikut pada CommandWindow :Create [NamaTable]

Page 30

Maka dilayar akan Visual Foxpro akan tampil :

masukkanlah struktur tabel tersebut. Kemudian klik OK .Keterangan Structure Designer Dialog :

Nama Kolom Information

Name Menyatakan nama FieldType Menyatakan type data yang ditampungWidth Menyatakan lebar/panjang untuk data field

Decimal Menyatakan jumlah digit bagian pecahan.Null Bila muncul tanda checklist, dapat diberikan

Aturan Penulisan Field :Penulisan nama field, tidak boleh menggunakan spasi.

Page 36 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 37: belajar foxpro

Nova Ardiansyah, S.Kom --|30

Penulisan nama field, tidak boleh menggunakan spasi.Jangan menggunakan tanda koma (,), tanda pipe (|) dan tanda seru (!).

Tipe-tipe Field :

Type Field InformationCharacter (C) Untuk menampung kumpulan karakter huruf, angka dan karakter ASCII

yang dapat tercetak, lebar field tipe antara 1 sampai dengan 254karakter.

Currency Untuk menyimpan nilai mata uang dan berisi hingga 20 digit, termasuk +,-, dan . (tanda decimal)

Float (F) Merupakan tipe data special dari field numeric yang didesain untuk datascientific

Date Untuk menyimpan data tanggal memasukkan dengan format mm/dd/yy.DateTime Berisi nilai dari tanggal, waktu atau tanggal dan waktu nilai tersebut.

Datanilai tersebut disimpan dengan format yy/mm/dd/hh/mm/ssDouble Digunakan untuk melakukan perhitungan dengan nilai yang berisi tanda

desimal (float)Integer Untuk menyimpan bilangan bulat 4-byte, value -2147483647 s/d

2147483647

Page 31

Logical Untuk menyimpan masukan True (T) atau False (F)Memo Untuk menyimpan sejumlah besar data, field memo dapat berisi tipe data

apa saja.General Digunakan untuk menyimpan OLE (object Lingking and Embedding).

Character(Binary)

Digunakan untuk menampung banyaknya data karakter . dengan ukuran1 byte perkarakter s/d 254.

Memo (binary) Digunakan untuk menampung banyaknya data memo dengan perawatantanpa mengunah kode dengan ukuran 4 byte dalam tabel.

5.4.2 Operasi pada Tabel

Mengaktifkan/membuka TabelUntuk mengaktifkan tabel, maka perintahnya :

Page 37 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 38: belajar foxpro

Nova Ardiansyah, S.Kom --|31

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 :

USE <nama_tabel>- Kemudian ketikkan perintah.

Page 38 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 39: belajar foxpro

Nova Ardiansyah, S.Kom --|32

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

Page 39 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 40: belajar foxpro

32

Page 33

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

CLOSE DATABASE- Aktifkan tabel yang akan di copy

USE <nama_tabel>- Kemudian ketikkan perintah :

COPY STRUCTURE TO <nama_tabel_baru>

Page 40 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 41: belajar foxpro

Nova Ardiansyah, S.Kom --|33

Page 34

Mengolah Data DenganForm

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

Page 41 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 42: belajar foxpro

Nova Ardiansyah, S.Kom --|34

AppendBlankReplace Kode_brg with Thisform.text1.value , Nm_Brg WithThisform.text2.value ,. . .. . .

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

Page 42 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 43: belajar foxpro

Nova Ardiansyah, S.Kom --|35

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

Form1 Caption PT.CREATIVE COMPUTER TASIKMALAYAAutoCenter .T. – True

Label1 Caption PEMASUKKAN DATA PEGAWAIAutosize .T. – TrueFontSize 11FontBold .T. – True

Label2 Caption NIPAutosize .T. – True

Label3 Caption NAMA PEGAWAIAutosize .T. – True

Label4 Caption TANGGAL LAHIRAutosize .T. – True

Page 43 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 44: belajar foxpro

Nova Ardiansyah, S.Kom --|36

Autosize .T. – TrueLabel5 Caption ADDRESS

Autosize .T. – TrueLabel6 Caption GOLONGAN

Autosize .T. – TrueLabel7 Caption SEX

Autosize .T. – TrueLabel8 Caption JAM KERJA

Autosize .T. – True

Combo1 RowSource 1,2,3RowSourceType 1 - ValueStyle 2 – DropDown List

Command1 Caption \<BROWSECommand2 Caption \<SIMPANCommand3 Caption \<KELUAR

Object OptionGroup1 :Option1 Caption LAKI – LAKI

Autosize .T. – TrueOption2 Caption PEREAMPUAN

Autosize .T. – True

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

USE pegawai

Page 37

Form1 Procedure Unload

Page 44 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 45: belajar foxpro

Close Database

Command1 Procedure ClickBROWSE

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

Page 45 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 46: belajar foxpro

Nova Ardiansyah, S.Kom --|37

Page 38

TUGAS PRAKTIKUM XI - 2

A. Buatlah tabel dengan biodata seperti dibawah ini dan simpan dengan namaBiodata.DBF

2. Kemudian buat program input, simpan dengan nama Biodata.SCX . Denganlayout sepertidibawah ini :

Aturlah Properties Objek-objek :Nama Objek Properties Value

Form1 Autocenter .T.Caption Program Biodata

Label1 Caption NikLabel2 Caption Name

Page 46 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 47: belajar foxpro

Nova Ardiansyah, S.Kom --|38

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

Command1 Caption \<SimpanCommand2 Caption \<Keluar

Page 39

Kemudian isikan kode program sesuai dengan objek dan event yang diperlukan, antaraother:

• Object Form1 Procedure Load EventCLOSE DATABASESUSE biodata

• Object Form1 Procedure Init EventWITH thisform

.text1. value = ''

.text2. value = ''

.text3. value = ''

.text4. value = CTOD ('')

.text5. value = ''

.combo1. value = ''

.text6. value = ''

.image1. picture = ''

.text1. setfocusENDWITH

• Object Image1 Procedure Click EventLOCAL nFilenFile=''nFile= GETPICT ('BMP','Nama File','Buka')thisform .image1. Picture = nFile

• Object Command1 Procedure Click EventWITH thisform

APPEND BLANKreplace nik WITH .text1. valuereplace nama WITH .text2. valuereplace tempat_lhr WITH .text3. valuereplace tgl_lhr WITH .text4. valuereplace WITHreplace

Page 47 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 48: belajar foxpro

Nova Ardiansyah, S.Kom --|39

pendidikan .text5.value

replacejenis_kWITH .combo1.value

replace alamat WITH .text6. valuereplace gambar WITH .image1. picture. refresh (). init ()

ENDWITH

• Object Command2 Procedure Click EventThisform . release

Page 40

Index &Searching

7.1. PreliminaryFile Indeks merupakan file berisi data atau record yang terurut berdasarkan field tertentu.

Kegunaan utama file indeks adalah untuk mencari data tertentu berdasarkan field yangdiketahui, dan untuk pengurutan di laporan (report).

7.2. Jenis File IndeksDilihat dari jenis indeksnya, file indeks dalam Visual foxpro terdiri dari beberapa jenis :

a. File Indeks Primer (Primary Index)File indeks primer atau file index utama merupakan file indeks yang tidak memperbolehkan

Page 48 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 49: belajar foxpro

Nova Ardiansyah, S.Kom --|40

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

• Membuka File Index Lewat Perintah

Page 49 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 50: belajar foxpro

Nova Ardiansyah, S.Kom --|41

• Membuka File Index Lewat PerintahUntuk membuka file indeks lewat perintah, bentuk umum perintahnya adalah :

Set Index To <FileIndeksList>Or

Use <TableMaster> Index <FileIndeks>

Example:Set Index To SiswaIdx [atau]Use Siswa Index SiswaIdx

7.5. Memilih File IndeksUntuk menentukan file indeks yang aktif pada jenis file indeks, gunakan perintah :

Set Order To <indexNumber>

7.6. Mereindeks Data atau RecordJika sebuah file indeks sudah tidak sesuai dengan kondisi terbaru, kita dapat mereindeks

ulang (reindeks). Ada beberapa cara untuk mereindeks.Mereindeks Data Lewat Table Designer :

• Buka tabel, kemudian pilih menu View > Browse• Pilih Table > Rebuild Indexes

Mereindeks Data Lewat Perintah Visual Foxpro :Untuk mereindeks data lewat perintah, gunakan perintah seperti contoh dibawah ini :

Use SiswaReindex

Page 42

Page 50 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 51: belajar foxpro

Page 42

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()

*Jika diketemukan. . .

Else*Jika tidak diketemukan. . .

Endif

Page 51 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 52: belajar foxpro

Nova Ardiansyah, S.Kom --|42

Page 43

TUGAS PRAKTIKUM XII

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

Form1 Caption PT.CREATIVE COMPUTER TASIKMALAYAAutoCenter .T. – True

Label1 Caption PENCARIAN DATA PEGAWAIAutosize .T. – TrueFontSize 11FontBold .T. – True

Label2 Caption NIPAutosize .T. – True

Label3 Caption NAMA PEGAWAIAutosize .T. – True

Label4 Caption TANGGAL LAHIRAutosize .T. – True

Label5 Caption ADDRESSAutosize .T. – True

Label6 Caption GOLONGANAutosize .T. – True

Label7 Caption SEX

Page 52 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 53: belajar foxpro

Nova Ardiansyah, S.Kom --|43

Label7 Caption SEXAutosize .T. – True

Label8 Caption JAM KERJAAutosize .T. – True

Combo1 RowSource 1,2,3RowSourceType 1 - ValueStyle 2 – DropDown List

Command1 Caption \<CARI NIPCommand2 Caption \<EDIT DATACommand3 Caption \<HAPUS DATACommand4 Caption \<KELUAR

Object OptionGroup1 :Option1 Caption LAKI – LAKI

Autosize .T. – TrueOption2 Caption PEREAMPUAN

Autosize .T. – True

Page 44

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

*MENONAKTIFKAN OBJEK FORM KECUALI TEXT1Thisform.text2.Enabled = .F.Thisform.text3.Enabled = .F.Thisform.text4.Enabled = .F.Thisform.text5.Enabled = .F.Thisform.combo1.Enabled = .F.Thisform.optiongroup1.Enabled = .F.

Page 53 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 54: belajar foxpro

Nova Ardiansyah, S.Kom --|44

*MENGAKTIFKAN CURSOR DI TEXT1thisform.text1.SetFocus

Form1 Procedure LoadCLOSE DATABASESET TALK OFFSET ECHO OFFSET SAFETY OFF

USE pegawaiINDEX ON nip TO pegawaiSET INDEX TO pegawai

Form1 Procedure UnloadClose Database

Page 45

Command1 Procedure ClickvNIP = ALLTRIM(Thisform.text1.value)SEEK vNIPIF FOUND()

*jika diketemukan, Tampilkan datathisform.text1.Value = nipthisform.text2.Value = namathisform.text3.Value = tgllahirthisform.text4.value = alamatthisform.combo1.Value = golIF jnske

thisform.optiongroup1.Value

Page 54 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 55: belajar foxpro

Nova Ardiansyah, S.Kom --|45

thisform.optiongroup1.Value=2ELSEthisform.optiongroup1.Value =1

ENDIFThisform.text5.Value = jamk

ELSE*Jika tidak diketemukan, tampilkan pesanMESSAGEBOX("Data Tidak Diketemukan !")Thisform.initthisform.text1.SetFocus()

ENDIF

Command2 Procedure ClickIF Thisform.Command1.Caption = "\<EDIT DATA"

Thisform.Command1.Caption = "\<SIMPAN"Thisform.Command4.Caption = "\<BATAL"*MENGAKTIFKAN OBJEK FORM KECUALI TEXT1Thisform.text2.Enabled = .T.Thisform.text3.Enabled = .T.Thisform.text4.Enabled = .T.Thisform.text5.Enabled = .T.Thisform.combo1.Enabled = .T.Thisform.optiongroup1.Enabled = .T.

*MENGAKTIFKAN CURSOR DI TEXT2thisform.text2.SetFocus

ELSE

Page 46

IF Thisform.Command1.Caption = "\<SIMPAN"Thisform.Command1.caption = "\<EDIT DATA"Thisform.Command4.Caption = "\<HAPUS DATA"*merubah

Page 55 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 56: belajar foxpro

Nova Ardiansyah, S.Kom --|

*merubahdatapegawaiberdasarkanhasilpencarian

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

ENDIFENDIF

Command3 Procedure ClickTombol = Thisform.command4.CaptionIF Tombol = "\<HAPUS DATA"

DELETEPACK

ELSEThisform.command1.Caption = "\<EDIT DATA"

ENDIFThisform.InitCommand4 Procedure ClickThisform.Release()

Page 56 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 57: belajar foxpro

|46

Page 47

ObjectFormII

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.

Page 57 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 58: belajar foxpro

Nova Ardiansyah, S.Kom --|47

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

Page 58 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 59: belajar foxpro

Nova Ardiansyah, S.Kom --|48

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:

Page 59 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 60: belajar foxpro

Nova Ardiansyah, S.Kom --|49

Aturlah Properties Objek Grid seperti dibawah ini:OBJECT PROPERTIES NILAI/VALUE

Grid1 ColumnCount 7DeleteMark .F. – FalseReadOnly .T. – TrueRecordSource EmployeeRecordSourceType 2 – Prompt

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.

Page 60 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 61: belajar foxpro

Nova Ardiansyah, S.Kom --|50

4.Simpan kembali Form tersebut .

TUGAS PRAKTIKUM XIX

A. Bukalah kembali Form FORM7.SCX , kemudian tambahkan Object grid padaform tersebutsehingga tampilan form tersebut seperti dibawah ini :

Aturlah Properties Objek Grid seperti dibawah ini:

OBJECT PROPERTIES NILAI/VALUEGrid1 ColumnCount 7

DeleteMark .F. – FalseReadOnly .T. – TrueRecordSource EmployeeRecordSourceType 2 – Prompt

Tambahkan isi Procedure/Event pada Object dibawah ini :Command1 Procedure ClickThisform.grid1.refresh

Command2 Procedure ClickThisform.grid1.refresh

2. Jalankan Form tersebut, kemudian lihatlah hasilnya didalam grid tersebut.3. Simpan kembali Form tersebut.

Page 51

Page 61 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 62: belajar foxpro

Bekerja Dengan MultiTable

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.

Page 62 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 63: belajar foxpro

Nova Ardiansyah, S.Kom --|51

Page 52

TUGAS PRAKTIKUM XX

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 :

Page 63 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 64: belajar foxpro

Nova Ardiansyah, S.Kom --|52

Page 53

Aturlah Properties :Object Properties Value

Form1 Autocenter .T.Borderstyle 2 – Fixed DialogCaption Transaksi Penjualan Barang

Text1 Maxlength 5Text3 Maxlength 5Text4 ReadOnly .T.Edit1 ReadOnly .T.Text5 ReadOnly .T.Text7 ReadOnly .T.Grid1 AllowAddNew .T.

DeleteMark .F.RecordSource TempRecordSourceType 1 – AliasColumnCount 5

Grid1.Column1.Header1 Caption Kode BarangGrid1.Column2.Header1 Caption Nama BarangGrid1.Column2.Header1.Text1 Enabled .F.Grid1.Column3.Header1 Caption PriceGrid1.Column3.Header1.Text1 Enabled .F.Grid1.Column4.Header1 Caption Jml BeliGrid1.Column5.Header1 Caption Jml BayarGrid1.Column5.Header1.Text1 Enabled .F.Command1 Caption \<SimpanCommand2 Caption \<Keluar

Ketikkan listing procedure dibawah ini :Form1.LoadSET TALK OFFSET ECHO OFF

Page 64 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 65: belajar foxpro

Nova Ardiansyah, S.Kom --|53

SET ECHO OFFSET SAFETY OFF

CLOSE DATABASESCREATE TABLE temp.dbf (kode_brg c(5), nama_brg c(25), harga n(10), jml_beli n(3),;

jml_byr n(10))USE tempAPPEND BLANKCLOSE DATABASES

SELECT 1USE barangINDEX ON kode_brg TO barangUSE barang INDEX barang

SELECT 2USE pelangganINDEX ON kode_lang TO pelangganUSE pelanggan INDEX pelanggan

Page 54

SELECT 3use transaksiINDEX ON no_tran TO transaksiUSE transaksi INDEX transaksi

SELECT 4USE detiltran ALIAS detiltran

SELECT 20USE temp ALIAS temp

Form1.InitWITH thisform

.text1.value=""

.text2.value=DATE()

.text3.value=""

Page 65 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 66: belajar foxpro

Nova Ardiansyah, S.Kom --|54

.text3.value=""

.text4.value=""

.edit1.value=""

.text5.value=0

.text6.value=0

.text7.value=0

SELECT tempZAPAPPEND BLANK

.grid1.refresh

.text1.setfocusENDWITH

Form1.UnloadCLOSE DATABASESDELETE FILE temp.dbf

Text1.LostfocusWITH thisform

IF ! EMPTY(.text1.value)SELECT 3SEEK ALLTRIM(.text1.value)IF FOUND()

MESSAGEBOX("No.Transaksi sudah ada !",0+16,"Perhatian").text1.setfocus

Page 55

ENDIFENDIF

ENDWITH

Text3.LostfocusWITH thisform

IF ! EMPTY(.text3.value)

Page 66 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 67: belajar foxpro

Nova Ardiansyah, S.Kom --|55

IF ! EMPTY(.text3.value)SELECT 2SEEK ALLTRIM(.text3.value)IF FOUND()

.text4.value=nama_lang

.edit1.value=alamatELSE

MESSAGEBOX("Kode Pelanggan tidak ada!",0+16,"Perhatian").text3.setfocus()

ENDIFENDIF

ENDWITH

Grid1.Column1.Text1.LostfocusWITH thisformIF ! EMPTY(.grId1.column1.text1.value)

SELECT 1SEEK ALLTRIM(.grid1.column1.text1.value)IF FOUND()

.grid1.column2.text1.value=nama_brg

.grid1.column3.text1.value=hargaELSE

MESSAGEBOX("Kode brg tidak ada !",0+16,"Perhatian").grid1.column1.text1.setfocus

ENDIFENDIFENDWITH

Grid1.Column1.Text1.KeyPressLPARAMETERS nKeyCode, nShiftAltCtrl*jika tekan tombol F5IF nKeyCode=-4

DO FORM listbrgENDIF

Page 56

Page 67 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 68: belajar foxpro

Page 56

Grid1.Column4.text1.InteractiveChangeWITH thisform

.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

SELECT 1

Page 68 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 69: belajar foxpro

Nova Ardiansyah, S.Kom --|56

SELECT 1SEEK ALLTRIM(temp.kode_brg)replace stok WITH stok-temp.jml_beli

Page 57

ENDIFSELECT tempskip

ENDDOENDIF

ELSEMESSAGEBOX("Masukkan No.Transaksi!",0+16,"Perhatian").text1.setfocus

ENDIF.init

ENDWITH

Command2.ClickThisform.release

4.Buatlah Form seperti dibawah ini untuk menampilkan list data barang, kemdian simpandengan nama LISTBRG.SCX

Aturlah Properties List1 :ColumnCount = 2Rowsource = BarangRowSourceType = 2 – Alias

Ketikkan Listing Procedure :

List1.DblClick danCommand1.Clicktransak.grid1.column1.text1.value=barang.kode_brgtransak.grid1.column1.text1.lostfocusthisform.Release

Command2.ClickThisform.release

Page 69 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 70: belajar foxpro

Nova Ardiansyah, S.Kom --|57

Page 58

CreatingReports

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

Page 70 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 71: belajar foxpro

Nova Ardiansyah, S.Kom --|58

Header ,Merupakanjudulhalaman,yang

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

Page 71 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 72: belajar foxpro

Nova Ardiansyah, S.Kom --|59

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.

Page 72 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 73: belajar foxpro

Nova Ardiansyah, S.Kom --|

3.Pilih bentuk laporan (Column atau Row)

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.

Page 73 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 74: belajar foxpro

|60

Page 61

TUGAS PRAKTIKUM XXII

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.

Page 74 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 75: belajar foxpro

Nova Ardiansyah, S.Kom --|61

Aturlah properties masing-masing object form tersebut.2. Simpan form tersebut dengan nama CETAKLAP.SCX

Page 62

TUGAS PRAKTIKUM XXIV

A.Buatlah kembali form dibawah ini untuk mencetak data pegawai per golongan dari laporanLAPPEG1.FRX kelayar atau ke printer.

Aturlah properties masing-masing object form tersebut.2. Simpanlah form tersebut dengan nama CETAKGOL.SCX

Page 75 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 76: belajar foxpro

Nova Ardiansyah, S.Kom --|62

Page 63

Membuat Menu &Kompilasi

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.

Page 76 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 77: belajar foxpro

Nova Ardiansyah, S.Kom --|63

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 Menu

Page 77 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 78: belajar foxpro

Nova Ardiansyah, S.Kom --|64

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.

Page 65

11.3.4 Membuat Menu SDI ( Single-

Page 78 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 79: belajar foxpro

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 .

Page 79 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 80: belajar foxpro

Nova Ardiansyah, S.Kom --|65

Page 66

Kemudian ketikkan listing programnya sebagai berikut :

2.Buatlah sebuah form untuk digunakan menampilkan menu. Rancanglah form tersebut sepertidibawah ini dan kemudian simpan dengan nama MenuUtama.scx :

Properties Form :Object Properties Nilai/Value

Form1 Caption Program Aplikasi PegawaiShowWindow 2 – As Top-Level Form

Page 80 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 81: belajar foxpro

Nova Ardiansyah, S.Kom --|66

WindowState 2 – Maximized

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 .

Page 81 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...

Page 82: belajar foxpro

Nova Ardiansyah, S.Kom --|67

4. Pilih Win32 Executable/COM server (exe) di Build Action5. Pilih Option > Recompile All Files , untuk mengkompilasi seluruh perintahyang pernahdikompilasi.

Page 82 of 82Basic - Visual Basic Foxpro

4/26/2012http://translate.googleusercontent.com/translate_c?hl=en&prev=/search%3Fq%3Dmen...