Sign in to follow this  
Followers 0
chachew

Add variable to 2d array inside FOR loop

5 posts in this topic

#1 ·  Posted (edited)

I have an array that is populated from a ListView so the array changes size/values every 8 seconds. There is one column that i am wanting to change every time the 8 second loop runs and reads the ListView. The column i am wanting to change is column 0 of each row, it is a 24hr time. I am reading those columns, using the StringSplit to isolate the HOUR and convert it to 12hr format and then save that into a new variable. All this i have successfully done, with the exception of getting that new variable back into the existing array.

Code snippits below:

For $r = 0 To $iRow - 1
    For $c = 0 To UBound($array, 2) - 1  ; Enter each and every column, $c, on the row, $r.
        $array[$r][$c] = ControlListView("CallStatus","",3,"GetText", $r, $c)
    Next
Next
For $row=0 To UBound($array,1) - 1
_TimeAdjust()
 
Next
 
Func _TimeAdjust()
For $i = 0 to UBound ($array,1) - 1
$split=StringSplit($array[$row][0],":")
If $split[1]> 12 Then $newTime=$split[1]-12 & ":" & $split[2]
Next
;~MsgBox(0,"",$newTime)
EndFunc

So i am now needing to get $newTime back into the array, something like this.... $array[$newTime][0] for each row in the existing array. Any suggestions?

Edited by chachew

Share this post


Link to post
Share on other sites



Try this way:

Func _TimeAdjust()
 For $i = 0 to UBound ($array,1) - 1
  $split=StringSplit($array[$row][0],":")
  If $split[1]> 12 Then
   $array[$row][0]=$split[1]-12 & ":" & $split[2]
  EndIf
 Next
;~MsgBox(0,"",$newTime)
EndFunc

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 :)

Share this post


Link to post
Share on other sites

Try this way:

Func _TimeAdjust()
For $i = 0 to UBound ($array,1) - 1
  $split=StringSplit($array[$row][0],":")
  If $split[1]> 12 Then
   $array[$row][0]=$split[1]-12 & ":" & $split[2]
  EndIf
Next
;~MsgBox(0,"",$newTime)
EndFunc

Worked perfectly enaiman, THANKS

Share this post


Link to post
Share on other sites

One last question, i modified Func _TimeAdjust() slightly to add "am" and "pm" to the end of the string but i have a problem appending "am". Since the function subtracts 12 from the 24hr formatted numbers the function thinks that 3:00pm is in the "am" so it turns out as 3:00pmam

What am i missing?

Func _TimeAdjust()
For $i = 0 to UBound($array,1) - 1
$split=StringSplit($array[$row][0],":")
If $split[1]>= 12 Then $array[$row][0]=$split[1]-12 & ":" & $split[2] & "pm"
Next
If $array[$row][0] <> $array[$row][0] & "pm" Then $array[$row][0]&= "am"
EndFunc

Share this post


Link to post
Share on other sites

Think a little bit about this:

$array[$row][0] <> $array[$row][0] & "pm"

....

:graduated:


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 :)

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