Page 1 of 1

Write config File

Posted: Fri Jul 20, 2018 11:37 am
by ace16vitamine
Hi,

i am writing informations into a configuration file line by line with

Code: Select all

   put tpath & "/test.txt" into theFile
   put  field "Field_DB_Server" into collected_data
   put  CR & the field "Field_DB_user" after collected_data
Later, I am reading the informations out of the file:

Code: Select all

put tpath & "/test.txt" into theFile1
put url("file:" & thefile1) into saved_data
put line 1 of saved_data into l1
put line 2 of saved_data into l2
But in the case that in my file is a CR (for example) I have a problem because I am reading the exact number of the line ;-)

Any other ideas how to make this easier? My Idea is to work with items in the config file:

host: "127.0.0.1"
Username: "Max Mustermann"

Another Idea is if it is possible to change only one item (e.g. only Username) without writing the complete file.

Stefan

Re: Write config File

Posted: Fri Jul 20, 2018 12:11 pm
by mrcoollion
You could use an array to keep you data in and save into file (binfile)
Fill you array with data (YourArrayName) and have a path with filename in tPathAndFileName then save like this:

Code: Select all

   put "binfile:"&tPathAndFileName into tBinPathFile
   put arrayEncode(YourArrayName) into URL tBinPathFile
Load back into array like this

Code: Select all

  put "binfile:"&tPathAndFileName into tBinPathFile
   put URL tBinPathFile into tEncodedArray
   put arrayDecode(tEncodedArray) into YourArrayName
Good luck,

Paul

Re: Write config File

Posted: Fri Jul 20, 2018 12:22 pm
by Klaus
Hi Steran,

or just don't use LINES but items with an itemdelimiter which is unlikely part of the text
in your fields like the pipe | or whatever, you get the picture! :-)


Best

Klaus

Re: Write config File

Posted: Fri Jul 20, 2018 2:40 pm
by ace16vitamine
Thank you Paul & Klaus,

I think the solution with the bin file is better for me and works fine, I already tested it on my play ground. The itemdelimiter is also a good Idea (I had this in my brains also before).

Stefan