Jump to content

Variables scope question.


kenedy
 Share

Recommended Posts

Look at this example code.

How is that possible that myFunc can access $input2 value? I don't pass it as argument. :)

#include <guiconstants.au3>
ShowGUI()

Func ShowGUI()
   GUICreate("My GUI")
   $Input1 = GUICtrlCreateInput  ( "text1", 10, 10)
   $Input2 = GUICtrlCreateInput  ( "text2", 10, 30)
   $Input3 = GUICtrlCreateInput  ( "text3", 10, 50)
   GUISetState (@SW_SHOW)
   
   $msg = GUIGetMsg()
   myFunc($input1,$input3)
EndFunc 

Func myFunc ($first,$second)
   For $i = $first to $second
      MsgBox (0,"",GUIRead ( $i ))
   Next
EndFunc
Link to comment
Share on other sites

  • Developers

Look at this example code.

How is that possible that myFunc can access $input2 value? I don't pass it as argument.  :)

<{POST_SNAPBACK}>

Myfunc doesn't access $input2.

This will be the values for $input?;

$input1 = 1

$input2 = 2

$input3 = 3

You tell MyFunc to retrieve the values for control 1 to 3.

MyFunc itself does the retrieval itselve for the 3 controls.

Edited by JdeB

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

Look at this example code.

How is that possible that myFunc can access $input2 value? I don't pass it as argument.  :)

#include <guiconstants.au3>
ShowGUI()

Func ShowGUI()
   GUICreate("My GUI")
   $Input1 = GUICtrlCreateInput  ( "text1", 10, 10)
   $Input2 = GUICtrlCreateInput  ( "text2", 10, 30)
   $Input3 = GUICtrlCreateInput  ( "text3", 10, 50)
   GUISetState (@SW_SHOW)
   
   $msg = GUIGetMsg()
   myFunc($input1,$input3)
EndFunc 

Func myFunc ($first,$second)
   For $i = $first to $second
      MsgBox (0,"",GUIRead ( $i ))
   Next
EndFunc

<{POST_SNAPBACK}>

define $input2 as a global variable at the begining of your script :)
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...