Jump to content

increase array size in a 3 col array


masonje
 Share

Recommended Posts

I need to add values to 3 column array with unknown number of rows, but I can't quite figure out how to expand the array AND add the data in. One of the guys at work had a 1 column _ArrayAddAdv function, but I can't quite figure out what to add to make it work for me. Here is some sample code and guess as to how to make it work.

#include <Array.au3>

$SW = "\\10.1.2.5\share;.Apps.SW.KMA.Corp;.AppsGrps.Apps.SW.KMA.Corp"
$SMABQ = "\\10.1.5.2\share;.Applications.ABQ.SM.KMA.Corp;.AppsGrps.Applications.ABQ.SM.KMA.Corp"
$SMLV = "\\10.4.5.3\share;.Applications.LV.SM.KMA.Corp;.Applications.LV.SM.KMA.Corp"

Dim $avArray[1][1][1]

_ArrayAddAdv($avArray, $SW)
_ArrayAddAdv($avArray, $SMABQ)
_ArrayAddAdv($avArray, $SMLV)

_ArrayDisplay( $avArray, "Whole array" )

Func _ArrayAddAdv(ByRef $avArray, $sValue)
    If IsArray($avArray) Then
        $sValueSplit = StringSplit($sValue, ";")
        ReDim $avArray[UBound($avArray) + 1]
        $avArray[0][0][0] = UBound($avArray) - 1
        $avArray[UBound($avArray) - 1] = $sValueSplit[ ;something here but I'm not sure what...
        SetError(0)
        Return 1
    Else
        SetError(1)
        Return 0
    EndIf
EndFunc   ;==>_ArrayAddAdv

Each office is a little different and that is why I have to set up my scripts with separate info for each location. Makes scripting deployments difficult. I was using different dims for each piece of info, but it is making my script more difficult to manage as I add functionality.

Thanks for your help

Link to comment
Share on other sites

ReDim $arr[1][2][3]

ok... Thanks for the tip...

Anyway, did some more reading on ReDim and I think this is what it should look like but it's not panning out. What's wrong with this picture? I keep getting, "Array variable has incorrect number of subscripts or subscript dimension range exceeded."

#include <Array.au3>

$SW = "\\10.1.2.5\share;.Apps.SW.KMA.Corp;.AppsGrps.Apps.SW.KMA.Corp"
$SMABQ = "\\10.1.5.2\share;.Applications.ABQ.SM.KMA.Corp;.AppsGrps.Applications.ABQ.SM.KMA.Corp"
$SMLV = "\\10.4.5.3\share;.Applications.LV.SM.KMA.Corp;.Applications.LV.SM.KMA.Corp"

Dim $x[1][1][1]

_ArrayAddAdv($x, $SW)
_ArrayAddAdv($x, $SMABQ)
_ArrayAddAdv($x, $SMLV)

_ArrayDisplay($x, "Whole array")

Func _ArrayAddAdv(ByRef $avArray, $sValue)
    If IsArray($avArray) Then
        $sValueSplit = StringSplit($sValue, ";")
        ReDim $avArray[UBound($avArray) + 1][1][1]
        $UBound = UBound($avArray) - 1
        $avArray[0][0][0] = $UBound
        $avArray[$UBound][0][0] = $sValueSplit[1]
        $avArray[$UBound][1][0] = $sValueSplit[2]
        $avArray[$UBound][0][1] = $sValueSplit[3]
        SetError(0)
        Return 1
    Else
        SetError(1)
        Return 0
    EndIf
EndFunc   ;==>_ArrayAddAdv
Link to comment
Share on other sites

#include <Array.au3>

$SW = "\\10.1.2.5\share;.Apps.SW.KMA.Corp;.AppsGrps.Apps.SW.KMA.Corp"
$SMABQ = "\\10.1.5.2\share;.Applications.ABQ.SM.KMA.Corp;.AppsGrps.Applications.ABQ.SM.KMA.Corp"
$SMLV = "\\10.4.5.3\share;.Applications.LV.SM.KMA.Corp;.Applications.LV.SM.KMA.Corp"

Dim $x[1][1][1]

_ArrayAddAdv($x, $SW)
_ArrayAddAdv($x, $SMABQ)
_ArrayAddAdv($x, $SMLV)

_ArrayDisplay($x, "Whole array")

Func _ArrayAddAdv(ByRef $avArray, $sValue)
    If IsArray($avArray) Then
        $sValueSplit = StringSplit($sValue, ";")
        ReDim $avArray[UBound($avArray) + 1][2][2]
        $UBound = UBound($avArray) - 1
        $avArray[0][0][0] = $UBound
        $avArray[$UBound][0][0] = $sValueSplit[1]
        $avArray[$UBound][1][0] = $sValueSplit[2]
        $avArray[$UBound][0][1] = $sValueSplit[3]
        SetError(0)
        Return 1
    Else
        SetError(1)
        Return 0
    EndIf
EndFunc  ;==>_ArrayAddAdv

Because you've got a 3 dimensional array, _ArrayDisplay won't work for that purpose... :D

Link to comment
Share on other sites

Hi,

try

; ArrayAdd3D.au3
#include <_ArrayDebugDisplay.au3>
$SW = "\\10.1.2.5\share;.Apps.SW.KMA.Corp;.AppsGrps.Apps.SW.KMA.Corp"
$SMABQ = "\\10.1.5.2\share;.Applications.ABQ.SM.KMA.Corp;.AppsGrps.Applications.ABQ.SM.KMA.Corp"
$SMLV = "\\10.4.5.3\share;.Applications.LV.SM.KMA.Corp;.Applications.LV.SM.KMA.Corp"

Dim $x[1][1][1]
_Arraydisplay3D($x, 1)

_ArrayAddAdv($x, $SW)
_Arraydisplay3D($x, 1)
_ArrayAddAdv($x, $SMABQ)
_Arraydisplay3D($x, 1)
_ArrayAddAdv($x, $SMLV)
_Arraydisplay3D($x, 1)

;~ _ArrayDisplay($x, "Whole array")

Func _ArrayAddAdv(ByRef $avArray, $sValue)
    If IsArray($avArray) Then
        $arValueSplit = StringSplit($sValue, ";")
        ReDim $avArray[UBound($avArray) + 1][2][2] ;so 1 more item in 1st dim
        $UBound = UBound($avArray) - 1
        $avArray[0][0][0] = $UBound
        $avArray[$UBound][0][0] = $arValueSplit[1]
        $avArray[$UBound][1][0] = $arValueSplit[2]
        $avArray[$UBound][0][1] = $arValueSplit[3]
        SetError(0)
        Return 1
    Else
        SetError(1)
        Return 0
    EndIf
EndFunc   ;==>_ArrayAddAdv
;~ _Arraydisplay3D($assy_Elements)
;~ _Arraydisplay3D($assy_Elements, 1)
;~ _Arraydisplay3D($assy_Elements, 0, 1)
;~ _Arraydisplay3D($assy_Elements, 1, 1)
;=============================================================================
Best, randall
Link to comment
Share on other sites

I'm a big fat dork. I didn't realize I was setting up a 3d array. This is what I needed and it works now. Thanks for the help guys....

Dim $x[1][3]

_ArrayAddAdv($x, $SW)
_ArrayAddAdv($x, $SMABQ)
_ArrayAddAdv($x, $SMLV)

_ArrayDisplay($x, "Whole array")

Func _ArrayAddAdv(ByRef $avArray, $sValue)
    If IsArray($avArray) Then
        $sValueSplit = StringSplit($sValue, ";")
        ReDim $avArray[UBound($avArray) + 1][3]
        $UBound = UBound($avArray) - 1
        $avArray[0][0] = $UBound
        $avArray[$UBound][0] = $sValueSplit[1]
        $avArray[$UBound][1] = $sValueSplit[2]
        $avArray[$UBound][2] = $sValueSplit[3]
        SetError(0)
        Return 1
    Else
        SetError(1)
        Return 0
    EndIf
EndFunc  ;==>_ArrayAddAdv
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...