Friday, August 03, 2012 7:48 PM
I need to create a FoxPro table from a text file (test.dat).
I've never used FoxPro before, I will be calling if from VB.net to create the table and passing the FP command (which is why I can't do it with the wizard). The table needs to have 5 columns (cat_id, address1, address2, city, state, zip). The text file I'm pulling from doesn't have delimiters, I just need to pull from specific locations for specific lengths. Please see below the layout of the file to be input for the table:
***Field Name (Start position, Length of field)
cat_id (1, 6)
address1 (7, 35)
address2 (42, )12
city (54, 25)
zip (81, 5)
Any help is greatly appreciated! I've been trying to figure this out (on and off) for weeks now and it seems all the info I find either wants me to use the wizard to create the table or doesn't specify how I can create the table with a command and specify where I want the data pulled from for each field.
Friday, August 03, 2012 10:53 PMModerator
BROWSE will display the imported data.
You need just two lines of code:
CREATE TABLE MyData (cat_id C(6), address1 C(35$), gap1 C(6), address2 C(12), ;
city C(25), gap2 C(2), zip C(5))
APPEND FROM test.dat TYPE SDF BROWSE
Saturday, August 04, 2012 12:27 AM
Thanks so much! That was making me crazy and I had a feeling it was something simple :)
I have a couple questions if you don't mind (I just want to make sure I understand)... what is the '$' do for the address1 field?
And also, what is the ';' at the end of the line for.. I'm assuming it's just to continue to the next line but want to be sure.
...I'm getting a 'missing operand' error when trying to run the CREATE TABLE command... do you know why that would happen?
I looked up the error and it say "An operator that requires two operands was used without the second operand, such as ? (13+4)/." Not sure how that even applies here..
THANKS AGAIN!! I really appreciate it!
- Edited by Joanie Brows Saturday, August 04, 2012 12:40 AM added some text
Saturday, August 04, 2012 12:48 AM
Nevermind.. I got it to work.
I removed the '$' just to see what would happen (also because I wasn't sure what it did) and it was like magic, everything just fell into place.
THANK YOU :)
Saturday, August 04, 2012 5:31 PMModerator
Oops... $ sign is really a typo. (I've been writing the post around 1:00 AM local time so my eyes were not so fresh... :-)
The missing operand error message was generated because column sizes can be defined as expressions in VFP but $ operator needs two operands... (VFP tests the operands presence during the compilation phase.)