Sign in to follow this  
Followers 0
cowsmanaut

iterating through labels to read each

10 posts in this topic

I've got a bunch of labels ranged in order like this:

$dig1 = GuiCtrlCreateLabel("digi01", 30, 20, 231, 21, 0x1000)
$dig2 = GuiCtrlCreateLabel("digi02", 30, 40, 231, 21, 0x1000)
$dig3 = GuiCtrlCreateLabel("digi03", 30, 60, 231, 21, 0x1000)
$dig4 = GuiCtrlCreateLabel("digi04", 30, 80, 231, 21, 0x1000)
$dig5 = GuiCtrlCreateLabel("digi05", 30, 100, 231, 21, 0x1000)
$dig6 = GuiCtrlCreateLabel("digi06", 30, 120, 231, 21, 0x1000)

etc etc

what I want is to be able to read though each and update them one at a time with the IP as it performs it's tasks. So, I tried to do this.

$a = 0
    while $a < 24
        $a = $a + 1
        
        $data = GUICtrlRead("$dig" & $a)
        WEnd

in hopes I could use that to create $dig1, $dig2, $dig3 etc up to $dig24 and then stop reading. However, it seems unsuccessfull.

I'm not even sure what to search for :S

perhaps someone has a hint? or and idea? I didn't see any "read all controls" command.. then again I could be blind.

any help would be greatly apreciated.

moo

Share this post


Link to post
Share on other sites



just so you know.. there is a funtion going on in the loop using $data.. just it's not relevant to the question

Share this post


Link to post
Share on other sites

You could use Eval(), but I don't recommend it.

Your best bet is to declare $dig as an array.


[font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font]

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

You could use Eval(), but I don't recommend it.

Your best bet is to declare $dig as an array.

Eval()... you have gained my highest thanks... I was banging my head against the floor.

and you have a castlevania user icon.. which makes it even more cool :D

cheers

for anyone else.. this is what I did with it as a test

$data1 = "kitten"
$data2 = "puppy"
$data3 = "vorgon"
$a_b = 12
$var =0

while $var < 4
    $var = $var + 1

$say = Eval("data" & $var )  

MsgBox ( 4096 ,"title", $say , )

WEnd
Edited by cowsmanaut

Share this post


Link to post
Share on other sites

$data1 = "kitten"
$data2 = "puppy"
$data3 = "vorgon"
$a_b = 12
$var =0

while $var < 4
    $var = $var + 1

$say = Eval("data" & $var )  

MsgBox ( 4096 ,"title", $say , )

WEnd

$var =0
MsgBox ( 4096 ,"title", "change" , )

while $var < 4
    $var = $var + 1

Eval("data" & $var )  = "cow"

MsgBox ( 4096 ,"title", $say , )

WEnd

I guess this is where it goes wrong.. :S

I suppose I could change all those variables with an array?

now I need to read more about arrays.. I know how to use them for strings.. but how do I read that string as variables instead of text??!

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I need to read more about arrays.. I know how to use them for strings.. but how do I read that string as variables instead of text??!

Best not to deal with them as strings...
Dim $data[3]; Make a 3-element array
$data[0] = "kitten"
$data[1] = "puppy"
$data[2] = "vorgon"
$a_b = 12
$var = 0

; Display original array
For $var = 0 To UBound($data) -1
    $say = $data[$var]
    MsgBox(4096, "title" & $var, $say)
Next

MsgBox(4096, "title", "change")

; Set each element in the array to "cow"
For $var = 0 To UBound($data) -1
    $data[$var] = "cow"
    MsgBox(4096, "title" & $var, $data[$var])
Next
There are plenty of useful array functions, but this script doesn't require them.

In this example, UBound returns 3, but we subtract one because arrays are zero-based. (0,1,2 instead of 1,2,3)

btw- $a_b isn't being used...

Edit: Are AutoIt tags working again?

Edited by Skruge

[font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font]

Share this post


Link to post
Share on other sites

There are plenty of useful array functions, but this script doesn't require them.

In this example, UBound returns 3, but we subtract one because arrays are zero-based. (0,1,2 instead of 1,2,3)

btw- $a_b isn't being used...

Edit: Are AutoIt tags working again?

I noticed the Autoit tags not working a few times too.. but yes.. they seem to be.

thanks very much.

As for the $a_b not being used it's because I tested the provided help file script and then made it into something different to try to understand it better and forgot to delete that value. :D

Share this post


Link to post
Share on other sites

I noticed the Autoit tags not working a few times too.. but yes.. they seem to be.

thanks very much.

As for the $a_b not being used it's because I tested the provided help file script and then made it into something different to try to understand it better and forgot to delete that value. :D

Here's a technique for doing it with arrays:

#include <array.au3>

Dim $DigCtrl[1]
_ArrayAdd($DigCtrl, GUICtrlCreateLabel("digi01", 30, 20, 231, 21, 0x1000))
_ArrayAdd($DigCtrl, GUICtrlCreateLabel("digi02", 30, 40, 231, 21, 0x1000))
_ArrayAdd($DigCtrl, GUICtrlCreateLabel("digi03", 30, 60, 231, 21, 0x1000))
_ArrayAdd($DigCtrl, GUICtrlCreateLabel("digi04", 30, 80, 231, 21, 0x1000))
_ArrayAdd($DigCtrl, GUICtrlCreateLabel("digi05", 30, 100, 231, 21, 0x1000))
_ArrayAdd($DigCtrl, GUICtrlCreateLabel("digi06", 30, 120, 231, 21, 0x1000))
$DigCtrl[0] = UBound($DigCtrl) - 1

