Jump to content

Can i declare a variable multiple times?


Go to solution Solved by TheDcoder,

Recommended Posts

  • Moderators
Posted

TheDcoder,

Can you give an example script where this happens? Although there should be no problem in most cases, I can imagine circumstances where it might cause difficulties. :wacko:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted

Can you please describe the scope where you want to use the variable (in the whole script, only a function)?

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted

  On 12/30/2014 at 8:41 AM, Melba23 said:

TheDcoder,

Can you give an example script where this happens? Although there should be no problem in most cases, I can imagine circumstances where it might cause difficulties. :wacko:

M23

 

  On 12/30/2014 at 11:47 AM, water said:

Can you please describe the scope where you want to use the variable (in the whole script, only a function)?

I dont have any scripts like that, just i was thinking about a function and it got popped up in my head

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

  • Moderators
Posted

It is a little difficult to answer your question when you cannot explain what you're after. As water alluded to, declaring a variable more than once depends on the scope of that variable. We really need an example of how you are thinking of putting this to use - help us help you ;)

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Posted
  On 12/30/2014 at 1:55 PM, JLogan3o13 said:

It is a little difficult to answer your question when you cannot explain what you're after. As water alluded to, declaring a variable more than once depends on the scope of that variable. We really need an example of how you are thinking of putting this to use - help us help you ;)

Its nothing serious you see, i just had a thought  o:)

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

  • 2 months later...
  • Solution
Posted

; Testing variables with Global Scope

Global $var_global = InputBox("Testing Global Variables", "Please enter anything: ")
Global $var_global = InputBox("Testing Global Variables", "Please enter anything: ")

; Results:
;
; 1st declaration = The
; 2nd declaration = Dcoder
;
; Result = Dcoder

MsgBox(64, "Result", "Result: " & $var_global)

; Testing variables with Global Scope

Local $var_local = InputBox("Testing Local Variables", "Please enter anything: ")
Local $var_local = InputBox("Testing Local Variables", "Please enter anything: ")

MsgBox(64, "Result", "Result: " & $var_local)

; Results:
;
; 1st declaration = The
; 2st declaration = Dcoder
;
; Result = Dcoder

; Testing variables with Dim Scope

Dim $var_dim = InputBox("Testing Dim Variables", "Please enter anything: ")
Dim $var_dim = InputBox("Testing Dim Variables", "Please enter anything: ")

MsgBox(64, "Result", "Result: " & $var_local)

; Results:
;
; 1st declaration = The
; 2st declaration = Dcoder
;
; Result = Dcoder

; Conclusion: Declaring a variable with any scope a 2nd time will result in loss of data in the variable

Exit

TD :)

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Posted

Following the AutoIt naming conventions doesn't result in problems like this happening. Oh, and Dim is kind of frowned upon if not converting a non-Array variable to an array.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

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...