Visual Foxpro


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

Advertisements

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

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