Jump to content

Help with iniread Function


Mesca
 Share

Recommended Posts

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

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