Tiboi Posted May 23, 2010 Share Posted May 23, 2010 As the topic states to some of you this might be a silly question but to me its a brick wall in my way cause i just begun learning Autoit. Now i would like to know how to see information from one function, in another function. eg. Func DECLARATIONS() $var = GUICtrlRead($txtbox) $var0 = GUICtrlRead($txtbox0) $var1 = GUICtrlRead($txtbox1) $var1 = GUICtrlRead($txtbox1) EndFunc Func INIWRITE() IniWrite("Save.ini", $var, "Name", $var0) IniWrite("Save.ini", $var, "Address", $var1) IniWrite("Save.ini", $var, "Age", $var2) EndFunc i want the INIWRITE() function to be able to see the variables i declared in the DECLARATIONS() Function. can someone help me please? Link to comment Share on other sites More sharing options...
wimhek Posted May 23, 2010 Share Posted May 23, 2010 In Autoit variables in a function are local, you must declare them global. Link to comment Share on other sites More sharing options...
Tiboi Posted May 23, 2010 Author Share Posted May 23, 2010 In Autoit variables in a function are local, you must declare them global. u mean like this? Func DECLARATIONS() Global $var = GUICtrlRead($txtbox) Global $var0 = GUICtrlRead($txtbox0) Global $var1 = GUICtrlRead($txtbox1) Global $var2 = GUICtrlRead($txtbox2) EndFunc Func INIWRITE() IniWrite("Save.ini", $var, "Name", $var0) IniWrite("Save.ini", $var, "Address", $var1) IniWrite("Save.ini", $var, "Age", $var2) EndFunc cause i still get the errors: "WARNING: $var: possibly used before declaration." "WARNING: $var0: possibly used before declaration." "WARNING: $var1: possibly used before declaration." "WARNING: $var2: possibly used before declaration." Link to comment Share on other sites More sharing options...
Tiboi Posted May 23, 2010 Author Share Posted May 23, 2010 (edited) This is an example of what the code is. its not the actual progrm i'm writing but it is close in structure. expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $Main = GUICreate("Test", 187, 97, 192, 124) $txtbox = GUICtrlCreateInput("", 0, 0, 121, 21) GUICtrlSetTip(-1, "Name") $txtbox0 = GUICtrlCreateInput("", 0, 24, 121, 21) GUICtrlSetTip(-1, "Sex") $txtbox1 = GUICtrlCreateInput("", 0, 48, 121, 21) GUICtrlSetTip(-1, "Address") $txtbox2 = GUICtrlCreateInput("", 0, 72, 121, 21) GUICtrlSetTip(-1, "Age") $Button1 = GUICtrlCreateButton("Save", 128, 24, 51, 25, $WS_GROUP) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 INI_WRITE() EndSwitch WEnd Func DECLARATIONS() Global $var = GUICtrlRead($txtbox) Global $var0 = GUICtrlRead($txtbox0) Global $var1 = GUICtrlRead($txtbox1) Global $var2 = GUICtrlRead($txtbox2) EndFunc Func INI_WRITE() IniWrite("Save.ini", $var, "Sex", $var0) IniWrite("Save.ini", $var, "Address", $var1) IniWrite("Save.ini", $var, "Age", $var2) EndFunc Func INI_WRITE2() IniWrite("Save2.ini", $var, "Sex", $var0) IniWrite("Save2.ini", $var, "Address", $var1) IniWrite("Save2.ini", $var, "Age", $var2) EndFunc Edited May 23, 2010 by Tiboi Link to comment Share on other sites More sharing options...
Makaule Posted May 23, 2010 Share Posted May 23, 2010 The problem is, that you dont call DECLARATIONS() function, that means it never declare variables, so either declare it at the begining, either declare it inside function. Link to comment Share on other sites More sharing options...
dBladez Posted May 23, 2010 Share Posted May 23, 2010 Declare your global variables at the top of your script and then whenever you need to use them just call the populateVariables function to make sure they have the newest infomation. expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global $var, $var0, $var1, $var2 $Main = GUICreate("Test", 187, 97, 192, 124) $txtbox = GUICtrlCreateInput("", 0, 0, 121, 21) GUICtrlSetTip(-1, "Name") $txtbox0 = GUICtrlCreateInput("", 0, 24, 121, 21) GUICtrlSetTip(-1, "Sex") $txtbox1 = GUICtrlCreateInput("", 0, 48, 121, 21) GUICtrlSetTip(-1, "Address") $txtbox2 = GUICtrlCreateInput("", 0, 72, 121, 21) GUICtrlSetTip(-1, "Age") $Button1 = GUICtrlCreateButton("Save", 128, 24, 51, 25, $WS_GROUP) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 populateVariables() INI_WRITE() EndSwitch WEnd Func populateVariables() $var = GUICtrlRead($txtbox) $var0 = GUICtrlRead($txtbox0) $var1 = GUICtrlRead($txtbox1) $var2 = GUICtrlRead($txtbox2) EndFunc Func INI_WRITE() IniWrite("Save.ini", $var, "Sex", $var0) IniWrite("Save.ini", $var, "Address", $var1) IniWrite("Save.ini", $var, "Age", $var2) EndFunc Func INI_WRITE2() IniWrite("Save2.ini", $var, "Sex", $var0) IniWrite("Save2.ini", $var, "Address", $var1) IniWrite("Save2.ini", $var, "Age", $var2) EndFunc Link to comment Share on other sites More sharing options...
Tiboi Posted May 23, 2010 Author Share Posted May 23, 2010 thanks for the help everyone especially 'dBladez' you made me really understand what i need to do. thanks man. Link to comment Share on other sites More sharing options...
Tiboi Posted May 23, 2010 Author Share Posted May 23, 2010 is there a shorter way to write this? Func INI_WRITE() IniWrite("Save.ini", $var, "Sex", $var0) IniWrite("Save.ini", $var, "Address", $var1) IniWrite("Save.ini", $var, "Age", $var2) EndFunc Link to comment Share on other sites More sharing options...
Developers Jos Posted May 23, 2010 Developers Share Posted May 23, 2010 Shorter? You mean you have many more variables to write? SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Tiboi Posted May 23, 2010 Author Share Posted May 23, 2010 Shorter? You mean you have many more variables to write? Func INI_WRITE() IniWrite("Save.ini", $var, "Sex", $var0) IniWrite("Save.ini", $var, "Address", $var1) IniWrite("Save.ini", $var, "Age", $var2) EndFunc i mean like writing (IniWrite("Save.ini", $var,) once, then add the rest of the information instead of having to write it 3 times Link to comment Share on other sites More sharing options...
Developers Jos Posted May 23, 2010 Developers Share Posted May 23, 2010 Func INI_WRITE() IniWrite("Save.ini", $var, "Sex", $var0) IniWrite("Save.ini", $var, "Address", $var1) IniWrite("Save.ini", $var, "Age", $var2) EndFunc i mean like writing (IniWrite("Save.ini", $var,) once, then add the rest of the information instead of having to write it 3 times In SciTE use Ctrl+D to duplicate the line. Other than that I cannot see your issue. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
monoceres Posted May 23, 2010 Share Posted May 23, 2010 Maybe using an 2D array? Local $array[3][2]=[["sex","male"],["age","undefined"],["address","home"]] For $i = 0 To Ubound($array) IniWrite("save.ini","test",$array[$i][0],$array[0][1]) Next Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
JohnOne Posted May 23, 2010 Share Posted May 23, 2010 would this work, if you didnt want to use globals? _INIWRITE(DECLARATIONS()) Func DECLARATIONS() Local $aVars[4] $aVars[0] = GUICtrlRead($txtbox) $aVars[1] = GUICtrlRead($txtbox0) $aVars[2] = GUICtrlRead($txtbox1) $aVars[3] = GUICtrlRead($txtbox1) Return $aVars EndFunc Func _INIWRITE($array) IniWrite("Save.ini", $array[0], "Name", $var0) IniWrite("Save.ini", $array[1], "Address", $var1) IniWrite("Save.ini", $array[2], "Age", $var2) EndFunc AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Tiboi Posted May 23, 2010 Author Share Posted May 23, 2010 (edited) Reply to " monoceres" Maybe using an 2D array? Local $array[3][2]=[["sex","male"],["age","undefined"],["address","home"]] For $i = 0 To Ubound($array) IniWrite("save.ini","test",$array[$i][0],$array[0][1]) Next i'll try this out thank you. reply to "JohnOne" would this work, if you didnt want to use globals? _INIWRITE(DECLARATIONS()) Func DECLARATIONS() Local $aVars[4] $aVars[0] = GUICtrlRead($txtbox) $aVars[1] = GUICtrlRead($txtbox0) $aVars[2] = GUICtrlRead($txtbox1) $aVars[3] = GUICtrlRead($txtbox1) Return $aVars EndFunc Func _INIWRITE($array) IniWrite("Save.ini", $array[0], "Name", $var0) IniWrite("Save.ini", $array[1], "Address", $var1) IniWrite("Save.ini", $array[2], "Age", $var2) EndFunc thanks for your help but this is way beyond me. only started learning 3 nights ago. i know nothing about arrays. my app comming along great tho Edited May 23, 2010 by Tiboi 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