Jump to content

Dynamic Array Size


Recommended Posts

I'm trying to get all the devices from a MySQL Database which works great then put them into a array that grows depending on the amount of devices as there could be ten there could be 1000 depending on the amount of devices on the network..

$Recordset.open("select device from pcdata", $Connection)
                    With $Recordset
                    $x = 1
                    While Not .EOF
                        $Found_Device = $Recordset.fields("DEVICE" ).Value
                        $devicearray[$x] = $Found_Device
                        $x = $x + 1
                        $devicearray[0] = $x
                        If UBound($devicearray[0]) = $devicearrayMAX Then
                            ReDim $devicearray[$devicearray[$x] + $devicearrayMAX]
                            $devicearrayMAX = $devicearray[0]
                        EndIf
                        _ArrayDisplay($devicearray)
                        .movenext
                                        Wend
                                        EndWith

I'm sure its something simple I'm missing..

Link to comment
Share on other sites

Yes there is something simple missing, the rest of your code, for it to make sense

where is $devicearray from

where is $devicearrayMAX from

etc...

"If UBound($devicearray[0])"

Unless that is an array of arrays, its wrong and maybe should be If UBound($devicearray), but its impossible to tell with selective code posting.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

You cannot make an array change in size after you declare it. Well, you can, but that erases the content of the array. Here is a work around:

When you first declare the array, make it huge (like 65535, considering that is the maximum). Some where in your loop, have a variable counting up to tell how many times you've gone through the loop. On your giant array, have the values continually adding to the array, but always have your 0th term be the number of items in the array (like how StringSplit() returns the strings, but term 0 is how many strings in the array there are). So the extra terms in your array won't be used, but the script can know that by telling how many there are by checking the 0th term.

If that doesn't work for you, you can always have the script run through the database without saving data to see how many terms you will need, then declaring the array and running through it again, this time saving data.

The former method will be faster.

For those who are asking questions, look in the help file first. I'm tired of people asking stupid questions about how to do things when 10 seconds in the help file could solve their problem.[quote name='JRowe' date='24 January 2010 - 05:58 PM' timestamp='1264381100' post='766337'][quote name='beerman' date='24 January 2010 - 03:28 PM' timestamp='1264372082' post='766300']They already have a punishment system for abuse.[/quote]... and his his name is Valik.[/quote]www.minikori.com

Link to comment
Share on other sites

"You cannot make an array change in size after you declare it. Well, you can, but that erases the content of the array"

ReDim

:huh2:

I do not deserve to program anymore.

For those who are asking questions, look in the help file first. I'm tired of people asking stupid questions about how to do things when 10 seconds in the help file could solve their problem.[quote name='JRowe' date='24 January 2010 - 05:58 PM' timestamp='1264381100' post='766337'][quote name='beerman' date='24 January 2010 - 03:28 PM' timestamp='1264372082' post='766300']They already have a punishment system for abuse.[/quote]... and his his name is Valik.[/quote]www.minikori.com

Link to comment
Share on other sites

@Minikori,

Please lookup ReDim in the help file before giving such advice, since your just plain wrong here.

@Ghost21,

You don't need doing the dirty job yourself. Try this:

$Recordset.open("select device from pcdata", $Connection)
                    With $Recordset
                        If Not .EOF Then
                            $devicearray = .GetRows()
                        Else
                            $devicearray = 0
                        EndIf
                    EndWith
                    $Recordset = 0
                    _ArrayDisplay($devicearray)

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 comment
Share on other sites

I created an Example yesterday about the most efficent way to ReDim, its called _ReDim in my signature.

Edited by guinness

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

When you do the

$Recordset.open("select device from pcdata", $Connection)

With $Recordset

If Not .EOF Then

$devicearray = .GetRows()

Else

$devicearray = 0

EndIf

EndWith

$Recordset.close

How do you read back each item...

_dbopen()

$Recordset.open("select device from pcdata", $Connection)

With $Recordset

If Not .EOF Then

$devicearray = .GetRows()

Else

$devicearray = 0

EndIf

EndWith

$Recordset.close

$z = UBound($devicearray)

_ArrayDisplay($devicearray)

For $x = 0 To $z

$device = $devicearray[$x] <--- keeps stopping here..

ERROR:

==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

etc..

Link to comment
Share on other sites

Not only!

Even with a 1D array your code will bomb out.

$z = UBound($devicearray)

_ArrayDisplay($devicearray)

For $x = 0 To $z - 1

$device = $devicearray[$x] <--- won't stop here..

Remember AutoIt arrays are zero-based! Indices run from 0 to UBound($ar1D) - 1

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