Jump to content

Recommended Posts

Posted

Hi,

I'm trying to use IniReadSection from inside of one of my functions and I'm wanting to take each ini key and make it a variable that I can access throughout the script.

$var = IniReadSection("C:\Temp\myfile.ini", "section2")
If @error Then 
    MsgBox(4096, "", "Error occurred, probably no INI file.")
Else
    For $i = 1 To $var[0][0]
        MsgBox(4096, "", "Key: " & $var[$i][0] & @CRLF & "Value: " & $var[$i][1])
    Next
EndIf

Now, obviously "$var[$i][0]" is the key I'm after and I believe I can make it global to everything by doing:

$var = IniReadSection("C:\Temp\myfile.ini", "section2")
If @error Then 
    MsgBox(4096, "", "Error occurred, probably no INI file.")
Else
    For $i = 1 To $var[0][0]
        $var_name = $var[$i][0]
        $var_value = $var[$i][1]
        
        Global $var_name
        
        ;how to set the global $var_name value now?
    Next
EndIf

Am I on the right path here?

If so how do I set the value then?

Posted (edited)

Just put "Global $var_name" somewhere in the main part of your script.

(usually you declare the variable first)

You can change its value from anywhere after that.

Global $var_name
$var = IniReadSection("C:\Temp\myfile.ini", "section2")
If @error Then 
    MsgBox(4096, "", "Error occurred, probably no INI file.")
Else
    For $i = 1 To $var[0][0]
        $var_name = $var[$i][0]
        $var_value = $var[$i][1]
    Next
EndIf

Looking at what's happening at this moment inside your example script: $var_name will take all the values in your array and ending up being equal to the last one at the end of the loop; you will need to USE that somewhere before going to the next value ...

Edited by enaiman

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Posted

I'm not sure if I'm following along correctly. I'm trying to make dynamic variables from within my ini file. Is there no way to make a global variable from inside of the function and assign it's value? That way the loop sets all the global variables and their values without me having to predefine it

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...