iniread issue Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Epialis
Posts: 858
Joined: 02 Aug 2020, 22:44

iniread issue

03 May 2022, 01:18

For the life of me I can't figure out why this throws the ERROR...

Code: Select all

	IniRead, OutputVar, Images.txt, Epiales, key
if (OutputVar = "") {
	FileSelectFile, SelectedFile, 3, , Open a file, Images (*.jpg; *.png; *.jpeg)
	Gui, Add, Picture,x15 y40 w470 h450, %SelectedFile%
	IniWrite, %SelectedFile%, Images.txt, Epiales, key
}
else
	IniRead, OutputVar, Images.txt, Epiales, key
	Gui, Add, Picture,x15 y40 w470 h450, %OutputVar%
Return
Any Idead? Thank you :headwall:

Text file just has the Section - Epiales and the key is the url to the image.
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: iniread issue

03 May 2022, 01:45

I'd guess that the issue isn't IniRead but displaying a remote/linked file ("URL") vs a local file?
Check out AHK's help about Gui, Add, Picture,... that is showing this...
Alternatively, the ActiveX control type can be used. For example:

; Specify below the path to the GIF file to animate (local files are allowed too):
pic := "http://www.animatedgif.net/cartoons/A_5odie_e0.gif"
Gui, Add, ActiveX, w100 h150, % "mshtml:<img src='" pic "' />"
Gui, Show
PS. just out of curiosity, why are your IniFiles saved as *.txt (regardless that it works reading them)? :think:
AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: iniread issue

03 May 2022, 01:47

does your file look like this

Code: Select all

[Epiales]
Key=https://www.autohotkey.com/
is so try simple first from the help file

Code: Select all

IniRead, OutputVar, Images.txt, Epiales, key
MsgBox, The value is %OutputVar%.
if it doesn't work, try

Code: Select all

fileread, x, Images.txt
msgbox, % x


does all the data show up from the file?

if everything works, the issue must be something else in your script
User avatar
Epialis
Posts: 858
Joined: 02 Aug 2020, 22:44

Re: iniread issue

03 May 2022, 03:26

AHKStudent wrote:
03 May 2022, 01:47
does your file look like this

Code: Select all

[Epiales]
Key=https://www.autohotkey.com/
is so try simple first from the help file

Code: Select all

IniRead, OutputVar, Images.txt, Epiales, key
MsgBox, The value is %OutputVar%.
if it doesn't work, try

Code: Select all

fileread, x, Images.txt
msgbox, % x


does all the data show up from the file?

if everything works, the issue must be something else in your script

Code: Select all

[Epiales]
key=c:/pathtofile
And I did try running the msgbox before and it read the path to the local image file correctly.
Last edited by Epialis on 03 May 2022, 03:30, edited 1 time in total.
User avatar
Epialis
Posts: 858
Joined: 02 Aug 2020, 22:44

Re: iniread issue

03 May 2022, 03:27

BoBo wrote:
03 May 2022, 01:45
I'd guess that the issue isn't IniRead but displaying a remote/linked file ("URL") vs a local file?
Check out AHK's help about Gui, Add, Picture,... that is showing this...
Alternatively, the ActiveX control type can be used. For example:

; Specify below the path to the GIF file to animate (local files are allowed too):
pic := "http://www.animatedgif.net/cartoons/A_5odie_e0.gif"
Gui, Add, ActiveX, w100 h150, % "mshtml:<img src='" pic "' />"
Gui, Show
PS. just out of curiosity, why are your IniFiles saved as *.txt (regardless that it works reading them)? :think:
Yeah, I just threw txt in there instead for some reason or another. Guess it's just easier to edit with text editor than to right click and open with. And read can't read local files?
just me
Posts: 9574
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: iniread issue

03 May 2022, 03:40

Missing block braces?

Code: Select all

IniRead, OutputVar, Images.txt, Epiales, key
if (OutputVar = "") {
	FileSelectFile, SelectedFile, 3, , Open a file, Images (*.jpg; *.png; *.jpeg)
	Gui, Add, Picture,x15 y40 w470 h450, %SelectedFile%
	IniWrite, %SelectedFile%, Images.txt, Epiales, key
}
else { ; start of a new block
	IniRead, OutputVar, Images.txt, Epiales, key ; <<<<< useless to read the ini a second time
	Gui, Add, Picture,x15 y40 w470 h450, %OutputVar%
}
Return
User avatar
Epialis
Posts: 858
Joined: 02 Aug 2020, 22:44

Re: iniread issue

03 May 2022, 03:44

just me wrote:
03 May 2022, 03:40
Missing block braces?

Code: Select all

IniRead, OutputVar, Images.txt, Epiales, key
if (OutputVar = "") {
	FileSelectFile, SelectedFile, 3, , Open a file, Images (*.jpg; *.png; *.jpeg)
	Gui, Add, Picture,x15 y40 w470 h450, %SelectedFile%
	IniWrite, %SelectedFile%, Images.txt, Epiales, key
}
else { ; start of a new block
	IniRead, OutputVar, Images.txt, Epiales, key ; <<<<< useless to read the ini a second time
	Gui, Add, Picture,x15 y40 w470 h450, %OutputVar%
}
Return
I thought that as well, but it throws the ERROR. If the information is already in the txt/ini file as the section/key, then when I click the choose image, it auto loads the image from the file. If I start from scratch and remove the information from the file, it throws the ERROR when I click on choose image.

Also, without the if/else.. it loads the file fine and displays it just fine when I click on choose image and then click ok on the image I want. It also saves the information in the file.
just me
Posts: 9574
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: iniread issue

03 May 2022, 04:05

What ERROR is thrown? You don't define a default return value in IniRead, so in case of errors OutputVar will contain the string ERROR and will not be empty.
User avatar
Epialis
Posts: 858
Joined: 02 Aug 2020, 22:44

Re: iniread issue

03 May 2022, 04:08

just me wrote:
03 May 2022, 04:05
What ERROR is thrown? You don't define a default return value in IniRead, so in case of errors OutputVar will contain the string ERROR and will not be empty.

That's the only ERROR it shows... it won't add image or write to file or anything.. when I click choose image... just get that big ERROR on screen.
Attachments
capture12.jpg
capture12.jpg (5.34 KiB) Viewed 781 times
just me
Posts: 9574
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: iniread issue  Topic is solved

03 May 2022, 04:23

As I already said, if the INI can't be read, OutputVar contains the string ERROR. So the condition

Code: Select all

if (OutputVar = "") {
will never be true, To get an empty OutputVar you have to use

Code: Select all

IniRead, OutputVar, Images.txt, Epiales, key,  %A_Space%
Source: IniRead
User avatar
Epialis
Posts: 858
Joined: 02 Aug 2020, 22:44

Re: iniread issue

03 May 2022, 04:28

just me wrote:
03 May 2022, 04:23
As I already said, if the INI can't be read, OutputVar contains the string ERROR. So the condition

Code: Select all

if (OutputVar = "") {
will never be true, To get an empty OutputVar you have to use

Code: Select all

IniRead, OutputVar, Images.txt, Epiales, key,  %A_Space%
Source: IniRead
Ah Gotcha... Okay, %A_Space% works fine. Loads picture perfect... Only problem is, in order to load the image from the file, I still have to click on the choose image... then it loads. It doesn't show auto upon GUI load, which will work for what I need it to to do.

Thank you Just Me!
just me
Posts: 9574
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: iniread issue

03 May 2022, 07:40

Epialis wrote:Only problem is, in order to load the image from the file, I still have to click on the choose image...
No code, no help! ;)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], peter_ahk, zephyrus2706 and 368 guests