pongmaster21 Posted February 9, 2011 Posted February 9, 2011 In the following script I would like to pull just the zero row and column but it defaults to displaying all. Using "_ArrayToString($avArray, " ", 1, 1)" works great if you only want row one and column one. How can I get only row and column zero? #include <Array.au3> Dim $avArray[20] ; Populate test array. For $i = 0 to UBound( $avArray ) - 1 $avArray[$i] = Random( 100, 200, 1) Next _ArrayDisplay($avArray, "$avArray") MsgBox(0, "_ArrayToString() getting items", _ArrayToString($avArray, " ", 0, 0))
enaiman Posted February 9, 2011 Posted February 9, 2011 - "zero row and column" ... why not use $avArray[0] ? SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :)
Varian Posted February 10, 2011 Posted February 10, 2011 The problem is that the start and end values are zero by default. when you pass 0's to the parameters, you are sending the defaults. The only thing I can suggest is to raise the element in 0 by using _ArrayPush($avArray, "", 1) and then reading element 1 _ArrayToString($avArray, "", 1, 1)
Malkey Posted February 10, 2011 Posted February 10, 2011 Because _ArrayToString($avArray, " ", 1, 1) = $avArray[1], logically, _ArrayToString($avArray, " ", 0, 0) should equal $avArray[0]. By modifying the function _ArrayToString from the #include <Array.au3> file, logic will prevail. #include <Array.au3> Dim $avArray[20] ; Populate test array. For $i = 0 To UBound($avArray) - 1 $avArray[$i] = Random(100, 200, 1) Next _ArrayDisplay($avArray, "$avArray") MsgBox(0, "_ArrayToString() getting items", _ "$avArray[0]: " & __ArrayToString($avArray, " ", 0, 0) & " = " & $avArray[0] & @CRLF & _ "$avArray[1]: " & __ArrayToString($avArray, " ", 1, 1) & " = " & $avArray[1]) ; Copied from #include <Array.au3> and modified, and renamed with 2 pre underscores. Func __ArrayToString(Const ByRef $avArray, $sDelim = "|", $iStart = 0, $iEnd = 0) If Not IsArray($avArray) Then Return SetError(1, 0, "") If UBound($avArray, 0) <> 1 Then Return SetError(3, 0, "") Local $sResult, $iUBound = UBound($avArray) - 1 ; Bounds checking ;If $iEnd < 1 Or $iEnd > $iUBound Then $iEnd = $iUBound ; Original line in UDF. If $iEnd < 0 Or $iEnd > $iUBound Then $iEnd = $iUBound ; Above line changed to. If $iStart < 0 Then $iStart = 0 If $iStart > $iEnd Then Return SetError(2, 0, "") ; Combine For $i = $iStart To $iEnd $sResult &= $avArray[$i] & $sDelim Next Return StringTrimRight($sResult, StringLen($sDelim)) EndFunc ;==>__ArrayToString
enaiman Posted February 10, 2011 Posted February 10, 2011 Why in the world would somebody want to use _ArrayToString just to get the value for a single element? "row zero and column zero" means only one element for God's sake. You want to modify the above function to return that cell value? Be my guest; just don't forget to write a 50 lines script to calculate how much "1+1" is. Really guys - this is a help request not a challenge. SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :)
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now