Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What is the best way to import a text file into a form? 2

Status
Not open for further replies.

montypython1

Technical User
Jan 12, 2005
187
US
Greetings,

What is the best way to import a text file into a form?

FILETOSTR() works, but it does not allow the use of "thisform." properties. I receive the error "THISFORM can only be used within a method".

Isn't there a way to import the text file so that when the user clicks the button, it thinks it is running within the form method? This would allow me to use form properties, rather than having to pass parameters.

This is important to me because I need a flexible way to allow the same button on a specific form to do different things for different customers (ex: the same button would run program "A" for one user, then run program "B" for another user, then run program "C" for another user, and so on). Then, if a customer needs a custom report, it would be a simple matter of distributing a unique text file for each customer.

Any assistance is greatly appreciated.

Thanks,
Dave Higgins
 
Execscript definialy runs out of the scope of the calling method and also out of the scope of the current object or thisform, so you need to pass in anything you want to use via parameters or as private or public variables.

Subclassing the buttons or forms would be easier in that aspect.

Of course I see an advantage with seperate files - it's easier to have one exe and only change some files holding individual code for a certain customer than to subclass for each customer and have all that code in an exe, which bloats with code for all customers.

But indeed it's advisible, if it's not really about the individual customer, but about specific features being licenseed or not.

Bye, Olaf.
 
What you could also do is put whole forms as seperate files for each customer. It's a matter of splitting the exe into several pjx, one for the general functionality and one for each customer with the customisations.

As a general idea: The secondary files could be APPs or even EXE you can use as a repository of classes and prgs you call.

You can call a prg compiled into an app file with:
Code:
Do someprg IN some.app WITH <<parameters>>

To create a class compiled into an app you can do:
Code:
o = newobject("classname","vcxname","some.app"),<<parameters>>)

The same goes with a seperate EXE, but as it's only a repository or kind of library and has no own functionality, it's suffiecient to compile as app.

If you seperate the modules of your application you can have a general EXE and one APP file for each customer. One advatage is, this APP contains already precompiled code.

Bye, Olaf.
 
We fixed it with this code. Using EXECSCRPT as advised above. This works pretty well by allowing easily updated text files to control parts of the program. We can customize the program for certain customers quickly and not worry about how it acts on others.

Create the Object oForm then instead of using ThisForm in the text file, we simply refer to it as oForm.FormMethod or oForm.FormProperty.



The click event code is:

PRIVATE oform
oform = thisform

IF FILE( [misc\] + lcFileName + [.txt] ) THEN

lcMyString = FILETOSTR( [misc\] + lcFileName + [.txt] )

*STRTOFILE(lcMyString , [misc\] + lcFileName + [.prg] )

EXECSCRIPT(lcMyString)


ELSE

MESSAGEBOX('warning ... the file called ' + '"lcFileName"' + 'is missing. Call 800-847-3111',48,'1on1')

ENDIF

RETURN

******* End of Procedure *************



NOW the code in the TEXT File is changed to this sample:


with oForm

.DlrSpecsLookup && 200810074: Don: this code does NOT work when placed in a method, but it DOES work when placed below. Temp fix is to assign Pub Vars.
.DlrSpecsRptVar

*check vars set by 'dlrlookup': lcDlrName, gcDlrName, etc
.lcdealership = "abc motors"
.lcdealership = UPPER(.lcdealership)
****************************************************************
endwith

return





 
Thank you All,

You guys are all amazing. It is working perfectly. Being able to read a text file into a form gives me the flexibility that I need. Especially when I can call the form's methods and properties from within the code in the text file.

A special thanks to Mike Lewis and my brother, Don. I could not have done it without your assistance.

Thanks,
Dave Higgins

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top