I have an .ini file with the following
[Gary Miller]
Subject = Gary Miller
Text_Body = Your Message.
I have tried to read this file with the following IniRead line.
IniRead, Value, %INIFile%, %Subject%, %Field1%,
IniRead, Val, %INIFile%, %Body%, %Field2%,
I get the results of %Value% %Val% in a MsgBox as Gary Miller Gary Miller
What am doing wrong?
Gary Miller and Your Message.
help with IniRead
Re: help with IniRead
Have you assigned values to variables named INIFile, Subject, Field1, Body, adn Field2? Can you post that part of your script?
Re: help with IniRead
Where are you defining the values of %INIFILE%, %Subject%, %Body%, %Field1%, and %Field2% ?
Does this result in the correct MsgBox?
?
My guess is that the variables other than INIFILE may be undefined. If those variables are undefined, then you're essentially doing IniRead, Value, %INIFILE% and so it will retrieve a list of all of the Section Names (the ones in [ ]). Since there's only one section in there, it gets the value Gary Miller.
Thus, you can get your code to work (though untested) like this:
But you can see that's terribly confusing to name your variables like that and use multiple variables for the same value. But I hope it sheds some light on the issue for you to play around with it.
Does this result in the correct MsgBox?
Code: Select all
IniRead, Value, %INIFile%, Gary Miller, Subject
IniRead, Val, %INIFile%, Gary Miller, Text_Body
MsgBox %Value% %Val%
My guess is that the variables other than INIFILE may be undefined. If those variables are undefined, then you're essentially doing IniRead, Value, %INIFILE% and so it will retrieve a list of all of the Section Names (the ones in [ ]). Since there's only one section in there, it gets the value Gary Miller.
Thus, you can get your code to work (though untested) like this:
Code: Select all
INIFile:=YourFile.ini
Subject:="Gary Miller"
Field1:="Subject"
Body:="Gary Miller"
Field2:="Text_Body"
IniRead, Value, %INIFile%, %Subject%, %Field1%
IniRead, Val, %INIFile%, %Body%, %Field2%
MsgBox %Value% %Val%
Re: help with IniRead
Here is my script.
I input the Subject and Text Body in the Edit boxes and the Write button produces:
[Gary Miller]
Subject = Gary Miller
Text_Body = Message here
I input the Subject and Text Body in the Edit boxes and the Write button produces:
[Gary Miller]
Subject = Gary Miller
Text_Body = Message here
Code: Select all
#SingleInstance, Force
/*
Sections =
(
A = Subject
B = Body
)
Keys =
(
%field1%
%field2%
)
*/
INIFile := "myProj.ini"
Gui, Add, Text, x10 w90 h20 , Subject ;the subject line of your text. 1st line shown in text message
Gui, Add, Text, x+10 wp30 hp , Text body ;your message
Gui, Add, Edit, x10 y+10 wp hp vField1 , Subject
Gui, Add, Edit, x+10 y36 w180 hp vField2 , Text body
Gui, Add, Button,x10 y+5 w70 h20 gWrite , Write
Gui, Add, Button,x10 y+10 w70 h20 gRead , Read
Gui, Show,, `t ; no title
Return
Write:
GUI, Submit, NoHide
INIWrite,% "`tSubject`t`t= " Field1 "`n"
. "`tText_Body`t= " Field2 "`n"
,% INIFile,% Field1 ; using 'cosmetical' tabs for better readabilty, feel free to remove'm all :)
;MsgBox, %Field1% %Field2%
return
Read:
;IniRead, OutputVar, Filename, Section, Key [, Default]
IniRead, Value, %INIFile%, %Subject%, %Field1%,
IniRead, Val, %INIFile%, %Body%, %Field2%,
IniRead, OutputVar, INIFile, Gary, Field1
MsgBox, The value is %Value% %Val%.
Return
Re: help with IniRead
Yeah, you never defined a variable "Subject" nor "Body". I suppose when the Section parameter is blank, it ignores the Key parameter and just treats this as a "OutputSectionNames" syntax for IniRead.
And your IniRead is just not matching the syntax anyway. I think you are confused on this because you are using variables as strings and putting them in the wrong places. Let's break down your IniWrite:
The syntax for IniRead is IniRead, OutputVar, Filename, Section, Key.
This means, if we were to read the first Value in the .ini, we need to specify: IniRead, Value, %INIFile%, %Field1%, Subject. Notice this is not %Subject%, but the literal string Subject.
And your IniRead is just not matching the syntax anyway. I think you are confused on this because you are using variables as strings and putting them in the wrong places. Let's break down your IniWrite:
You have written Keys Subject and Text_Body. You have written Values %Field1% and %Field2% (the contents of those variables come from the GUI). You have written Ini File myProj.ini. You have written Section %Field1% (the contents of this variable comes from the GUI -- instructed to be "Subject").INIWrite,% "`tSubject`t`t= " Field1 "`n"
. "`tText_Body`t= " Field2 "`n"
,% INIFile,% Field1 ; using 'cosmetical' tabs for better readabilty, feel free to remove'm all
The syntax for IniRead is IniRead, OutputVar, Filename, Section, Key.
This means, if we were to read the first Value in the .ini, we need to specify: IniRead, Value, %INIFile%, %Field1%, Subject. Notice this is not %Subject%, but the literal string Subject.
Re: help with IniRead
that works for the 1st value of Field1
I then added
IniRead, Val, %INIFile%, %Field2%, Text_Body to get the Field2 value and get ERROR
I then added
IniRead, Val, %INIFile%, %Field2%, Text_Body to get the Field2 value and get ERROR
Re: help with IniRead
That's not correct. You have "Text_Body" in there twice because Field2 contains "Text_Body". Replace %Field2% with %Subject%.G_Allen wrote:that works for the 1st value of Field1
I then added
IniRead, Val, %INIFile%, %Field2%, Text_Body to get the Field2 value and get ERROR
Re: help with IniRead
iN MY INIWrite,% "`tSubject`t`t= " Field1 "`n"
. "`tText_Body`t= " Field2 "`n"
,% INIFile,% Field1 ; using 'cosmetical' tabs for better readabilty, feel free to remove'm all
I get in the .ini file
[Gary Miller]
Subject = Gary Miller ;input from Field variable
Text_Body = Message 2 ;input from Field2 variable
IniRead, Value, %INIFile%, %Field1%, Subject gets me
Gary Miller Message 2
I am not able to get anthing but ERROR for the value of what was put into Field2.
I have tried
IniRead, Val, %INIFile%, %Subject%, Text_Body
IniRead, Val, %INIFile%, %Field2%, TextBody
What I need to get is: Gary Miller Message 2 which is the input to variables Field1 and Field2.
. "`tText_Body`t= " Field2 "`n"
,% INIFile,% Field1 ; using 'cosmetical' tabs for better readabilty, feel free to remove'm all
I get in the .ini file
[Gary Miller]
Subject = Gary Miller ;input from Field variable
Text_Body = Message 2 ;input from Field2 variable
IniRead, Value, %INIFile%, %Field1%, Subject gets me
Gary Miller Message 2
I am not able to get anthing but ERROR for the value of what was put into Field2.
I have tried
IniRead, Val, %INIFile%, %Subject%, Text_Body
IniRead, Val, %INIFile%, %Field2%, TextBody
What I need to get is: Gary Miller Message 2 which is the input to variables Field1 and Field2.
Re: help with IniRead
Does your script assign "Garry Miller" to the variable called Subject? Does the variable Field2 contain "Text_Body"?
Then IniRead, Val, %INIFile%, %Subject%, %Field2% should work.
Then IniRead, Val, %INIFile%, %Subject%, %Field2% should work.
Re: help with IniRead
Actually, I believe the second one should be IniRead, Val, %INIFILE%, %Field1%, Text_Body.
This is what I'm talking about with confusing variables. That third parameter represents what is in the [ ] in the Ini. In this case, the answer is Gary Miller -- which %Field1% holds it's value. When you used IniWrite, you used %Field1% for the name of the Section.
You have never created any %Subject% or %Body% or %Text_Body% variables.
Edit for a bit more clarity. Follow the colors from my previous reply.
There is a lot of confusion because you use %Field1% and %Field1% (again, in forced-expression mode) inside the IniWrite command. You are using the same variable in two different spots.
Also, emphasis was added to my original reply regarding the key Subject not being a variable.
This is what I'm talking about with confusing variables. That third parameter represents what is in the [ ] in the Ini. In this case, the answer is Gary Miller -- which %Field1% holds it's value. When you used IniWrite, you used %Field1% for the name of the Section.
You have never created any %Subject% or %Body% or %Text_Body% variables.
Edit for a bit more clarity. Follow the colors from my previous reply.
That third parameter in IniRead is colored Orange. In the IniWrite, you have only a single Orange parameter, the last one, which was told to use the variable %Field1% (just using forced-expression mode). There is no other variable that would match up and be consistent. So in this isolated case, your %Field1% is "static" -- You use %Field1% to retrieve both values for the keys Subject and Text_Body.Exaskryz wrote:IniRead, Value, %INIFile%, %Field1%, Subject. Notice this is not %Subject%, but the literal string Subject.INIWrite,% "`tSubject`t`t= " Field1 "`n"
. "`tText_Body`t= " Field2 "`n"
,% INIFile,% Field1 ; using 'cosmetical' tabs for better readabilty, feel free to remove'm all
There is a lot of confusion because you use %Field1% and %Field1% (again, in forced-expression mode) inside the IniWrite command. You are using the same variable in two different spots.
Also, emphasis was added to my original reply regarding the key Subject not being a variable.
Last edited by Exaskryz on 21 Sep 2017, 18:10, edited 3 times in total.
Re: help with IniRead
Yeah, I thougt I saw in one of the above scripts where it was assigned to Subject and another one where it's to one of the Field variables. You're right that well-named variables make all the difference.
Re: help with IniRead
So, in my IniWrite in the line
,% INIFile,% Field1 ; using 'cosmetical' tabs for better readabilty, feel free to remove'm all
I should be using something other than Field1 such as TxtMsg. Is that where I am going wrong?
,% INIFile,% Field1 ; using 'cosmetical' tabs for better readabilty, feel free to remove'm all
I should be using something other than Field1 such as TxtMsg. Is that where I am going wrong?
Re: help with IniRead
I would recommend that, yes. Whether you use ,% INIFile, TxtMsg or put in a field in your Gui Gui, Add, Edit, x+10 y36 w180 hp vTxtMsg , Section Name (with the position coordinates changed), and use ,% INIFile, % TxtMsg is up to you on that preference.
Re: help with IniRead
Thanks, everyone. I appreciate the help.
Re: help with IniRead
Thanks for the help. much appreciated!
Who is online
Users browsing this forum: Google [Bot] and 306 guests