Jump to content

Populate input boxes from ini file values


lyledg
 Share

Recommended Posts

I am trying to populate various input boxes from values in an ini file.

I am using inireadsection and am able to read the file, but not sure how to populate the respective input boxes with the values read from the inifile. Do I use an _FileReadToArray UDF in this action?

Also, if I wanted to get rid of ALL "" within the ini file, how would that be done?

Attached is the a sample of the inifile I am using.

Also, had some trouble uploading the file as a *.ini file, so just renamed to *.txt

Thanx very much :lmao::P

Edited by lyledg
Link to comment
Share on other sites

  • Moderators

I answered a similar question a few days ago for populating a combobox for a gui with the same scenerio, I'll see if I can find the post.

This might give you some ideas: http://www.autoitscript.com/forum/index.php?showtopic=19446

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

In this case you may be better off using plain INIRead():

GUICtrlSetData($SrcField, Read('SourceDir'))
GUICtrlSetData($DestField, Read('DestDir'))
GUICtrlSetData($Files, Read('Files'))
GUICtrlSetData($LogField, Read('LogOverwrite'))

Func Read($Key)
    Local $Data = INIRead('INI', 'Settings', $Key, '""')
  ; Trim a character off each end if the string begins with a double quote
    If StringLeft($Data, 1) = '"' Then $Data = StringTrimLeft(StringTrimRight($Data), 1)
    Return $Data
EndFunc

P.S. Is the LogOverwrite line of the supplied INI file correct? The double quotes don't match up.

Edit: Typo.

Edited by LxP
Link to comment
Share on other sites

Smoke

Sorry for being a pest mate, but I only kinda have an idea on how to do this...Would you be able to to show me how to do this with input boxes and using my example, please? To be honest, i am still learning the ropes with regards to Arrays, Ubound etc..

Cheers mate...

Link to comment
Share on other sites

  • Moderators

In this case you may be better off using plain INIRead():

GUICtrlSetData($SrcField, Read('SourceDir'))
GUICtrlSetData($DestField, Read('DestDir'))
GUICtrlSetData($Files, Read('Files'))
GUICtrlSetData($LogField, Read('LogOverwrite'))

Func Read($Key)
    Local $Data = INIRead('INI', 'Settings', $Key, '""')
 ; Trim a character off each end if the string begins with a double quote
    If StringLeft($Data, 1) = '"' Then $Data = StringTrimLeft(StringTrimRight($Data), 1)
    Return $Data
EndFunc

P.S. Is the LogOverwrite line of the supplied INI file correct? The double quotes don't match up.

Edit: Typo.

Hmmm, there were 2 examples there on the post I sent them too, one using IniReadSection(), and one using _FileReadToArray(), and now they have one for IniRead() :lmao:... That should cover all bases, along with cameronsdads quote strip :P

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

Would be more of a pain with input boxes lyledg for me, does it have to be input boxes, and if so why? If it's inexperience with a GUI maybe we can help some.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Hmmm, there were 2 examples there on the post I sent them too, one using IniReadSection(), and one using _FileReadToArray(), and now they have one for IniRead() :lmao:... That should cover all bases, along with cameronsdads quote strip :P

actually i pulled mine when i saw that there were other more complete solutions... i didn't want to be the one with the half ass response...
Link to comment
Share on other sites

Thanks Cameronsdad, that works a treat..

Hmm...ok, guess I'll have to go and hit the books to understand this all a bit better..

glad i could help, even though i thought i pulled it before anyone saw it. :P as far as using ini to populate input boxes, do you mean boxes that you're creating, or in a pre-existing window? i can whip you up a little example depending on where the boxes are...
Link to comment
Share on other sites

Sorry Lyle; I should have read the initial post better. You aren't using a GUI. Here's another try:

Local $SrcDir = InputBox('', 'Enter source directory:', Read('SourceDir'))
Local $DestDir = InputBox('', 'Enter destination directory:', Read('DestDir'))
Local $Files = InputBox('', 'Enter file specification:', Read('Files'))
Local $LogOverwrite = InputBox('', 'Enter log overwrite string:', Read('LogOverwrite'))

Func Read($Key)
    Local $Data = INIRead('INI', 'Settings', $Key, '""')
 ; Trim a character off each end if the string begins with a double quote
    If StringLeft($Data, 1) = '"' Then $Data = StringTrimLeft(StringTrimRight($Data), 1)
    Return $Data
EndFunc
Link to comment
Share on other sites

Actually, I am using a GUI...Sorry guys for not posting this initially...

I have a pre-exiting GUI, that has multiple Input boxes which gets input such as Source directory, backup directory etc...It is backup GUI.

What I am trying to achieve is that if a user decides not to run the backup job and wants to save their current settings, I thought of saving these into an ini file so that it can later be read, and obvioulsy re-populate the input boxes that were initially used to grab the data from..

The reason for stripping off the quotes was so that when the input boxes get re-populated, these would not be there

Link to comment
Share on other sites

If you're using INIWrite() at some stage to save those values to file, you should find that surrounding double quotes aren't added. This probably means that you don't need to worry about stripping them when restoring the values.

Link to comment
Share on other sites

  • Moderators
:P - man, I must be tired... I'm totally not following this thread. If your not getting the desired affect off of the examples posted, then I would suggest posting all that you currently have for more helpful (hopefully) advice.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Thanks, but because I am using GUICTRLREAD($Value_of_an_Inputbox), the double quotes are needed as the path usually contains spaces..

You should find that the GUICtrlRead() and INI...() functions work as expected even if the path contains spaces and double quotes aren't used. The only time that you will need to worry about double quotes is if you're passing the path as a parameter to something else via Run/Wait().
Link to comment
Share on other sites

  • Moderators

Hey Lxp

Thanks, but because I am using GUICTRLREAD($Value_of_an_Inputbox), the double quotes are needed as the path usually contains spaces..

I would think that calling it without quotes into a variable would be less cause for harm than calling it with quotes, unless your stripping whitespaces.

I misinterpret about 90% of what I read, so I may be doing the same here?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

lmao! No doubt! I'm about to head out to OutBack and see the movie Narnia with the kids and wife. So, I'll get the 'Fat Bastard Steak' , 'Fat Bastard Onion', 'Fat Bastard Beer', and the 'Fat Bastard Pop-Corn'!! :P

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...