232showtime

Insert Values to Array Column

20 posts in this topic

been practicing array for weeks and got confused, came up with this, How can I insert values in blank array column using this method:

#include <Array.au3>

Example()

Func Example()
    Local $aArray[6][2]
    For $i = 0 To UBound($aArray) - 1
        For $j = 0 To $aArray
            $aArray[$i][$j] = $i
        Next
    Next
    _ArrayDisplay($aArray) ; Display the array.
EndFunc   ;==>Example

 


ill get to that... i still need to learn and understand a lot of codes graduated.gif

Correct answer, learn to walk before you take on that marathon.

Share this post


Link to post
Share on other sites



#include <Array.au3>

Example()

Func Example()
    Local $aArray[6][2]
    For $i = 0 To UBound($aArray) - 1
        For $j = 0 To $aArray
            $aArray[$i][$j] = $i
            $aArray[$i][1] = $i
        Next
    Next
    _ArrayDisplay($aArray) ; Display the array.
EndFunc   ;==>Example

 

1 person likes this

Share this post


Link to post
Share on other sites

thanks, need more practice. :lol::lol::lol:


ill get to that... i still need to learn and understand a lot of codes graduated.gif

Correct answer, learn to walk before you take on that marathon.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <MsgBoxConstants.au3>
#include <Array.au3>

$hello= "123"
    ; 3 column load  [row][column]
    Local $aItems1 [4] =["IP","SUB","Gateawy","DNS"]
    _ArrayDisplay($aItems1)
    Local $aItems[4][4]
    ;_ArrayDisplay($aItems)

   For $iI = 0 To UBound($aItems) - 1

     For $ij = 0 To UBound($aItems) - 1

      $aItems[$iI][$iJ] = $iI &"-"& $ij
      $aItems[0][0] = "ip:" &$hello
      $aItems[1][0] = "Sub:" &$hello
      $aItems[2][0] = "Gateway:" &$hello
      $aItems[3][0] = "DNS:" &$hello


     Next




   Next


 _ArrayDisplay($aItems)

some help here, how do I fill programmatically from  top to bottom for each column or across as long the pattern is the same. I can do it manually but that will defeat the purpose

array.png

Edited by antonioj84

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Hi,

to answer this part of your question "fill top to bottom", this does that:

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <MsgBoxConstants.au3>
#include <Array.au3>

$hello= "123"
    ; 3 column load  [row][column]
    Local $aItems1 [4] =["IP","SUB","Gateawy","DNS"]
    _ArrayDisplay($aItems1)
    Local $aItems[4][4]
    ;_ArrayDisplay($aItems)

   For $i = 0 To UBound($aItems) - 1

     For $j = 0 To UBound($aItems) - 1

;~       $aItems[$iI][$iJ] = $iI &"-"& $ij
      $aItems[$j][$i] = "ip:" &$hello
      $aItems[$j][$i] = "Sub:" &$hello
      $aItems[$j][$i] = "Gateway:" &$hello
      $aItems[$j][$i] = "DNS:" &$hello
      _ArrayDisplay($aItems)
     Next
   Next

 _ArrayDisplay($aItems)

 

Edited by l3ill

Share this post


Link to post
Share on other sites

I assume you were going for something like this?

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <MsgBoxConstants.au3>
#include <Array.au3>

$hello= "123"
    ; 3 column load  [row][column]
    Local $aItems1 [4] =["IP","SUB","Gateawy","DNS"]
    _ArrayDisplay($aItems1)
    Local $aItems[4][4]
    ;_ArrayDisplay($aItems)

   For $i = 0 To UBound($aItems) - 1

     For $j = 0 To UBound($aItems1) - 1

;~       $aItems[$iI][$iJ] = $iI &"-"& $ij
      $aItems[$j][$i] = $aItems1[$j] & $hello

      _ArrayDisplay($aItems)
     Next
   Next

 _ArrayDisplay($aItems)

 

1 person likes this

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

thanks  i3ill

that is exactly what I wanted, thank you so much, i just could NOT  walk in the aitems1, I Promised to learn and be good in array  in the next 3 months

 

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <MsgBoxConstants.au3>
#include <Array.au3>

$hello= "123"
    ; 3 column load  [row][column]
    Local $aItems1 [4] =["IP","SUB","Gateawy","DNS"]
    _ArrayDisplay($aItems1)
    Local $aItems[4][4]
    ;_ArrayDisplay($aItems)

   For $i = 0 To UBound($aItems) - 1

     For $j = 0 To UBound($aItems1) - 1

