Sign in to follow this  
Followers 0
lyledg

Populate input boxes from ini file values

22 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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

[center]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.[/center]

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Wow, that was quick! Thanks Guys

Yes, that is a mistake on the quotes question...I must have left there during my testing..

Will give your code a go LXP and Smoke

:P

Edited by lyledg

Share this post


Link to post
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...

Share this post


Link to post
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.

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

[center]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.[/center]

Share this post


Link to post
Share on other sites

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.


[center]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.[/center]

Share this post


Link to post
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...

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
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..

Share this post


Link to post
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...

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Hey Lxp

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

Edited by lyledg

Share this post


Link to post
Share on other sites
: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.

[center]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.[/center]

Share this post


Link to post
Share on other sites

Ok, cool...I will PM the code to you mate...

Share this post


Link to post
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().

Share this post


Link to post
Share on other sites

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?


[center]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.[/center]

Share this post


Link to post
Share on other sites

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

still delirious from your 'fat bastard special'?

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

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


[center]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.[/center]

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  
Followers 0