Jump to content

Recommended Posts

I have a need to create a number of variables like $Var_1, $_var2, ........$_VarN

The Assign function looks really good EXCEPT that if you try and USE any of the variables it creates, an exception is created:

"Warning:    $_Var1:   possibly used before declaration."

"ERROR:    $_Var1:   undeclared global variable"

Of course, if I declare them all, no problem. I just am trying to refactor my code to eliminate as many lines of code as possible.

If I declare them all, I have already CREATED them.

Is there any other way to dynamically create variables?

Link to post
Share on other sites

Use Eval:
 

#include <MsgBoxConstants.au3>

Example()

Func Example()
        ; Assign the variable string sString with data.
        Assign("sString", "This is a string which is declared using the function Assign")

        ; Find the value of the variable string sString and assign to the variable $sEvalString.
        Local $sEvalString = Eval("sString")

        ; Display the value of $sEvalString. This should be the same value as $sString.
        MsgBox($MB_SYSTEMMODAL, "", $sEvalString)
EndFunc   ;==>Example

 

Link to post
Share on other sites

The question remains: why play useless games with Assign & Eval in the first place?

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to post
Share on other sites

Hurley,

Thanks for the suggestion.

BTW

I dont have

<MsgBoxConstants.au3>

I get an error about variable not yet defined on

$MB_SYSTEMMODAL

Maybe because I dont have the message box constants. Is this file available on Autoit web site?

 

I will answer jchd's question here:

jc,

Usually, in a large program, hundreds of lines of code, it gets hard to manage it.

One good example to eliminate code (called refactoring) is when dozens of variables need to be created and assigned a value.

say I need to create 50 variables named $Lable_1 through $Label_55. This is what it would look like:
 

$Lable_1="ABC"

$Label_2="DEF"

$Label_3="GHI"

.

.

.

.

.

All the way to :

$Lable_55="ZZZ" ;Or what ever

 

Maybe not simpler but more CONCISE:

;Three lines of code
For $N=1 to 55

    Assign("Lable_" & $N, {the value needed}) ;here you would pull the value from an array that you created containing the value needed (well, one more line                                                ;of code)
    
Next

 

 

 

 

 

 

 

 

 

Link to post
Share on other sites

Then make your array 2D and store the controlID (useless for labels in most use cases) and the text. Or better yet, use a Map.

I've yet to see real-world code where Assign() is required or even useful.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to post
Share on other sites

BTW, the MsgBoxConstants.au3 UDF is part of the standard AutoIt install. Simply reinstall the latest version over your setup and you'll be on track.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

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

    No registered users viewing this page.

×
×
  • Create New...