Sign in to follow this  
Followers 0
Mesca

Help with iniread Function

4 posts in this topic

#1 ·  Posted (edited)

I am trying to do something along the lines of this...

IniRead("config.ini", "Messages", $message, "Error")

I organized the messages in an ini and have the key names as numbers.

ex:

[Messages]

1 - random message

2 - another random message

The $message variable is a random generated number within the total number of messages.

My problem is that the key name needs to be in quotes. I tried """ & $message & """, but you can't quote quotations. :S

Any solution?

Edited by Mesca

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

wrap the quote in single quotes like: '"'

I keep getting "Error in expression" even when I do this.

Here is the code that I am using with the error.

$numberofmessages = IniRead("config.ini", "Messages", "NumberOfMessages", 1)
        $message = Random(1,$numberofmessages,1)
        GUICtrlSetData($CurrentMessageEdit, IniRead("config.ini", "Messages", '"' & $message & '"', "Error"))

/edit

I think it is boiling down to if you can use variables in iniread functions or not.

Edited by Mesca

Share this post


Link to post
Share on other sites

I keep getting "Error in expression" even when I do this.

Here is the code that I am using with the error.

$numberofmessages = IniRead("config.ini", "Messages", "NumberOfMessages", 1)
        $message = Random(1,$numberofmessages,1)
        GUICtrlSetData($CurrentMessageEdit, IniRead("config.ini", "Messages", '"' & $message & '"', "Error"))

/edit

I think it is boiling down to if you can use variables in iniread functions or not.

You've got your quotes in the wrong place: you need to wrap the results of the IniRead in the quotes, not the variable in the IniRead:

GUICreate("test")
$CurrentMessageEdit = GUICtrlCreateInput("", 5, 5)

$numberofmessages = IniRead("config.ini", "Messages", "NumberOfMessages", 1)
ConsoleWrite($numberofmessages & @CRLF)
$message = Random(1, $numberofmessages, 1)

GUICtrlSetData($CurrentMessageEdit, '"' & IniRead("config.ini", "Messages", $message, "Error") & '"')

GUISetState()

Do
Until GUIGetMsg() = -3

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