Normal Topic creating a txt file from a record (Read 885 times)
billgordon
Junior Member
**
Offline


No personal text

Posts: 61
Joined: Dec 31st, 2003
creating a txt file from a record
Jul 4th, 2005 at 5:42am
Print Post Print Post  
Can someone please suggest the easiest method for me to create a text file containing a few elements on a form.

I want to be able to press a command button and get a text file with city, state and zip elements from that record.

Thanks
  
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: creating a txt file from a record
Reply #1 - Jul 4th, 2005 at 12:14pm
Print Post Print Post  
The File I/O functions do this quite nicely. Look in the 1.1 Programming Guide starting on page 125. There are a number of File I/O functions. The example for FileWriteLn should get you started.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: creating a txt file from a record
Reply #2 - Jul 4th, 2005 at 3:01pm
Print Post Print Post  
Ascii export spec?
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
billgordon
Junior Member
**
Offline


No personal text

Posts: 61
Joined: Dec 31st, 2003
Re: creating a txt file from a record
Reply #3 - Jul 4th, 2005 at 11:12pm
Print Post Print Post  
I know Sesame is simple and user friendly but I am apparently stupid, I can not do a simple thing like get 4 elements to create a file when I press a command button. Below is my botched attempt. I know my statement Vcrlf =   ""," is a problem because it is being misinterpreted. If I make that * "it works with the character, so I guess I need to find the literal character key. The filedelete() is also wrong but I did not want to keep appending the file I just wanted to replace the data each time so I stuck that in trying to delete it prior to writing.

Please steer me in another direction.



var VfileHandle as Int
var Vcrlf as string

Vcrlf =   "","  // makes it look like an comma del file
VfileHandle = Fileopen("c:\Sesame\mydat.txt")
filedelete(vfilehandle) //deletes previous try
if vfileHandle >= 0
{
     //fileseek(vfilehandle, filesize(vfilehandle))
     
     Filewrite(vfilehandle, Street)
     filewrite(vfilehandle, vcrlf)
     Filewrite(vfilehandle, city)
     filewrite(vfilehandle, vcrlf)
       Filewrite(vfilehandle, State)
     filewrite(vfilehandle, vcrlf)
     Filewrite(vfilehandle, zip)
     //filewrite(vfilehandle, vcrlf)
     fileclose(vfilehandle)
}
Else
{
     Writeln("open failed: " + @str(vfilehandle))
}
  
Back to top
 
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2482
Joined: Aug 20th, 2003
Re: creating a txt file from a record
Reply #4 - Jul 5th, 2005 at 2:38pm
Print Post Print Post  
Hello,

The piece of code below will produce the results that you are looking for.

Code
Select All
Var vHandle as Int
Var vData as String

If FileExists("C:\Sesame\Data\MyData.txt") Then
{
	FileDelete("C:\Sesame\Data\MyData.txt")
}

vHandle = FileOpen("C:\Sesame\Data\MyData.txt")

If vHandle >= 0
{
	vData = @Chr(34) + Add1 + @Chr(34) + ","
	vData += @Chr(34) + Add2 + @Chr(34) + ","
	vData += @Chr(34) + City + @Chr(34) + ","
	vData += @Chr(34) + State + @Chr(34) + ","
	vData += @Chr(34) + Zip + @Chr(34)
	FileSeek(vHandle, 0)
	FileWriteln(vHandle, vData)
	FileClose(vHandle)
}
 



If the file already exists then the code deletes it, this way we always start with a fresh file. Then the new file is opened for writing. The Data is assembled next. The Data gets written to the file and the file is closed. The output for this is below.

Code
Select All
"6066 Spruce Street","Apt 2- K","PHILA","PA","05040" 



-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
billgordon
Junior Member
**
Offline


No personal text

Posts: 61
Joined: Dec 31st, 2003
Re: creating a txt file from a record
Reply #5 - Jul 5th, 2005 at 3:18pm
Print Post Print Post  
Thank You. I was so close to throwing in the towel.
  
Back to top
 
IP Logged
 
BOBSCOTT
Senior Member
Members
*****
Offline


That Darn Computer #$X#
{curse words}

Posts: 1195
Joined: Nov 22nd, 2002
Re: creating a txt file from a record
Reply #6 - Jul 5th, 2005 at 4:27pm
Print Post Print Post  
Ray,

Your  snippet is a great little tool that should probably be posted in the examples section.

Thanks
  

Team – Together Everyone Achieves More
Back to top
 
IP Logged