INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Creating a table within a function

Creating a table within a function

(OP)
I have a program that read an imported .csv file and determines the position and length of the string for building a dynamic table. This part works fine. The problem I am having is the command string for building the table is put in function using the strtofile() function for building a .prg file. When I run it using the DO command from the command screen it works fine. But when I build an .EXE and run the program the Do command won't update the table with the new structure. I am not sure if you can build an function on the fly and run it after its creation and get the correct results. Maybe there is a better approach?

Thanks
Rich

RE: Creating a table within a function

You don't need to create a file for this. You can use &lcYourString

RE: Creating a table within a function

Not sure what you're saying about the aspect of making up a table from a csv file, but taken that for granted, of course you can also run a newly generated script from within an EXE, instead of saving as PRG use it as the code script parameter of EXECSCRIPT. It does nothing else as you do, though, it creates a prg and runs it. But it does that for you, and it cleans up after executing, so the prg/fxp files generated are in temp. You can also save a prg and do it, but EXECSCRIPT is made for that. Besides the script you can pass in parameters, which will need a LPARAMETERS withint the script, and when your script ends in RETURN that is it's return value. So you can see this as inline function, kind of. I wonder if it's really necessary in your case, but to show how this aspect works, too:

CODE

nSum = Execscript("Lparameters tnOP1, tnOP2"+chr(13)+"Return tnOP1+tnOP2",1,2) 

Which compares to having a PRG Addition.prg:

CODE

Lparameters tnOP1, tnOP2
Return tnOP1+tnOP2 
and call that via:

CODE

nSum=Addition(1,2) 
Now since you can also build up the script in a string variable or store the script in a memo field, you can have your dynamically created prg, but for executing a single CREATE TABLE or CREATE CURSOR you would neither need LPARAMETERS nor RETURN, you only execute one line of code and that can also be done with macro substitution, eg

CODE

lcSQL="CREATE CURSOR crsTest (iid I, cText C(20))"
&lcSQL 


or since the first part of it is constant and only the field composition changes, you can do:

CODE

lcFields="iid I, cText C(20)" && put together from analyzing a CSV file
CREATE CURSOR crsTest (&lcFields) 


Bye, Olaf.

RE: Creating a table within a function

(OP)
I tried to use the macro approach and it comes up with an error.The string is fairly long and is formatted to build a table. That would be a simple approach if it worked. Are there any limitations on using macros?


Thanks for your help

Rich

RE: Creating a table within a function

(OP)
Olaf
Thanks for your reply I will give those options a try and see how they work.

I am a first time user on the forum and appreciate all the help

Rich

RE: Creating a table within a function

After re-reading your initial message, I think the problem is different from what you think. If you can't change the structure of the table, could it be that you have included the table in the exe itself? If so, it's read only. The same is true if the table is in the same folder as the exe, and they are both in "c:\program files". The "program files" folder is protected by Windows to protect your computer from virus attacks.

RE: Creating a table within a function

Quote (techrich9)

I tried to use the macro approach and it comes up with an error
Which error?

Tore already has ideas about reasonings, there is a length limit of commands, too, yes, but whatever the problem is, the error message will tell you what's wrong and even if you can't understand it, we can. In lieu of what Tore thinks and I think there are at least 3 different categories of errors, each of which has some possible messages which could happen, but unfortunately we can't know without you telling it. Range of reasons varies from insufficient permissions to readonly nature of the EXE, too long command, too many fields, wrong field types/lengths, .... It's impossible to say what's wrong without knowing your macro string and error message.

Edit: Here's a very important overview of system capacities (and limits) of VFP:
https://msdn.microsoft.com/en-us/library/aa975385(...

Of which at least two address the CREATE makro:

1. Maximum # of fields per record: 255 (254 when at least one field is nullable)
2. Maximum # of characters per macro substituted line: 8192

And then you find more limits, eg Maximum # of characters per table field: 254

Bye, Olaf.

RE: Creating a table within a function

(OP)
Thanks everyone for your idea's I found the Execscript() fixed the problem. I guess when you create a .prg file at run time it won't run correctly. Reading more about Execscript() in the help file said it will process a script file during runtime. First time using the forum and it really paid off. Thanks Again

Rich

RE: Creating a table within a function

You only need Execscript, if you want to run more than one command, and CREATE CURSOR or CREATE TABLE is just one command, so when you have your code for Execscript and it is a one liner, you can also run it using macro substitution (&). Have you created the command with multi lines and semicolons for line continuation? That's one of the things not working.

Bye, Olaf.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close