;~       $aItems[$iI][$iJ] = $iI &"-"& $ij
      $aItems[$j][$i] = $aItems1[$j] & $hello

      _ArrayDisplay($aItems)
     Next
   Next

 _ArrayDisplay($aItems)

 

Edited by antonioj84

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

sorry the bother again,  is there a better to populate the arrays ? should I be using "arrayTo string"  to place the all  content or I can walk into the array and populate help ..

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()
    Local $iI, $iTimer, $idListview

    ; Create GUI
    GUICreate("ListView Add Array", 550, 300)
    $idListview = GUICtrlCreateListView("", 2, 2, 650, 268)
    GUISetState(@SW_SHOW)

    ; Add columns
    ;_GUICtrlListView_AddColumn($idListview, "Items", 100)
    _GUICtrlListView_AddColumn($idListview, "Black Network/Modem ALU ISP", 175)
    _GUICtrlListView_AddColumn($idListview, "White Network ", 175)
    _GUICtrlListView_AddColumn($idListview, "Wireless Network ", 175)

         ;$aitems= row[0] column[1]

        $BlackNetwork_netblock="123" ;IP
        $BlackNetwork_netCE=" 124"   ;Sub
        $BlackNetwork_netPE="125"    ;Gateway
        $primaryDns = "224"          ;DNS

        ; $aitems= row[1] colum[2]

        $White_netblock="323"  ;Ip
        $White_netCE="324"     ;Sub
        $White_netPE="325"      ;gateway
        $secondaryDns = "113"   ;DNS

         ;$aitems= row[2] column[3]

        $LTE_netblock="453"   ;ip
        $LTE_netCE="454"      ;sub
        $LTE_netPE="455"      ;gateway
        $DNS = "n/a"          ;dns









    ; 3 column load  [row][column]
    Local $aItems1 [4] =["IP","SUB","Gateawy","DNS"]

    Local $aItems[4][4]
    ;_ArrayDisplay($aItems)

   For $i = 0 To UBound($aItems) - 1

     For $j = 0 To UBound($aItems1) - 1

;~       $aItems[$iI][$iJ] = $iI &"-"& $ij
      $aItems[$j][$i] = $aItems1[$j]

      ;_ArrayDisplay($aItems)
     Next
   Next








    _GUICtrlListView_AddArray($idListview, $aItems)
   ; MsgBox($MB_SYSTEMMODAL, "Information", "Load time: " & TimerDiff($iTimer) / 1000 & " seconds")

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example

 

Edited by antonioj84

Share this post


Link to post
Share on other sites

antonioj84,

Is this how you want your array to look? (run the code)

#include <array.au3>

local $aArray = [ _
        [123,124,125,224], _
        [323,324,325,113], _
        [453,454,455,'n/a'] _
                ]

_arraydisplay($aArray)

kylomas

1 person likes this

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

tHANK YOU , you just save me hours of work, I was looking at at least 30 lines of code  your solution is elegant, short and easy . I will keep that snippet in a safe place

Share this post


Link to post
Share on other sites

antonioj84,

You might want to read the help file and wiki about arrays.  What I posted is simple declaration/initialization.

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

here is the final code, it just perfect for what i wanted , of course, Thnks SO much kylomas

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <MsgBoxConstants.au3>
#include <Array.au3>




Example()

Func Example()
    Local $idListview

    ; Create GUI
    GUICreate("ListView Add Array", 550, 300)
    $idListview = GUICtrlCreateListView("", 2, 2, 650, 268)
    GUISetState(@SW_SHOW)

    ; Add columns
    ;_GUICtrlListView_AddColumn($idListview, "Items", 100)
    _GUICtrlListView_AddColumn($idListview, "Black Network/Modem ALU ISP", 175)
    _GUICtrlListView_AddColumn($idListview, "White Network ", 175)
    _GUICtrlListView_AddColumn($idListview, "Wireless Network ", 175)

         ;$aitems= row[0] column[1]

        $BlackNetwork_netblock="123" ;IP
        $BlackNetwork_netCE=" 124"   ;Sub
        $BlackNetwork_netPE="125"    ;Gateway
        $primaryDns = "224"          ;DNS

        ; $aitems= row[1] colum[2]

        $White_netblock="323"  ;Ip
        $White_netCE="324"     ;Sub
        $White_netPE="325"      ;gateway
        $secondaryDns = "113"   ;DNS

         ;$aitems= row[2] column[3]

        $LTE_netblock="453"   ;ip
        $LTE_netCE="454"      ;sub
        $LTE_netPE="455"      ;gateway
        $DNS = "n/a"          ;dns