Dim $DigData[$DigCtrl[0] + 1]
$DigData[0] = $DigCtrl[0]

For $d = 1 To $DigCtrl[0]
    $DigData[$d] = GUICtrlRead($DigCtrl[$d])
Next

You can insert as many of those _ArrayAdd() lines as you want and the array indexes will work themselves out automaticaly.

:D


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

why is it this works

(see changed lines highlighted by "********")

#include <array.au3>

Dim $DigCtrl[1]
_ArrayAdd($DigCtrl, "digi01")
_ArrayAdd($DigCtrl, "digi02")
_ArrayAdd($DigCtrl, "digi03")
_ArrayAdd($DigCtrl, "digi04")
_ArrayAdd($DigCtrl, "digi05")
_ArrayAdd($DigCtrl, "digi06")
$DigCtrl[0] = UBound($DigCtrl) - 1

Dim $DigData[$DigCtrl[0] + 1]
$DigData[0] = $DigCtrl[0]

; Display original array
For $var = 1 To UBound($DigCtrl) -1
    $data = $DigCtrl[$var]
    
            ;send ipconfig request to selected computer
            Run(@ComSpec & ' /c c:\au3_tool\psexec \\' & $data & ' -u Administrator -p bu330ff ipconfig /all > c:/ip.txt', '', @SW_HIDE)
            
            $say = ipget () ;********* change
            
Next

func ipget()
        ;open the file   
        $file = FileOpen("c:/ip.txt", 0)

            ; Check if file opened for reading OK
            If $file = -1 Then
                MsgBox(0, "Error", "Unable to open file.")
                Exit
            EndIf

            ; Read in lines 34 and 40

            $vara = FileReadLine($file, 34)
            If @error = -1 Then $vara = ": unknown" 
            $varb = FileReadLine($file, 40)
            If @error = -1 Then $varb = ": unknown" 
            
                $chara = StringRight($vara, 20)
                $charb = StringRight($varb, 14)
        
        MsgBox(0, $data, $data & " information:" & @cr  & @cr  & $chara & @cr & $charb) ;********* change
        
        FileClose($file)
        
        
    EndFunc
oÝ÷ ٩ݶ¬v¬ZºÚ"µÍÚ[ÛYH    Ø^K]LÉÝÂ[H  ÌÍÑYÐÝÌWBÐ^PY
    ÌÍÑYÐÝ ][ÝÙYÚLI][ÝÊBÐ^PY
    ÌÍÑYÐÝ ][ÝÙYÚL][ÝÊBÐ^PY
    ÌÍÑYÐÝ ][ÝÙYÚLÉ][ÝÊBÐ^PY
    ÌÍÑYÐÝ ][ÝÙYÚL
    ][ÝÊBÐ^PY
    ÌÍÑYÐÝ ][ÝÙYÚL
I][ÝÊBÐ^PY
    ÌÍÑYÐÝ ][ÝÙYÚL
][ÝÊBÌÍÑYÐÝÌHHPÝ[
    ÌÍÑYÐÝ
HHB[H   ÌÍÑYÑ]VÉÌÍÑYÐÝÌH
ÈWBÌÍÑYÑ]VÌHH ÌÍÑYÐÝÌBÈÜ^HÜYÚ[[^BÜ ÌÍÝHHÈPÝ[
    ÌÍÑYÐÝ
HLB ÌÍÙ]HH   ÌÍÑYÐÝÉÌÍÝBBBBNÜÙ[ÛÛYÈ]YÝÈÙ[XÝYÛÛ]BBT[ÛÛTÜXÈ    [È ÌÎNÈØÈÎÌLØ]L×ÝÛÛ    ÌLÜÙ^XÈ ÌLÉÌLÉÌÎNÈ   [È ÌÍÙ]H    [È ÌÎNÈ]HYZ[Ý]ÜLÌÌÛÛYÈØ[    ÝÈÎÚ    ÌÎNË ÌÎNÉÌÎNËÕ×ÒQJBBBBBBÙÐÞ

MK  ÌÍÙ]HÙ]

H
HÊÚ[ÙB^[ÈÙ]

BBNÛÜ[H[HBIÌÍÙ[HH[SÜ[ ][ÝØÎÚ  ][ÝË
BBBNÈÚXÚÈY[HÜ[YÜXY[ÈÒÂBBRY ÌÍÙ[HHLH[BBBSÙÐÞ
    ][ÝÑÜ][ÝË  ][ÝÕ[XHÈÜ[[K][ÝÊBBBBQ^]BBQ[YBBNÈXY[[ÈÍ[
BBIÌÍÝHH[TXY[J   ÌÍÙ[KÍ
BBBRYÜHLH[ ÌÍÝHH    ][ÝÎ[ÛÝÛ][ÝÂBBBIÌÍÝH[TXY[J    ÌÍÙ[K

BBBRYÜHLH[ ÌÍÝH ][ÝÎ[ÛÝÛ][ÝÂBBBBBBBIÌÍØÚHHÝ[ÔYÚ
    ÌÍÝK
BBBBIÌÍØÚHÝ[ÔYÚ
    ÌÍÝM
BBBBQ[PÛÜÙJ  ÌÍÙ[JBBBBT]
    ÌÍØÚH   [ÈÜ   [È ÌÍØÚHÊÚ[ÙBBBQ[[Â

the second one here just blinks and sends no message box at all. From the examples I've been reading it seems like the second should be correct using "return" to send back the information.

Share this post


Link to post
Share on other sites

answer? because I'm stupid and put 4095 for the message box instead of 0

gah

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