Sparrowlord Posted April 7, 2010 Share Posted April 7, 2010 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? Link to comment Share on other sites More sharing options...
enaiman Posted April 7, 2010 Share Posted April 7, 2010 (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 April 7, 2010 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 :) Link to comment Share on other sites More sharing options...
Sparrowlord Posted April 7, 2010 Author Share Posted April 7, 2010 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 Link to comment Share on other sites More sharing options...
blakel Posted April 7, 2010 Share Posted April 7, 2010 http://www.autoitscript.com/autoit3/docs/functions/Assign.htm Link to comment Share on other sites More sharing options...
MvGulik Posted April 7, 2010 Share Posted April 7, 2010 (edited) whatever Edited February 7, 2011 by MvGulik "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ... Link to comment Share on other sites More sharing options...
MHz Posted April 7, 2010 Share Posted April 7, 2010 Sure you can, but that don't mean you should. He can and probably will as is valid to do so. You saw the posted help by blakel? Assign("MyVar", "MyData", 2) MyFunction1() MyFunction2() func MyFunction1() if Eval("MyVar") Then MsgBox(0, '', Eval("MyVar")) ;; other code. EndIf EndFunc func MyFunction2() Assign("MyVar", 1, 2) EndFunc It seems like doing magic Link to comment Share on other sites More sharing options...
MvGulik Posted April 7, 2010 Share Posted April 7, 2010 (edited) whatever Edited February 7, 2011 by MvGulik "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ... Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now