belajar foxpro code


download program klik disini


1. The Init Method of the form

thisform.iim1 = CREATEOBJECT("imacros")  && create an instance of the iMacros Class

2. The Click Method of Command1

LOCAL iret, iplay, sdata, spos, d0, d1
* Initialize and start IM browser
IF thisform.check1.Value = 1 && if the run in system tray option is checked
 thisform.sCmdline = "-tray" && this parameter is needed
ELSE
 thisform.sCmdline = ""
ENDIF

iret = thisform.iim1.iimGetInterfaceVersion()
thisform.lbl_message = "Version: " + iret
thisform.Refresh
iret = thisform.iim1.iimInit(thisform.scmdline, .t.)
* Tip: With iret = thisform.imm1.immInit(thisform.scmdline, .f.) you can ask the Scripting Interface to
* connect to an already open IM browser. If there is no IM browser open, the return value will be negative.
iret = thisform.iim1.iimDisplay("Extract Example")
* Set a new command line for the next PLAY command
IF thisform.check1.Value = 1 && if the run in system tray option is checked
 iret = thisform.iim1.iimset("-tray", "")
ENDIF
* Note: If you do not want a tray icon to appear, use "-silent" instead of "-tray"
* Normally the Scripting Interface waits about 10 seconds before a Scripting Interface
* timeout error occurs (for example, if a user closed the IM browser while it was running,
* please do not confuse this with the BROWSER timeout errors if a web page loads to slow.)
* iret = thisform.iim1.iimSetInternal("INTERFACETIMEOUT", 1) && reduce the interface timeout to 1s
iplay = thisform.iim1.iimPlay("wsh-extract-rate")
sdata = thisform.iim1.iimGetLastMessage()
iret = thisform.iim1.iimExit
DO CASE
CASE iplay = 2
 thisform.lbl_message = "Done!"
 thisform.refresh
 * VB code uses Split function to split the string around the text "[EXTRACT]"
 * and place the result into an array
 * The UBound function is used to check if the text "[EXTRACT]" was actually found
 * ---------- original VB Code ----------------
 * sSplit = Split(sdata, "[EXTRACT]")
 * d0 = sSplit(0)
 * if UBound(Ssplit) > 0
 * d1 = sSplit(1)
 * endif
 *
 * VFP "SPLIT" code with use AT and SUBSTR:
 spos = AT("[EXTRACT]", sdata) && look for "[EXTRACT]" in the data
 IF spos = 0      && [EXTRACT] not found in data
  d0 = sdata     && set d0 to the entire string
  d1 = ""
 ELSE
  d0 = SUBSTR(sdata, 1, spos-1) && set d0 to the first part of the string
  d1 = SUBSTR(sdata, spos+9, LEN(sdata)-(spos+19))
 ENDIF
 =MESSAGEBOX("One US$ costs " + d0 + " EURO or " + d1 + " British Pounds (GBP)")
 thisform.lbl_message = "Done!"
 thisform.Refresh
CASE iplay = 1
 thisform.lbl_message = "Done, but no data extracted"
 thisform.Refresh
CASE iplay < 0
 thisform.lbl_message = sData
 thisform.Refresh
ENDCASE
RETURN

3. The Click Method of Command2

* Order Lunch
LOCAL iret
thisform.lbl_message = "Running..."
thisform.Refresh
IF thisform.check1.Value = 1       && if run macros in system tray checked
 iret = thisform.iim1.iimInit("-tray")
ELSE
 iret = thisform.iim1.iimInit()
ENDIF
iret = thisform.iim1.iimDisplay("Start First Part")
IF thisform.check1.Value = 1       && if run macros in system tray checked
 iret = thisform.iim1.iimSet("-tray", "")
ENDIF
iret = thisform.iim1.iimPlay("wsh-start")
IF iret < 0
 thisform.lbl_message = thisform.iim1.iimGetLastMessage()
 thisform.refresh
ENDIF
iret = thisform.iim1.iimDisplay("Select lunch")
iret = thisform.iim1.iimPlay("wsh-lunch")
IF iret < 0
 thisform.lbl_message = thisform.iim1.GetLastMessage()
 thisform.Refresh
ENDIF
iret = thisform.iim1.iimDisplay("Submit Form")
iret = thisform.iim1.iimPlay("wsh-submit-button")
* Typically "iimplay" is the only command where errors can occur
IF iret < 0
 thisform.lbl_message = thisform.iim1.iimGetLastMessage()
ELSE
 thisform.lbl_message = "Done!"
ENDIF
thisform.Refresh
iret = thisform.iim1.iimExit
RETURN
4. The Click Method of Command3
* Order Dinner
LOCAL iret
thisform.lbl_message = "Running..."
thisform.Refresh
IF thisform.check1.Value = 1       && if run macros in system tray checked
 iret = thisform.iim1.iimInit("-tray")
ELSE
 iret = thisform.iim1.iimInit()
ENDIF
iret = thisform.iim1.iimDisplay("Start First Part")
IF thisform.check1.Value = 1       && if run macros in system tray checked
 iret = thisform.iim1.iimSet("-tray", "")
ENDIF
iret = thisform.iim1.iimPlay("wsh-start")
IF iret < 0
 thisform.lbl_message = thisform.iim1.iimGetLastMessage()
 thisform.refresh
ENDIF
iret = thisform.iim1.iimDisplay("Select dinner")
iret = thisform.iim1.iimPlay("wsh-dinner")
IF iret < 0
 thisform.lbl_message = thisform.iim1.GetLastMessage()
 thisform.Refresh
ENDIF
iret = thisform.iim1.iimDisplay("Submit Form")
iret = thisform.iim1.iimPlay("wsh-submit-button")
* Typically "iimplay" is the only command where errors can occur
* (for example, a timeout error)
IF iret < 0
 thisform.lbl_message = thisform.iim1.iimGetLastMessage()
ELSE
 thisform.lbl_message = "Done!"
ENDIF
thisform.Refresh
iret = thisform.iim1.iimExit
RETURN
The Program file (PRG) that would be required would have the following lines of code:
DO FORM FORM1
READ EVENTS
The form would also need the following line in its Unload Method
QUIT

Iklan

loading...