Sign in to follow this  
Followers 0
gerpion73

Array not working

6 posts in this topic

Hello, i'm new to Autoit and trying to do some small things.

I'm getting some trouble while playing with Array. Here is my code.

; Include Files
#include <file.au3>
#include <GUIConstants.au3>
#include <GUIComboBox.au3>

; Déclaration des variables
Dim $aRecords,$tab[255][255]
Dim $x,$y
Dim $choix

; Programme
; Creation de l'interface graphique

$mainwindow = GUICreate("Adresse IP / Machine", 400, 150)
$hComboIP = _GUICtrlComboBox_Create($mainwindow,"",20,20,150,300)
$hComboMACHINE = _GUICtrlComboBox_Create($mainwindow,"",190,20,150,300)
$okbutton = GUICtrlCreateButton("OK", 70, 50, 60)

If Not _FileReadToArray("ip.log",$aRecords) Then
   MsgBox(4096,"Erreur", " Erreur:" & @error)
   Exit
EndIf
For $x = 1 to $aRecords[0]-1 step 3
    _GUICtrlComboBox_AddString ($hComboIP, $aRecords[$x])
    for $y = 0 to 2
        $tab[$x][$y+1] = $aRecords[$x+$y]
    next
        
Next
GUISwitch($mainwindow)
GUISetState(@SW_SHOW)

        MsgBox(1, "Information", "Cur Sel: " & $tab[2][2])

; Loop d'affichage

While 1
  $msg = GUIGetMsg(1)

  Select
    Case $msg[0] = $okbutton
    $choix= _GUICtrlComboBox_GetCurSel ($hComboIP)
    if $choix=-1 then
        msgBox(4160,"Erreur","Choisissez une adresse IP")
    else
        MsgBox(4160, "Information", "Cur Sel: " & $choix+1)
    endif

    Case $msg[0] = $GUI_EVENT_CLOSE And $msg[1] = $mainwindow 
      ExitLoop
  EndSelect
WEnd

the line : MsgBox(1, "Information", "Cur Sel: " & $tab[2][2])

doesnt work as i expect, it doesnt print the content of $tab[2][2]

Anyone can enlight me about the use of arrays ?

Thanks

Share this post


Link to post
Share on other sites



what is the content of IP.LOG ?

cannot see whats happening without it ...

The content of the log file is something like this :

10.1.1.1

PC01

USER1

10.1.1.2

PC02

USER2

so i'm doing an array like this :

$tab[1][1]=10.1.1.1

$tab[1][2]=PC01

$tab[1][3]=USER1

$tab[2][1]=10.1.1.2

$tab[2][2]=PC02

$tab[2][3]=USER2

Share this post


Link to post
Share on other sites

Perhaps it's because of this:

for $y = 0 to 2
        $tab[$x][$y+1] = $aRecords[$x+$y]
    next

Add this line after GuiSetState(@Sw_Show)

_ArrayDisplay($tab)

And you'll see what's wrong with your array. What exactly are you trying to do?

Share this post


Link to post
Share on other sites

$x steps from 1,4,7 etc so thats where your problem is.

try something like:

$Acount = 0
For $x = 1 To $aRecords[0] - 1 Step 3
    _GUICtrlComboBox_AddString($hComboIP, $aRecords[$x])
    $Acount += 1
    For $y = 0 To 2
        $tab[$Acount][$y + 1] = $aRecords[$x + $y]
    Next
Next

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

$x steps from 1,4,7 etc so thats where your problem is.

try something like:

$Acount = 0
For $x = 1 To $aRecords[0] - 1 Step 3
    _GUICtrlComboBox_AddString($hComboIP, $aRecords[$x])
    $Acount += 1
    For $y = 0 To 2
        $tab[$Acount][$y + 1] = $aRecords[$x + $y]
    Next
Next
Thanks for the anwser.

I took some time to write down the algothim and found where i was wrong.

Here is the final code :

For $x = 1 to ($aRecords[0]-1)/3
; _GUICtrlComboBox_AddString ($hComboIP, $aRecords[$x])
    for $y = 0 to 2
        $z=$z+1
        $tab[$x][$y+1] = $aRecords[$z]
    next
        
Next

Thanks for your help.

I'm using a counter ($z)

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
Sign in to follow this  
Followers 0