local $aItems = [ _
        ["IP:"&123,323,453], _
        ["SUB:"&124,324,454], _
        ["Gateawy:"&125,325,455], _
        ["DNS:"&224,113,'n/a'] _
                ]



    _GUICtrlListView_AddArray($idListview, $aItems)
   ; MsgBox($MB_SYSTEMMODAL, "Information", "Load time: " & TimerDiff($iTimer) / 1000 & " seconds")

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example

I will substitute the variable name

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

i will spend sometimes, this week in checking out arrays  in the wiki in help file

Edited by antonioj84

Share this post


Link to post
Share on other sites

antonioj84,

Glad you got it working.  Two points:

1 - By itself the code is pretty much useless except to display some info

2 - labeling cell data within the cell is a bad idea for several reasons.

Additions/changes in code below:

1 - Added dummy control and notification routine to retrieve lv data on DBL-click.

2 -  listview rearranged to reflect an x,y table.

3 - Eliminated unused declarations.

4 - eliminated calling the main prog from a function (make life easier in the notification routine).

5 - added var to guicreate function.

6 - changed message loop to process messages.

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <MsgBoxConstants.au3>
#include <Array.au3>
#include <WindowsConstants.au3>

Local $idListview

; Create GUI
Local $hgui = GUICreate("ListView Add Array", 550, 300)
$idListview = GUICtrlCreateListView("", 2, 2, 650, 268)

; ctlid actioned by lv notification routine
Local $lv_Dummy = GUICtrlCreateDummy()
GUISetState(@SW_SHOW)

; routine to run for lv notification messages
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

; Add columns
_GUICtrlListView_AddColumn($idListview, "Network", 100)
_GUICtrlListView_AddColumn($idListview, "IP", 100)
_GUICtrlListView_AddColumn($idListview, "Sub ", 100)
_GUICtrlListView_AddColumn($idListview, "Gateway ", 100)
_GUICtrlListView_AddColumn($idListview, "DNS ", 100)

Local $aItems = [ _
        ['Black Network', 123, 323, 453, 001], _
        ['White Netblock', 124, 324, 454, 999], _
        ['LTE Netblock', 125, 325, 455, 'N/A'] _
        ]

_GUICtrlListView_AddArray($idListview, $aItems)

; Loop until the user exits.

Local $msg
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $lv_Dummy
            MsgBox(0, '', _GUICtrlListView_GetItemTextString($idListview, -1), 5, $hgui)
    EndSwitch
WEnd

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)

    Local $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)

    Switch $tNMHDR.IDFrom
        Case $idListview
            Switch $tNMHDR.Code
                Case $nm_dblclk
                    GUICtrlSendToDummy($lv_Dummy)
            EndSwitch
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

I understand that you are new and working from examples, however, take the code apart piece by piece and it will start to make sense.

Good Luck,

kylomas

 

 

 

 

 

1 person likes this

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

GETTing error with your code

ARRAYCapture.JPG

Share this post


Link to post
Share on other sites

Are you sure you copied it correctly?  Post exactly what you ran...


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

try it like this

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <MsgBoxConstants.au3>
#include <Array.au3>
#include <WindowsConstants.au3>

Local $idListview

; Create GUI
Local $hgui = GUICreate("ListView Add Array", 550, 300)
$idListview = GUICtrlCreateListView("", 2, 2, 650, 268)

; ctlid actioned by lv notification routine
Local $lv_Dummy = GUICtrlCreateDummy()

GUISetState(@SW_SHOW)

; routine to run for lv notification messages
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

; Add columns
_GUICtrlListView_AddColumn($idListview, "Network", 100)
_GUICtrlListView_AddColumn($idListview, "IP", 100)
_GUICtrlListView_AddColumn($idListview, "Sub ", 100)
_GUICtrlListView_AddColumn($idListview, "Gateway ", 100)
_GUICtrlListView_AddColumn($idListview, "DNS ", 100)

Local $aItems = [ _
        ['Black Network', 123, 323, 453, 001], _
        ['White Netblock', 124, 324, 454, 999], _
        ['LTE Netblock', 125, 325, 455, 'N/A'] _
        ]

_GUICtrlListView_AddArray($idListview, $aItems)

; Loop until the user exits.

Local $msg
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $lv_Dummy
            MsgBox(0, '', _GUICtrlListView_GetItemTextString($idListview, -1), 5, $hgui)
    EndSwitch
WEnd

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)

    #forceref $hWnd, $iMsg, $iwParam, $ilParam

    Local $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)

    Switch $tNMHDR.IDFrom
        Case $idListview
            Switch $tNMHDR.Code
                Case $nm_dblclk
                    GUICtrlSendToDummy($lv_Dummy)
            EndSwitch
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

 

1 person likes this

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

work like a charm

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