Jump to content

Recommended Posts

Posted (edited)

Is it possible to edit part of a variable name?

While 1

    If $name1 = " "
    
    EndIf
    
    If $name2 = " "
    
    EndI

    If $name3 = " "
    
    EndIf
    
    Local newvar = $name(+= 1)
WEnd

I mean adding +1 in the var name instead +1 in var value.

Edited by c7aesa7r
Posted

It’s simpler to use arrays in this case.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted (edited)

sure, the help file is full of array examples as well as the Assign function

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Posted

Don't be addict to the name of variables. A name is just a tag you attach to a particular piece of data.

I your case, use an array and vary the index.

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)

Posted

As others have mentioned an array would be the better approach as it gives you alot more flexibility, basic example of both using basic array and assign functionality.

;~ Array Example
#include <Array.au3> ;~ Required for _Array functions _ArrayAdd, _ArrayDisplay
Global $aName[3] = ["", 2, "third"] ;~ add data to three array items: $aName[0] = "", $aName[1] = 1 and $aName[2] = "third"
_ArrayDisplay($aName, "Before Changes to $aName array") ;~ You can view the values of your array using _ArrayDisplay
;~ You can check your items using the following, just remember arrays start at 0

If $aName[0] = "" Then ;~ We set the value above to "" above, so this will return true
    MsgBox(4096, "Success", 'Before: $aName[1] = "' & $aName[0] & '"')
    $aName[0] = "First array item"  ;~  ;~ Change the value to "First array item"
    MsgBox(4096, "Success", 'After: $aName[1] = "' & $aName[0] & '"')
EndIf
If $aName[1] = 2 Then ;~ We set the value above to 2 above, so this will return true
    MsgBox(4096, "Success", 'Before: $aName[1] = "' & $aName[1] & '"')
    $aName[1] = "Second array item" ;~  ;~ Change the value to "Second array item"
    MsgBox(4096, "Success", 'After: $aName[1] = "' & $aName[1] & '"')
EndIf
If $aName[2] = "third" Then
    MsgBox(4096, "Success", 'Before: $aName[2] = "' & $aName[2] & '"')
    $aName[2] = "Third array item"  ;~  ;~ Change the value to "Third array item"
    MsgBox(4096, "Success", 'After: $aName[2] = "' & $aName[2] & '"')
EndIf

;~ To add additional items you can use ReDim or use the _ArrayAdd to add any additional items to the array
If UBound($aName) = 3 Then ;~ Check if we've reached the end of the array
    _ArrayAdd($aName, "Forth array item")
EndIf
_ArrayDisplay($aName, "After Changes to $aName array")

;~ You can also loop through the array items using For/Next
For $i = 0 To UBound($aName) - 1
    MsgBox(4096, 'Array Item: "' & $i, "$aName[" & $i & '] = "' & $aName[$i] & '"')
    $aName[$i] = StringUpper($aName[$i]) ;~ Change all the values to uppercase
Next

_ArrayDisplay($aName, "UpperCase")

;~ Assign Example
For $i = 1 To 4
    Assign("name" & $i, $i)
Next

If IsDeclared("name1") Then MsgBox(4096, "Success: Name1 Variable", "$name1 = " & Eval("name1"))
If IsDeclared("name2") Then MsgBox(4096, "Success: Name2 Variable", "$name2 = " & Eval("name2"))
If IsDeclared("name3") Then MsgBox(4096, "Success: Name3 Variable", "$name3 = " & Eval("name3"))
If IsDeclared("name4") Then MsgBox(4096, "Success: Name4 Variable", "$name4 = " & Eval("name4"))
If IsDeclared("name5") Then
    MsgBox(4096, "Success: Name5 Variable", "$name5 = " & Eval("name5")) ;~ This message shouldn't appear as we didn't assign the variable name5
Else
    Assign("name5", 5)
    MsgBox(16, "Failure: Name5 Variable", "$name5 was not declared: " & @CRLF & "$name5 = " & Eval("name5"))
EndIf

 

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