Jump to content
Sign in to follow this  
Kovitt

StringRegExp to Array Problem

Recommended Posts

Kovitt

Does anyone see anything wrong with the following? I can't figure it out.

$path = "RollupJobs.txt"
        $test = _FileReadToArray($path,$jobs)
      
       For $x=0 to Ubound($jobs) - 1
                    ;------------------------------------------------------------------------------------
        ;       Pulls CE_ID and Instance from TB_Board_Msg output
        ;------------------------------------------------------------------------------------
        $CEID_Instance = StringRegExp($jobs, '([:space]{1,})([:digit]{1,})([:space]{2,})([:digit]{1,}?:)',1) 
        ;----------------------------My attempt at StringRegExp------------------------------
        ;StringRegExp($jobs,'([0-9]{1,2},[ ]{1,}?:) ([0-9]{1,9},[ ]{2,}?:)',1)
        ;------------------------------------------------------------------------------------------
            MsgBox(0,"@error", @error);Keeps giving me a 1
            
            
            If @error = 0 then
            MsgBox(0,"test",$CEID_Instance[0])
            MsgBox(0,"test",$CEID_Instance[1])
            $ce_id[$x] = $CEID_Instance[0] 
            $instance[$x] = $CEID_Instance[1]
            EndIf
            
        Next
        _ArrayDisplay($ce_id, "CE_IDs")
        _ArrayDisplay($instance, "Instances")

The contents of rollupjobs.txt look similar to:

CE_ID Instances of CE_ID

---------- ------------------

14001 16

19604 2

12505 2

12007 7

12108 2

20009 2

19633 4

18734 9

12893 11

12685 9

13596 4

CE_ID Instances of CE_ID

---------- ------------------

11564 2

18985 4

11435 20

18515 9

15465 9

18645 9

18646 9

14685 9

15632 9

15641 9

15615 9

Thanks for the help!

Edited by Kovitt

Share this post


Link to post
Share on other sites
zorphnog

For one, you're not sending an element of the array, but the whole array to StringRegExp. Second, your MsgBox is reseting the @error flag. Anyway, try this:

Dim $jobs
$path = "RollupJobs.txt"
$test = _FileReadToArray($path,$jobs)
$size = UBound($jobs) - 1
Dim  $ce_id[$size][2]
$count = 0

For $x=1 to $size
    $CEID_Instance = StringRegExp($jobs[$x], '(\d+)\s(\d+)',3)
      
    If @error = 0 then
        $ce_id[$count][0] = $CEID_Instance[0]
        $ce_id[$count][1] = $CEID_Instance[1]
        $count += 1
    EndIf
   
Next
ReDim $ce_id[$count][2]
_ArrayDisplay($ce_id, "CE_IDs")
Edited by zorphnog

Share this post


Link to post
Share on other sites
Kovitt

For one, you're not sending an element of the array, but the whole array to StringRegExp. Second, your MsgBox is reseting the @error flag. Anyway, try this:

Dim $jobs
$path = "RollupJobs.txt"
$test = _FileReadToArray($path,$jobs)
$size = UBound($jobs) - 1
Dim  $ce_id[$size][2]
$count = 0

For $x=1 to $size
    $CEID_Instance = StringRegExp($jobs[$x], '(\d+)\s(\d+)',3)
      
    If @error = 0 then
        $ce_id[$count][0] = $CEID_Instance[0]
        $ce_id[$count][1] = $CEID_Instance[1]
        $count += 1
    EndIf
   
Next
ReDim $ce_id[$count][2]
_ArrayDisplay($ce_id, "CE_IDs")
Wow, looks like it will do the trick.. Just one thing.

I put this in my code and its saying that:

CODE

C:\Documents and Settings\******\My Documents\scripts\Job_Watch\Job_Watch.au3 (70) : ==> Array variable subscript badly formatted.:

ReDim $ce_id[$count][2]

ReDim $ce_id[^ ERROR

Do you by any chance know why this is?

Thanks sooo much for helping me!! I think you have helped in everysingle one of my posts!

Edit: Due to Typos...

Edited by Kovitt

Share this post


Link to post
Share on other sites
Skruge

You need a condition in case Count still equals zero.

If $count Then
    ReDim $ce_id[$count][2]
    _ArrayDisplay($ce_id, "CE_IDs")
Else
    MsgBox(0, "CE_IDs", "No Matches found")
EndIf

I would do the same for $size as well.


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

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  

×