This sample code for get data temperature in clipper :
FUNCTION GetTemperature()
LOCAL buff_size,com_ok,init_ok,c_input,l_send, t01,a01,b01,VAL_01
a01 := 0
b01 := 0
t01  := 0

buff_size := 4000 && 4000 byte buffer
com_ok := COM_OPEN(1,buff_size) && COM1: open
DO WHILE .T. .and. INKEY()<> K_ESC
IF .NOT. com_ok
? “It was not possible to open interface.”
ELSE
init_ok = COM_INIT(1, 9600, “N”, 8, 1)
IF .NOT. init_ok
alert(“It was not possible to initialize the interface”)
ELSE
** SENSOR 01
l_send = COM_SEND(1,”:01R;”)
INKEY(0.5)
c_input = COM_READ(1,COM_COUNT(1)) && Read in 10
IF LEN(ALLTRIM(c_input)) <= 0
t01 = 0
ENDIF
a01 = AT(“01+”,c_input )
IF a01 > 0
b01 = AT(“*”,SUBSTR(c_input ,a01,9))
IF b01 > 0
VAL_01 = VAL(SUBSTR(c_input ,(a01+b01)-5,4))
t01 = VAL_01
ENDIF
ENDIF

COM_FLUSH(1)

@XX,XX SAY TRANSFORM(t01,”###.##”)

ENDIF

ENDIF

IF LastKey() = 27 &&K_ESC
COM_CLOSE(1)
ENDIF
ENDDO

RETURN .T.

CLEAR ALL
#DEFINE STARTXL_LOC      “Starting Excel……..”
#DEFINE ENDDATA_LOC “Transfer Finished..”
LOCAL xlsheet,XLApp,tmpsheet,n_hit,Title01,Title02

Title01 = “LIST OF EMPLOYEES”
Title02 = “COMPANY”

WAIT WINDOW STARTXL_LOC NOWAIT
tmpsheet=GetObject(”,’excel.sheet’)
XLApp=tmpsheet.application
XLApp.Visible=.t.
XLApp.WorkBooks.Add()
XLSheet=XLApp.ActiveSheet
XLSheet.Cells(1,01).Value = Title01
XLSheet.Cells(2,01).Value = Title02
XLSheet.Cells(4,01).Value = “ID”
XLSheet.Cells(4,02).Value = “NAME”
XLSheet.Cells(4,03).Value = “DIVISION”
XLSheet.Cells(4,04).Value = “DATE HIRED”

*!* Open table employee

USE employee AGAIN ALIAS ListEmployee IN 0
SELECT ListEmployee
GO TOP
n_hit = 5
SCAN FOR !EOF()
n_hit = n_hit + 1
XLSheet.Cells(n_hit,01).Value = ListEmployee.ID
XLSheet.Cells(n_hit,02).Value = ListEmployee.NAME
XLSheet.Cells(n_hit,03).Value = ListEmployee.DEPT
XLSheet.Cells(n_hit,04).Value = ListEmployee.DATEHIRED
ENDSCAN
WAIT WINDOW ENDDATA_LOC TIMEOUT 2
SELECT ListEmployee
USE

This sample code for disable menu Data – Employee when employee form activated and enabled when form Employee deactivated.

Create menu Master :

Click “Edit” and create submenu “Employee” :

Click Create button and write command :

DO FORM employee.scx

And save ( CTRL+W).

Then click Option button and put variable mnDataEmployee on ‘Skip For:”

Note: Variable must be declared on General Setup in menu Master :

PUBLIC mnDataEmployee as Boolean

STORE .F. TO mnDataEmployee

Save and Generate menu master.

Open form Employee and add code in :

FormLoad procedure :

mnDataEmployee = .T.

SET SKIP OF BAR 1 OF Data mnDataEmployee

FormRelease procedure :

mnDataEmployee = .F.

SET SKIP OF BAR 1 OF Data mnDataEmployee

Save and close form employee.

Run command with DO master.mpr

FUNCTION SayRupiah(par)
LOCAL nTot,nRp,cRp,cRupiah
ntot = 0
cRupiah=””

lExit = .F.
nTot  = par

cTotal= ALLTRIM(STR(nTot))

FOR i=1 TO LEN(cTotal)
nRp= (LEN(SUBSTR(cTotal,i)))
cRp= SUBSTR(cTotal,i,1)

DO CASE
CASE nRp > 0
GetDetailRupiah(nRp,cRp,@cRupiah)
CASE nRp < 0
nRp= nRp + 3
GetDetailRupiah(nRp,cRp,@cRupiah)
CASE nRp = 0
cRupiah = cRupiah
ENDCASE
NEXT

IF nTot – INT(nTot) > 0
cRupiah = cRupiah
ENDIF

RETURN cRupiah + “RUPIAH “
(more…)

On Form1.Refresh :
THISFORM.txtNoPokok.Value = ”
THISFORM.txtNoPokok.Enabled= .T.
THISFORM.txtNoInduk.Value = ”
THISFORM.txtNama.Value = ”
THISFORM.txtUnit.Value = ”
THISFORM.cmdSave.Enabled = .F.
THISFORM.cmdCancel.Enabled = .F.
THISFORM.cmdErase.Enabled= .F.

SELECT datakar.no_pokok,datakar.no_induk,datakar.nama,datakar.unit from datakar INTO CURSOR ListKar
SELECT ListKar
INDEX on RIGHT(ALLTRIM(no_pokok),4) TAG nop ADDITIVE
THISFORM.grid1.RecordSourceType = 1
THISFORM.grid1.RecordSource = “listkar”
THISFORM.grid1.column1.Width = 100
THISFORM.grid1.column1.header1.Caption = ‘ID #1′
THISFORM.grid1.column2.Width = 100
THISFORM.grid1.column2.header1.Caption = ‘ID #2′
THISFORM.grid1.column3.Width = 150
THISFORM.grid1.column3.header1.Caption = ‘Name’
THISFORM.grid1.column4.Width = 125
THISFORM.grid1.column4.header1.Caption = ‘Unit’
THISFORM.txtNoPokok.SetFocus

On Form1.Unload :
IsFormActive = .F.
LogData.ENABLED = .T.

(more…)

Within a timer, this function can be running periodically to reduce memory usage vfp application.
I have already try and work with well.

Function ReduceMemory()

Declare Integer SetProcessWorkingSetSize In kernel32 As SetProcessWorkingSetSize  ;
Integer hProcess , ;
Integer dwMinimumWorkingSetSize , ;
Integer dwMaximumWorkingSetSize
Declare Integer GetCurrentProcess In kernel32 As GetCurrentProcess
nProc = GetCurrentProcess()
bb = SetProcessWorkingSetSize(nProc,-1,-1)
*EOFunct ReduceMemory()

this function created by Bernard BoutReduce

This sample VFP code for read data from temperature sensor :

*** Com1 setting = “9600,n,8,1″
thisform.MsCom.settings = “9600,n,8,1″
thisform.timer1.Interval = 1000

** SENSOR 01
VAL_01 = ASC(substr(thisform.MsCom.Input,5,5))
thisform.text1.Value = VAL_01

** SENSOR 02
thisform.MsCom.Output = ’02R;’
VAL_02 = ASC(substr(thisform.MsCom.Input,5,5))
thisform.text2.Value = VAL_02

** SENSOR 03
thisform.MsCom.Output=':03R;’
VAL_03 = ASC(substr(thisform.MsCom.Input,5,5))
thisform.text3.Value = VAL_03

** SENSOR 04
thisform.MsCom.Output=':04R;’
VAL_04 = ASC(substr(thisform.MsCom.Input,5,5))
thisform.text4.Value = VAL_04

** SENSOR 05
thisform.MsCom.Output=':05R;’
VAL_05 = ASC(substr(thisform.MsCom.Input,5,5))
thisform.text5.Value = VAL_05

thisform.MsCom.inBufferCount = 0
thisform.MsCom.Refresh

Follow

Get every new post delivered to your Inbox.