gfunk999 Posted July 13, 2008 Share Posted July 13, 2008 Please help, could someone please help me get this code into a loop? As you can see the model.log could contain different models, this code works the way it is, but I was wondering if a loop was possible. thanks in advance. #include <file.au3> #include <Process.au3> $file = FileOpen("c:\model.log", 0) $model = FileRead($file) $err = StringInStr($model, "Model 2047") If Not $err = 0 Then MsgBox(0, "Model", "Model 2047 found!") EndIf $err = StringInStr($model, "Model 2056") If Not $err = 0 Then MsgBox(0, "Model", "Model 2056 found!") EndIf $err = StringInStr($model, "Model 2347") If Not $err = 0 Then MsgBox(0, "Model", "Model 2347 found!") EndIf $err = StringInStr($model, "Model 2500") If Not $err = 0 Then MsgBox(0, "Model", "Model 2500 found!") EndIf Link to comment Share on other sites More sharing options...
SIone Posted July 13, 2008 Share Posted July 13, 2008 How about either: #include <file.au3> #include <Process.au3> Func FindModel() $file = FileOpen("c:\model.log", 0) $model = FileRead($file) $err = StringInStr($model, "Model 2047") If Not $err = 0 Then MsgBox(0, "Model", "Model 2047 found!") EndIf $err = StringInStr($model, "Model 2056") If Not $err = 0 Then MsgBox(0, "Model", "Model 2056 found!") EndIf $err = StringInStr($model, "Model 2347") If Not $err = 0 Then MsgBox(0, "Model", "Model 2347 found!") EndIf $err = StringInStr($model, "Model 2500") If Not $err = 0 Then MsgBox(0, "Model", "Model 2500 found!") EndIf Return $err EndFunc or #include <file.au3> #include <Process.au3> Func FindModel($FindModel) $file = FileOpen("c:\model.log", 0) $model = FileRead($file) $err = StringInStr($model, $FindModel) If Not $err = 0 Then MsgBox(0, "Model", $FindModel&" found!") EndIf Return $err EndFunc Just enter the Model number into the $FindModel string and call the function.. I havent tested this (as i dont have the .log file you are working) on so let me know how you get on. SIone Perilous to all of us are the devices of an art deeper than we ourselves possess. Link to comment Share on other sites More sharing options...
JustinMeyer Posted July 13, 2008 Share Posted July 13, 2008 You could try this to get one message box for all the models in your script, and loop until you want to cancel. expandcollapse popup#include <file.au3> #include <Process.au3> $file = FileOpen("c:\model.log", 0) $model = FileRead($file) Do $2047_CHCK = StringInStr($model, "Model 2047") If Not $2047_CHCK = 0 Then $2047 = "Model 2047 found!" Else $2047 = "Model 2047 not found!" EndIf $2056_CHCK = StringInStr($model, "Model 2056") If Not $2056_CHCK = 0 Then $2056 = "Model 2056 found!" Else $2056 = "Model 2056 not found!" EndIf $2347_CHCK = StringInStr($model, "Model 2347") If Not $2347_CHCK = 0 Then $2347 = "Model 2347 found!" Else $2347 = "Model 2347 not found!" EndIf $2500_CHCK = StringInStr($model, "Model 2500") If Not $2500_CHCK = 0 Then $2500 = "Model 2500 found!" Else $2500 = "Model 2500 not found!" EndIf $RESULT = MsgBox(5,"Model Check",$2047 & @CRLF & $2056 & @CRLF & $2347 & @CRLF & $2500) Until $RESULT = 2 Link to comment Share on other sites More sharing options...
SIone Posted July 13, 2008 Share Posted July 13, 2008 A good alternative, I wasnt sure if the list of model numbers was finite, hence my two versions. Perilous to all of us are the devices of an art deeper than we ourselves possess. Link to comment Share on other sites More sharing options...
andybiochem Posted July 13, 2008 Share Posted July 13, 2008 (edited) How about using arrays? #include <Array.au3> #include <File.au3> ;build an array of the 'models' you want to search for Dim $ModelArray[5] $ModelArray[1] = "Model 2047" $ModelArray[2] = "Model 2056" $ModelArray[3] = "Model 2347" $ModelArray[4] = "Model 2500" ;load the log file into a separate array Dim $LogArray[1] _FileReadToArray("c:\model.log",$LogArray) ;loop through your model array to see if each item exists in the log file For $i = 1 to (UBound($ModelArray) - 1) If _ArraySearch($LogArray,$ModelArray[$i],1) <> -1 Then MsgBox(0,"",$ModelArray[$i] & " found!") EndIf Next Not tested. [edited to add File.au3 include] Edited July 13, 2008 by andybiochem - Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar! Link to comment Share on other sites More sharing options...
SIone Posted July 13, 2008 Share Posted July 13, 2008 That is very Pro... I like that you saw the difference between 'testing for', and 'parsing for'. Slick work!! Perilous to all of us are the devices of an art deeper than we ourselves possess. Link to comment Share on other sites More sharing options...
gfunk999 Posted July 13, 2008 Author Share Posted July 13, 2008 Thanks all for the replies, they all work excellent! How about using arrays? #include <Array.au3> #include <File.au3> ;build an array of the 'models' you want to search for Dim $ModelArray[5] $ModelArray[1] = "Model 2047" $ModelArray[2] = "Model 2056" $ModelArray[3] = "Model 2347" $ModelArray[4] = "Model 2500" ;load the log file into a separate array Dim $LogArray[1] _FileReadToArray("c:\model.log",$LogArray) ;loop through your model array to see if each item exists in the log file For $i = 1 to (UBound($ModelArray) - 1) If _ArraySearch($LogArray,$ModelArray[$i],1) <> -1 Then MsgBox(0,"",$ModelArray[$i] & " found!") EndIf Next Not tested. [edited to add File.au3 include] Link to comment Share on other sites More sharing options...
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