Jump to content

1D to 2D Array Issues


 Share

Recommended Posts

 

would a map function like an array? I ask because the test program is universal, so the switch names arent always the same and the number of switches varies. So the "Show Stat" button / array captures the names and the positions. I would need the map to also do that. 

nvm....I see that maps are in the beta only. I need the scripts to be stable so I only use the release versions....:(

 

Edited by Fractured
Link to comment
Share on other sites

It's not the darkest of magic.  It's just instead of needing to search the array for the match in col[0] so you can change the corresponding value in col[1],  you can store and retrieve things by name.

The ini functions are a little bit better documented and would serve the same purpose.

Edited by iamtheky

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

Link to comment
Share on other sites

I toyed with the ini idea but I would like the script to be somewhat self contained since it will be on 4 different machines that are of varying ages...Ive had to tweak the scripts depending on OS version (all windows flavors) and speeds going back to Pentium II...:'(  My company doesn't believe in upgrading anything!! Timeouts during communication with the boxes is a big pain!! 

So now I just need to figure out how to pass the info from the array back to the core program and access it from other functions...back to the wiki!!! 

 

Link to comment
Share on other sites

If you're looking for a really fast way, easy to use and working on all Windows versions, as any element in col[0] is unique you might try Scripting.Dictionary
Example below  :)

#include <Array.au3>

$str = "route: 0100" & @CRLF & _
                    "S1: 1" & @CRLF & _
                    @CRLF & _
                    @CRLF & _
                    "J13P1 out (HF_AMP): 1"
$res = StringRegExp($str, '(?m)(^.+):\h(.+$)', 3)
; _ArrayDisplay($res)

; create the dictionary
$sd = ObjCreate("Scripting.Dictionary")
; populate it
For $i = 0 To UBound($res) - 1 step 2
   $sd.add($res[$i], $res[$i+1])
Next
; visualize it
$array = _list($sd)
_ArrayDisplay($array)

; change the value for "S1" ...
$sd.item("S1") = 3
; ... and visualize the result
$array = _list($sd)
_ArrayDisplay($array)


Func _list($sd)
    Local $keys = $sd.Keys, $items = $sd.Items, $count = $sd.Count, $ret[$count][2] 
    For $i = 0 To $count-1
        $ret[$i][0] = $keys[$i]
        $ret[$i][1] = $items[$i]
    Next
    Return $ret
EndFunc

 

Link to comment
Share on other sites

@mikell - Looking at the script, would this only work if you knew $str? I only ask because $str values are not standard across the units I test. I only get those values from the  RecieveString returned from the unit as $sResult. I have to do this so that I get all device settings in the unit...i.e. attenuator values, switch settings, amp states, etc.....

Link to comment
Share on other sites

Can you provide a few actual examples of $sResult?   If by 'not standard' you mean 'colon wont always separate the key from the value', then you may have issues.

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

Link to comment
Share on other sites

Example....so say unit A has 4 switches, and 6 attenuators....the "Show Stat" command returns SW1 1, SW2 1, SW3 1, SW4 1, ATTN1 95.5, ATTN2 65.5,ETC....

Unit B might only have 5 switches - SW1 through SW5

The separator is always the same, but the information recieved is different per unit. Thats why I was trying to use an Array with variable amount of rows....The columns will always be component "name"  and then component "value". 

If need be ill try and post the $sResult for various units but testing is pretty heavy today.

 

Link to comment
Share on other sites

Then scripting dictionary would work just fine, and you can even wrap those in map-like functions if you wish to avoid the beta (though i disagree that the resulting scripts are unstable).  

Some nutter lost his wits a few years ago and started digging that rabbit hole.

 

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

Link to comment
Share on other sites

nice....now to figure out how to use it!! LOL! Possibly after lunch...(10:08am here)..The script I posted early on is just a test script to get the function working.  Once its working it will be added to my Test Functions UDF im building to make current and future test scripts closer to "plug and play".

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...