Jump to content
Sign in to follow this  
michaelslamet

Text File

Recommended Posts

michaelslamet

Hello, World :)

Back to 2010, when I first hear and learn about AutoIT, I created some scripts that I still developing until today.

I use text files a lot. At that time, I never heard about INI files (and the related functions like IniRead, IniReadSection, etc),

so I create my own function to read (and write) the text files using FileReadLine, FileOpen and sort of them.

Those functions works very well, but they are very fragile because it's very line-dependent, means $varA has to be at line 11,

$varB has to be at line 15, etc, so when I need to add some line into the text file, I need to change many part of the scripts.

This is problem because the scripts consist of 3000~4000 ++ lines and "connected" to each others.

I am thinking to add a section to those text files so I can use INI function to read them, this way I dont need to worry if I need to add

lines, although thinking this make my head spinning hard.

Any advices for me?

Thank you :)

Share this post


Link to post
Share on other sites
Xenobiologist

What kind of information to you store in that files? Maybe a database would be nice. Otherwise switching to ini should be easy.


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites
czardas

ini files are generally used to store program settings. What you probably need is some sort of database to access information I guess. Programs don't generally have 4000 settings. I see I'm a bit slow in answering. :mellow:

Share this post


Link to post
Share on other sites
water

I would leave the text files alone and write the new data to a separate Ini file using the Ini* functions.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
michaelslamet

What kind of information to you store in that files? Maybe a database would be nice. Otherwise switching to ini should be easy.

 

Mega,

Thanks for taking time to reply :)

Those text files store variable/field like size, price, color. Yes, a database would be nice but this is already wrong from the first time,

and changing all those scripts to database model is not a good idea for now :P

Share this post


Link to post
Share on other sites
michaelslamet

ini files are generally used to store program settings. What you probably need is some sort of database to access information I guess. Programs don't generally have 4000 settings. I see I'm a bit slow in answering. :mellow:

 

A mean the script has 4000++ lines, not the text file :)

Share this post


Link to post
Share on other sites
michaelslamet

I would leave the text files alone and write the new data to a saparate Ini file using the Ini* functions.

 

Aha! So you suggest I should keep two version, one the old version and one the new (INI) version, until the INI version tested and ready, I should use the old version, is that?

Share this post


Link to post
Share on other sites
water

Correct.

How much data in the Ini files are we talkign about?

There seems to be a limit of 32K. Be it the total size of the Ini file or the size of a section.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
michaelslamet

Correct.

How much data in the Ini files are we talkign about?

There seems to be a limit of 32K. Be it the total size of the Ini file or the size of a section.

 

Not much, each text file only consist of no more than 50 lines so it wont break the 32K limit :)

Share this post


Link to post
Share on other sites
water

Then moving to Ini files shouldn't be a problem.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
michaelslamet

Is there any trick to let the INI* function read the text file without add a section ([sectionName]) to the text file?

That way I dont need to add [sectionName] to the top of the text files and current function will work because there is no lines change in the text file

Share this post


Link to post
Share on other sites
czardas

There's no way to determine section, key or its value without using some sort of reference. You can easily prefix numbered keys to every line in the file using AutoIt (or my >editor ... 3 operations ==>  prefix '=' ... enumerate selection ... prefix 'key' - see demo gif). Results in ==>

key1=data1

key2=data2

key3=data3

You will have to change the code to access the information in your main script if you use ini functions.

Edited by czardas

Share this post


Link to post
Share on other sites
water

That's why I suggested to leave the text file alone and start with an additional Ini file.

Change your script(s) variable for variable.

Means: Modify all statements where you read/write $varA so they point to the new Ini file. $varB still points to the text file. If $varA works then modify $varB etc. etc.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×