Write config File

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
ace16vitamine
Posts: 130
Joined: Fri Apr 13, 2018 1:53 pm

Write config File

Post by ace16vitamine » Fri Jul 20, 2018 11:37 am

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

mrcoollion
Posts: 719
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Write config File

Post by mrcoollion » Fri Jul 20, 2018 12:11 pm

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

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Write config File

Post by Klaus » Fri Jul 20, 2018 12:22 pm

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

ace16vitamine
Posts: 130
Joined: Fri Apr 13, 2018 1:53 pm

Re: Write config File

Post by ace16vitamine » Fri Jul 20, 2018 2:40 pm

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

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”