Jump to content
Sign in to follow this  
Decker87

Reading data live from a file

Recommended Posts

Decker87

I have been using files to store settings for quite some time now. For example, having the compiled "My Program.exe" read from the file "My Settings.ini". In these files I would often have some format like:

Setting1: 20

Setting2: 45

Et cetera. I would then have some function to sequentially read each line, then interpret the text. This method works but it is horrendous for editing the data with autoIT. That is, writing a program to specify these values in a user-friendly way has for me up to this point also been sequential.

I am tired of sequentially accessing external data. Has anyone out there made a set of functions to handle external data in a dynamic way? I don't really need a database, I just want to read/write 50 or so lines from a text file.

Share this post


Link to post
Share on other sites
Valuater

An ini file has 'sections' and 'keys' then 'info'

This does not need to be read or accessed sequentially. Just read the info of the key in the section to get the data you want.

[General] ; Section name

1=Light ; key = information

2=dark

3=etc

[settings]

Auto=On

Open=Off

Restart=Off

etc, etc... HTH

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites
Decker87

Well, I feel like I just climbed a wall of dicks. I didn't even realize AutoIT had a set of functions for handling INIs! I've been doing it wrong for weeks!

On another note, I do have one question that might actually be legitimate. Is there a way to store more dynamic information in an INI file? That is, say I want the INI to hold a list of strings: string1, string2, string3 etc. Is there such a way for an INI file to contain an arbitrary number of "keys"?

Edited by Decker87

Share this post


Link to post
Share on other sites
Valuater

Yes!!!

; File.ini
[Section name]
Key name=this way,that way,which way? 

$read = IniRead("File.ini", "Section name", "Key name", "error")
$KeySplit = StringSplit($read, ",")

For $x = 1 To $KeySplit[0]
    MsgBox(0x0, $x, $KeySplit[$x], 2)
Next

... Hope you didn't have to "Hug that wall too Hard"... lol

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites
JeremyE

OK, this sounds closest to what I'm wanting to do, so I'm hoping I can get some help... I'm trying to write a script to change servers for a WoW installation, right now I have to hard-code all the servers, I'd really like to make it so that the server info is all in an external file. If nothing else, it will save me recompiling every time I add in a new server. I'm including the code for the script as I have it now.

#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>

Global $RealmList, $ServerList

$filepath = RegRead ( "HKLM\SOFTWARE\Blizzard Entertainment\World of Warcraft" , "InstallPath" )

$filename = $filepath & "\realmlist.wtf"

$file = FileOpen ( $filename , 2 )

GUICreate ( "Server selection", 210, 80 )

Global $g_idCombo = GUICtrlCreateCombo ( "", 10, 10, 190, 10 )
GUICtrlSetData ( -1,"Blizz|Hell360|Project Requiem", "Project Requiem" )

$Button_1 = GUICtrlCreateButton ( "Select",  80, 40, 50 )

GUISetState ()

Do

    $msg = GUIGetMsg ()
    $Server = GUICtrlRead ( $g_idCombo )

Until $msg = $Button_1

If $Server = "Blizz" Then
    
    FileWrite ( $file, "set realmlist us.logon.worldofwarcraft.com" & @CRLF )
    FileWrite ( $file, "set patchlist us.version.worldofwarcraft.com" & @CRLF )

ElseIf $Server = "Hell360" Then
    
    FileWrite ( $file, "set realmlist logon.hell360.net" & @CRLF )

ElseIf $Server = "Project Requiem" Then
    
    FileWrite ( $file, "set realmlist 74.196.184.170" & @CRLF )

EndIf

FileClose ( $file )

If anyone can help me with this, I'd be greatly appreciative. Thanks!

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.