Sign in to follow this  
Followers 0
gordo

Trying to match a whitelist with nested IFs...

8 posts in this topic

#1 ·  Posted (edited)

I am working on a script where I am trying to have it parse through a whitelist of arbitrary size. I've read the whitelist file into an array. Now, I want it to process the main instructions only if the comparison string ($new_list[$process_number][0]) is not found in the whitelist. I've gone so far as using a set of nested IF statements to accomplish this task. In the below case, it works for a whitelist consisting of exactly five strings, but won't work for a whitelist of any other size. Can I utilize some kind of loop to perform this whitelist testing? Here's a snippet...

While 1

Sleep(500)

     If $new_list[$process_number][0] <> $whitelist[1] Then
      If $new_list[$process_number][0] <> $whitelist[2] Then
       If $new_list[$process_number][0] <> $whitelist[3] Then
        If $new_list[$process_number][0] <> $whitelist[4] Then
         If $new_list[$process_number][0] <> $whitelist[5] Then
    
             ***MAIN INSTRUCTIONS SNIPPED***
    
          EndIf
         EndIf
        EndIf
       EndIf
      EndIf

WEnd

By the way, I'm aware that whitelist[0] contains the total number of strings in the whitelist, but I'm not sure how to use this piece of information to accomplish this task...

Edited by gordo

Share this post


Link to post
Share on other sites



?

While 1
   
   Sleep(500)
    $found = 0
   For $i = 1 To $whitelist[0]
      If $new_list[$process_number][0] == $whitelist[$i] Then
         $found = 1
         ExitLoop
      EndIf
   Next
   If Not $found Then
     ;***MAIN INSTRUCTIONS SNIPPED***
      
   EndIf
   
WEnd

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

Hmmm... I think that just might do it. Thanks! Does ExitLoop exit out of the For loop? I need it to stay in the While loop after testing.

?

While 1
   
   Sleep(500)
    $found = 0
   For $i = 1 To $whitelist[0]
      If $new_list[$process_number][0] == $whitelist[$i] Then
         $found = 1
         ExitLoop
      EndIf
   Next
   If Not $found Then
    ;***MAIN INSTRUCTIONS SNIPPED***
      
   EndIf
   
WEnd

<{POST_SNAPBACK}>

Share this post


Link to post
Share on other sites

from the help

ExitLoop

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

Terminate a While/Do/For loop.

ExitLoop [level]Parameters

level [optional] The number of levels of loop to exit. The default is 1 (meaning the current loop).


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

Thanks for the timely info. It worked exactly as requested. I had to change the double == to a single one though...

Now if I can only figure out how to deal with _readfiletoarray and its strange propensity for adding CR's to array strings... I've implemented StringTrimRight to strip off the CR, but the last line is always a doozie. If the file ends with a CR, I get an extra blank record. If the file ends at the last character of the last word, then after trimming, the last string is cut off by a character. Because of this, I can never get all the strings to evaluate properly.

#include <file.au3>
Dim $whitelist

If Not _FileReadToArray("c:\whitelist.txt",$whitelist) Then
   MsgBox(4096,"Error", " Error reading whitelist to array:" & @error)
   Exit
EndIf

For $x = 1 to $whitelist[0]
    $whitelist_trimmed = StringTrimRight($whitelist[$x], 1)
    Msgbox(0,'Record:' & $x, $whitelist_trimmed)
Next

Share this post


Link to post
Share on other sites

Have you tried- StringStripCR()?

Removes all carriage return values ( Chr(13) ) from a string.

StringStripCR ( "string" )

Parameters: string (The string to convert.)

Return Value: Returns the string with all instances of the @CR character (Chr(13)) removed.

Remarks: None.

The above is pulled from the help file. Let me know how that works out.

JS


AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Share this post


Link to post
Share on other sites

Thanks, that definitely works better -- it no longer cuts off the last character.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Perhaps someone might help if you created your own thread and didn't hi-jack someone else's. Excuse me if you have already and I haven't seen it.

Edited by Burrup

[u]Old Projects:[/u]A3MORGB2Hex[u]Old Functions:[/u]_TimeAdd/_TimeSub_AddComma_BubbleSort _RippleSort "He who does not understand your silence will probably not understand your words." - Elbert Hubbard.

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