Wiki Home

Whats Wrong With This Picture


Namespace: VFP
One Text Box grabs the dir path (textbox2) for final output or more code to follow:
The other Text Box grabs the filename (dis.txt) to populate a table, however in the prg (01_populatevolumedbf) an error is generated and cannot recognize "MyPath2" as the true path to the filename. (ERROR: File 'c\VFP\MyPath2' does not exist)

CODE IN TEXTBOX1 - CONTROL BUTTON

cFileName= GETFILE()
this.parent.TxtBox1.value=cFileName


_________________________________________________
CODE IN TEXTBOX2 - CONTROL BUTTON

cOUTPUTDIR = GETDIR()
this.parent.TxtBox2.value = cOUTPUTDIR


_________________________________________________
CODE IN CONTROL BUTTON (START PROCESS)

open database E:\PostPJobs\PP0408005\_VFP_Project\doculex.dbc
PgrmDir='E:\PostPJobs\PP0408005\_VFP_Project\'

cOUTPUTDIR=this.parent.TxtBox2.value
cFileName=this.parent.TxtBox1.value


CURDIR(cOUTPUTDIR)
SET DEFAULT TO (cOUTPUTDIR)
MyPath = cOUTPUTDIR
MyPath2 = cFileName

SET DEFAULT TO (HOME())
CURDIR()


cFileName=this.parent.TxtBox1.value
MyPath2 = cFileName

Do PgrmDir+'01_populatevolumedbf'


MESSAGEBOX("FINISHED PROCESSING" , 0 , "FINISHED")

THISFORM.RELEASE

________________________________________________
CODE IN PROGRAM 01_POPULATEVOLUMEDBF (Where error described above is generated)

	set safety off
	USE PgrmDir + 'volume.dbf' IN 0 EXCLUSIVE
	zap	
	APPEND FROM MyPath2 delimited 	
        pack
	rein
	USE

The Class Browser on the Tools menu let's you see the code in a form. You can use it to copy and paste code. Here's the code for the form...

**************************************************
*-- Form:         frmimport (junk4.scx)
*-- ParentClass:  form
*-- BaseClass:    form
*-- Time Stamp:   09/05/04 11:08:08 AM
*
DEFINE CLASS frmimport AS form


	DoCreate = .T.
	Caption = "Import Form"
	Name = "frmImport"


	ADD OBJECT cmdfilename AS commandbutton WITH ;
		Top = 12, ;
		Left = 24, ;
		Height = 27, ;
		Width = 84, ;
		Caption = "Filename", ;
		Name = "cmdFileName"


	ADD OBJECT txtfilename AS textbox WITH ;
		Height = 23, ;
		Left = 108, ;
		Top = 14, ;
		Width = 240, ;
		Name = "txtFileName"


	ADD OBJECT cmdstart AS commandbutton WITH ;
		Top = 108, ;
		Left = 145, ;
		Height = 27, ;
		Width = 84, ;
		Caption = "Start", ;
		Name = "cmdStart"


	PROCEDURE cmdfilename.Click
		this.parent.txtFileName.value=GETFILE()
	ENDPROC


	PROCEDURE cmdstart.Click
		IF EMPTY(THISFORM.txtFileName.Value)
		  THISFORM.Release()
		  RETURN .T.
		ENDIF

		*Don't hard code pathing into programs. It just
		*makes for more to change later on.
		open database doculex.dbc

		*Keep variables local to the method.
		LOCAL lcFileName
		lcFileName = ALLTRIM(THIS.Parent.txtFileName.Value)

		*Pass variables to routines that need them.
		DO 01_populatevolumedbf WITH m.lcFileName

		MESSAGEBOX("FINISHED PROCESSING" , 0 , "FINISHED")

		THISFORM.RELEASE()
	ENDPROC


ENDDEFINE
*
*-- EndDefine: frmimport
**************************************************


Here's 01_PopulateVolumeDBF.PRG.

*01_PopulateVolumeDBF.PRG
LPARAMETERS m.tcFileName
LOCAL ;
  m.lcSafety, ;
  m.lnSelect

m.lnSelect = SELECT()
*"Volume" is a reserved word and should be avoided. Use an alias.

*If your volume.dbf is where the program started
*and you don't switch the directory, you don't
*need PgrmDir. You should pass it if you need it.

*Is volume.dbf a file in the doculex.dbc?
*If so, you could do this...

USE doculex!volume ALIAS TheTarget IN 0 EXCLUSIVE
SELECT TheTarget

*Always remember and reset environmental settings.
*Leave SET SAFETY OFF for as little time as possible.
m.lcSafety = SET("SAFETY")
SET SAFETY OFF
ZAP
SET SAFETY &lcSafety.

*tcFileName should be fully qualified.
APPEND FROM (m.tcFileName) DELIMITED
*Pack would only have been necessary if
*you deleted some records after the append.
*PACK
*REINDEX is not required because VFP updates
*the indexes as the records are added.
*REIN
*Close the file.
USE IN (SELECT("TheTarget"))
SELECT (m.lnSelect)
RETURN .T.


Mike Yearwood


Thanks that worked. I did not know how to pass the file (or path)strings to the program without hard coding the path on the form but I did not want to hard code the path in each of the programs. that will be running from the one form, so I though using to text boxes to get me string.
I will also keep all the tips in mind (not using volume as a dbf in the dcb,not rein, etc. I did not know volume was an internal name)

rookies, what will be of them without the "masters".
Category VFP Troubleshooting Category Questions
( Topic last updated: 2005.08.19 04:06:03 PM )