Jump to content

Issues with having to many variables


 Share

Recommended Posts

Hi there , im very new to AutoIT, and i have 1 quick question.

Lets say i have, 20 Variables, i want to match up against something, if any of them match id like the if function to execute what is below it.

Is there a way to put it that would be less CPU intensive then;

Func Abc()

$1 = a

$2 = b

Etc etc,

If $1 OR $2 OR $3 etc etc

(code)

EndIf

EndFunc

I have never used Arrays, and i just looked in to them abit in the help file, still dosnt seem to make 100% sence.

Oh, and if i try to make the Variables Global, as in only load on script startup, i get the Error that the variable was not declared, how can i fix that?

Thank you very much in advance!

Link to comment
Share on other sites

Here is an array in a nut shell.

$my_array[5] is the same as declaring five variables. When you write $my_array[0] then that't the same as accessing the first variable that was declared. Same as for $my_array[1] which will be the second variable. The numbers start at zero and not one because indexing is not counting.

Link to comment
Share on other sites

see 'Dim' in the help file

if you still need help you should post some code so we can see what you're trying to do - 1 line of code is worth 1000 words :)

FUNCTIONS: WinDock (dock window to screen edge) | EditCtrl_ToggleLineWrap (line/word wrap for AU3 edit control) | SendEX (yet another alternative to Send( ) ) | Spell Checker (Hunspell wrapper) | SentenceCase (capitalize first letter of sentences)

CODE SNIPPITS: Dynamic tab width (set tab control width according to window width)

Link to comment
Share on other sites

Let’s say I have, 20 Variables, I want to match up against something, if any of them match id like the if function to execute what is below it.

This is something I would personally do with an array and a for loop, here is a small example that might help you.

#include <Array.au3>
Local $NamesArray[5] ; Creating your array.

$NamesArray[0] = "Mark" ; Setting the values of the array.
$NamesArray[1] = "John"
$NamesArray[2] = "Ben"
$NamesArray[3] = "Michael"
$NamesArray[4] = "Tim"

For $i = 0 to 4 ; This loop will execute until $i = 4 going up in increments of 1.
If $NamesArray[$i] = "Tim" Then ; If the array matches to the name Tim then display message.
MsgBox(64, "Testing", "Hello Tim!")
Else
MsgBox(64, "Testing", "You Are Not Tim You Are: " & $NamesArray[$i]) ; Else display other message.
EndIf
Next
Exit

Edit: I am not entirely sure if this is what you are after you might want to read up on switch statements to if you haven’t done so already.

Edited by Venix
Link to comment
Share on other sites

Thank you very much guys, i tried to make an array and it works perfectly now, it dosnt load up the variables every func call, that took alot of my CPU, "Global $Var" dosnt work for some reason, but the array did.

Anyhow thanks again (:

EDIT: There is no way of shortening this i asume?

IF $arr[0] OR $arr[1] OR $arr[2] OR $arr[3] OR $arr[4] OR $arr[5] OR $arr[6] OR $arr[7] OR $arr[8] OR $arr[9] OR $arr[10] OR $arr[11] OR $arr[12] OR $arr[13] OR $arr[14] OR $arr[15] OR $arr[16] OR $arr[17] OR $arr[18] OR $arr[19] OR $arr[20] OR $arr[21] = True Then

Edited by Makaveli10a
Link to comment
Share on other sites

EDIT: There is no way of shortening this i asume?

IF $arr[0] OR $arr[1] OR $arr[2] OR $arr[3] OR $arr[4] OR $arr[5] OR $arr[6] OR $arr[7] OR $arr[8] OR $arr[9] OR $arr[10] OR $arr[11] OR $arr[12] OR $arr[13] OR $arr[14] OR $arr[15] OR $arr[16] OR $arr[17] OR $arr[18] OR $arr[19] OR $arr[20] OR $arr[21] = True Then

uhh this?

This is something I would personally do with an array and a for loop, here is a small example that might help you.

#include <Array.au3>
Local $NamesArray[5] ; Creating your array.

$NamesArray[0] = "Mark" ; Setting the values of the array.
$NamesArray[1] = "John"
$NamesArray[2] = "Ben"
$NamesArray[3] = "Michael"
$NamesArray[4] = "Tim"

For $i = 0 to 4 ; This loop will execute until $i = 4 going up in increments of 1.
If $NamesArray[$i] = "Tim" Then ; If the array matches to the name Tim then display message.
MsgBox(64, "Testing", "Hello Tim!")
Else
MsgBox(64, "Testing", "You Are Not Tim You Are: " & $NamesArray[$i]) ; Else display other message.
EndIf
Next
Exit

Edited by Victorique
Link to comment
Share on other sites

Dim is bad. Use Local or Global exclusively.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

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