Jump to content

[Resolved]: Array help


Recommended Posts

I'm making a program, and I need some help with some array questions. I'm sorry I know I've seen these somewhere before, but I can't think of what to search for.

1) My array will be all 1's and 0's. But I need to delete all 1's up to the first 0. And if possible move all following elements up in rank. If that's as confusing as it sounds to me here's and example: If first 0 = $array[7] I would like it to become $array[1] and move all the following digits up as well.

2) For testing purposes, I would like to have a message box that lists all the $array values The problem is 1. it will be over 1000 long if I'm not mistaken, and the final number isn't set in stone (aka it will very)

3)Now this one I don't believe I've ever seen, but I would like to group the sets as well. For example, if $array[1] thru [5] = 0 then $0array[1] = 5 and so on.

I would probably know these by now if I didn't have work to do the last month or so :-P Thanks for any help.

Edited by youknowwho4eva

Giggity

Link to comment
Share on other sites

what about this:

for $i=0 to Ubound($array)-1 step 1
if($array[$i]=0) Then
move($i,$array)
exitloop
endif
next

func move($start,$array)

for $i=0 to Ubound($array)-$start-1 step 1     
$array[i]=$array[$start+$i]
endfunc

im not 100% sure about the range you need to loop through in the move function . probably something like i stated here tho. just test.

its probably not 100% working but its a good pointer into the right direction i hope.

for the arraydisplay:

#include <Array.au3>

_ArrayDisplay()

Parameters:

$avArray Array to display 
$sTitle [optional] Title to use for window 
$iItemLimit [optional] Maximum number of listview items (rows) to show 
$iTranspose [optional] If set differently than default, will transpose the array if 2D 
$sSeparator [optional] Change Opt("GUIDataSeparatorChar") on-the-fly 
$sReplace [optional] String to replace any occurrence of $sSeparator with in each array element

all this information is in the helpfile too.

Edited by cageman
Link to comment
Share on other sites

Ok, this is what I have so far, and I'm stuck. I have it so it trims to the first 0. I can't figure out how to get it to trim to the last 0. I've tried everything I can think of or find. This is just my latest attempt.

#include <misc.au3>
#include <array.au3>
Global $color[100000]
Dim $bar[10000]
$dll = DllOpen("user32.dll")
$start = 0
While 1
    If $start = 0 and _IsPressed("01",$dll) = 1 Then
        $mouse = MouseGetPos()
        $start = 1
        Sleep(2000)
    Elseif $start = 1 and _IsPressed("01",$dll) = 1 Then
        $mouse2 = MouseGetPos()
        $start = 0
        For $n = 1 to ($mouse2[0] - $mouse[0]) + 1
        $color = PixelGetColor($mouse[0] + $n,$mouse[1])
        If $color = 0 Then 
            $bar[$n] = 0
        Else
            $bar[$n] = 1
        EndIf
        
        
    Next
    $bar[0] = $n
    For $i = 1 to $bar[0]
        if $bar[1] <> 0 Then
            _ArrayDelete($bar,1)
        Else
            ExitLoop
        EndIf
    Next
    $r = $bar[0]
    $bar[0] = $r - $i
    $bar2 = _ArrayToString($bar)
    $count = StringLeft($bar2, StringInStr($bar2,0,Default,-1)-1)
    $bar = StringSplit($bar2,"|")
    _ArrayTrim($bar, $count,1)
    MsgBox(0,"",$bar[0])
    
        If $bar[1] = 0 And $bar[2] = 0 And $bar[3] = 0 And $bar[4] = 1 And $bar[5] = 1 And $bar[6] = 1 And $bar[7] = 0 And $bar[8] = 0 And $bar[9] = 0 Then
        Else
            MsgBox(0,"","Read Error")
        EndIf
        
    _ArrayDisplay($bar,"",$bar[0])
EndIf
WEnd

Here's the part I'm stuck on.

$bar2 = _ArrayToString($bar)
    $count = StringLeft($bar2, StringInStr($bar2,0,Default,-1)-1)
    $bar = StringSplit($bar2,"|")
    _ArrayTrim($bar, $count,1)

I've tried reversing the array and repeating the steps that I did to get to the first 0 but that didn't work. Any help would be greatly appreciated.

Edited by youknowwho4eva

Giggity

Link to comment
Share on other sites

Solution

#include <misc.au3>
#include <array.au3>
Global $color[100000]
Dim $bar[1000]
$dll = DllOpen("user32.dll")
$start = 0
While 1
    If $start = 0 and _IsPressed("01",$dll) = 1 Then
        $mouse = MouseGetPos()
        $start = 1
        Sleep(2000)
    Elseif $start = 1 and _IsPressed("01",$dll) = 1 Then
        $mouse2 = MouseGetPos()
        $start = 0
        For $n = 1 to ($mouse2[0] - $mouse[0]) + 1
        $color = PixelGetColor($mouse[0] + $n,$mouse[1])
        If $color = 0 Then 
            $bar[$n] = 0
        Else
            $bar[$n] = 1
        EndIf
        
        
    Next
    $bar[0] = $n
    For $i = 1 to $bar[0]
        if $bar[1] <> "0" Then
            _ArrayDelete($bar,1)
        Else
            ExitLoop
        EndIf
    Next
    _ArrayDisplay($bar,"",$bar[0])
    _ArrayReverse($bar)
    _ArrayDisplay($bar,"",$bar[0])
    For $i = 0 to 1000
        if $bar[0] <> "0" Then
            _ArrayDelete($bar,0)
        Else
            ExitLoop
        EndIf
    Next
    _ArrayReverse($bar)
    
        If $bar[1] = 0 And $bar[2] = 0 And $bar[3] = 0 And $bar[4] = 1 And $bar[5] = 1 And $bar[6] = 1 And $bar[7] = 0 And $bar[8] = 0 And $bar[9] = 0 Then
        Else
            MsgBox(0,"","Read Error")
        EndIf
        
    _ArrayDisplay($bar)
EndIf
WEnd

Giggity

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