Jump to content
Chimaera

Does Array Count 0 element have to be accurate?

Recommended Posts

Chimaera

Ive got an array which is 186 elements then i add another array of 48 or so to it, now the count stays at 186 but

If there is an item after the 186 does it get missed because the cycle through the array stops at 186?

How do i reset the number to be accurate if thats the case?
I made a small reproducer to show it
 

#include <Array.au3>

$sRemoveServices = 'AeLookupSvc|ALG|AppHostSvc'
Global $aRemoveServices = StringSplit($sRemoveServices, "|")
_ArrayDisplay($aRemoveServices, 'Initial Services')

$sServiceTotalArray = 'AntiVirService|AntiVirSchedulerService'
Global $aServiceTotalArray= StringSplit($sServiceTotalArray, "|")

Local $aServiceArrayAdd = _ArrayAdd($aRemoveServices, $aServiceTotalArray, '0', '|')
_ArraySort($aRemoveServices) ; sort them into numerical
_ArrayDelete($aRemoveServices, 0) ; for some reason it picks up a another index  after the add so i delete it
;~ ReDim $aRemoveServices
_ArrayDisplay($aRemoveServices, 'Total Services')

Now i started looking at redim but couldnt figure out what element to give as i dont know the last element

Edited by Chimaera

Share this post


Link to post
Share on other sites
Melba23

Chimaera,

No, the actual value in the [0] element has no effect on the rest of the array.  It is just used as a shortcut count by some AutoIt functions and does not need to be accurate - if you think about it, how would AutoIt even know that it was a count? If you need to know the number of elements in an array, just use UBound.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Chimaera

Ok im finding its not picking up some that are in that section after the 186 so ill go and recheck to see if i can find any thing else that might be causing it.

Many thanks

Share this post


Link to post
Share on other sites
iamtheky

if you wanted to keep it, you have all the info prior to the _arrayadd.

$aRemoveServices[0] = ubound($aRemoveServices) + ubound($aServiceTotalArray)

i think that number could also be used for a redim, but that would seem unnecessary since _arrayadd did that.


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites
Melba23

Chimaera,

If you are coding the loop like this:

For $i = 1 To $aArray[0]

then you do need an accurate count - if not then the loop will stop too early or you will get an overrun error.

If you do not know that the [0] element count is accurate (or indeed you do not have one) then do it like this:

For $i = 1 To UBound($aArray) - 1

Clear now?

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Chimaera

Still working with this i decided to add a progress bar as it passes through the array

got the single array ones working but the joining arrays together for a different task is making me cross

Local $aServiceStopAdd0 = _ArrayAdd($aServiceStopArray, $sServiceManualList)
Local $aServiceStopAdd1 = _ArrayAdd($aServiceStopArray, $sServiceDisabledList)
_ArraySort($aServiceStopArray)
_ArrayDisplay($aServiceStopArray, 'Services To Stop')
$sStopCount = Round( _ArrayMax($aServiceStopArray)  /3, 0)
ConsoleWrite('Stop Count = ' & $sStopCount & @CRLF)

This how im joining them but it has no 0 (number) section with the count so the arraymax doesnt have a number to work with

I tried boththose suggestion like 

Global $aServiceStopArray[0] = UBound($aServiceDisabledArray) + UBound($aServiceManualArray)
;~ Local $aServiceStopAdd0 = _ArrayAdd($aServiceStopArray, $sServiceManualList)
;~ Local $aServiceStopAdd1 = _ArrayAdd($aServiceStopArray, $sServiceDisabledList)
_ArraySort($aServiceStopArray)
_ArrayDisplay($aServiceStopArray, 'Services To Stop')
$sStopCount = Round( _ArrayMax($aServiceStopArray)  /3, 0)
ConsoleWrite('Stop Count = ' & $sStopCount & @CRLF)

but it gives me an error like this

: error: Statement cannot be just an expression.
Global $aServiceStopArray[0] = UBound

Any suggestions? 

Edited by Chimaera

Share this post


Link to post
Share on other sites
Malkey

_ArrayAdd() does not return a third array.   Also see AutoIt help file.

#include <Array.au3>

$sRemoveServices = 'AeLookupSvc|ALG|AppHostSvc'
Global $aArray1 = StringSplit($sRemoveServices, "|", 2) ; $STR_NOCOUNT (2) = disable the return count in the first element - effectively makes the array 0-based (must use UBound() to get the size of the array in this case).
_ArrayDisplay($aArray1, '0-based Array1')

$sServiceTotalArray = 'AntiVirService|AntiVirSchedulerService'
Global $aArray2 = StringSplit($sServiceTotalArray, "|", 2) ; $STR_NOCOUNT (2) = disable the return count in the first element - effectively makes the array 0-based (must use UBound() to get the size of the array in this case).
_ArrayDisplay($aArray2, '0-based Array2')

_ArrayAdd($aArray1, $aArray2) ; The 3rd parameter of _ArrayAdd, $iStart, [optional] Column in which addition is to begin (2D array only). See _ArrayConcatenate() for a $iStart parameter.
_ArrayDisplay($aArray1, '0-based ($aArray1 + Array2)')

_ArrayInsert($aArray1, 0, UBound($aArray1)) ; Convert $aArray1 from a 0-based array into a 1-based array.
_ArrayDisplay($aArray1, '1-based Array')

 

Share this post


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

×