Kovitt Posted July 23, 2008 Posted July 23, 2008 (edited) Hello, I tried using a variable in a StringReg and it doesn't work How can I do this differently? Also how come my _Filereadtoarray didn't work? (I know its commented out) Instead I am forced to use a while loop. $JobNum = _ArrayMaxIndex($Job_Instance) $path = FileOpen("JobInfo.txt",0) $i = 0 ;_filereadtoarray($path, $JobInfo) While True $Line = FileReadLine($path) If @error = -1 Then ExitLoop EndIf $JobInfo[$i] = $Line $i += 1 Wend $JobArray = StringRegExp($JobInfo, '(?:\s{1,})(' & $Job[$JobNum] &')(?:\s{1,})([0-9]{1,})(?:\s{1,})([0-9]{1,})') If @error = 0 Then $JobInfoFinal = $JobArray[0] & " " & $JobArray[1] & " " & $JobArray[2] EndIf MsgBox(0,"Session ID", $JobInfoFinal) Contents of JobInfo.txt JOB SID SERIAL# ---------- ---------- ---------- 532 187 4448 241 447 13965 381 535 62765 281 271 61865 530 818 45848 529 530 37572 533 740 60799 141 128 47172 8 rows selected. Thanks for the help! Edited July 23, 2008 by Kovitt
andybiochem Posted July 23, 2008 Posted July 23, 2008 (edited) Hi again! Re - your file read to array... This: $path = FileOpen("JobInfo.txt",0) _filereadtoarray($path, $JobInfo) Should be: $path = "JobInfo.txt" _filereadtoarray($path, $JobInfo) Edited July 23, 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!
PsaltyDS Posted July 23, 2008 Posted July 23, 2008 Hello, I tried using a variable in a StringReg and it doesn't work How can I do this differently? Also how come my _Filereadtoarray didn't work? (I know its commented out) Instead I am forced to use a while loop. $JobNum = _ArrayMaxIndex($Job_Instance) $path = FileOpen("JobInfo.txt",0) $i = 0 ;_filereadtoarray($path, $JobInfo) While True $Line = FileReadLine($path) If @error = -1 Then ExitLoop EndIf $JobInfo[$i] = $Line $i += 1 Wend $JobArray = StringRegExp($JobInfo, '(?:\s{1,})(' & $Job[$JobNum] &')(?:\s{1,})([0-9]{1,})(?:\s{1,})([0-9]{1,})') If @error = 0 Then $JobInfoFinal = $JobArray[0] & " " & $JobArray[1] & " " & $JobArray[2] EndIf MsgBox(0,"Session ID", $JobInfoFinal) Contents of JobInfo.txt JOB SID SERIAL# ---------- ---------- ---------- 532 187 4448 241 447 13965 381 535 62765 281 271 61865 530 818 45848 529 530 37572 533 740 60799 141 128 47172 8 rows selected. Thanks for the help! One step at a time... First, does this work? #include <Array.au3> $path = "JobInfo.txt" Global $JobInfo _filereadtoarray($path, $JobInfo) _ArrayDisplay($JobInfo, "$JobInfo") muttley Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
andybiochem Posted July 23, 2008 Posted July 23, 2008 One step at a time... First, does this work? #include <Array.au3> $path = "JobInfo.txt" Global $JobInfo _filereadtoarray($path, $JobInfo) _ArrayDisplay($JobInfo, "$JobInfo") muttley lol, beat you to it. - 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!
Kovitt Posted July 23, 2008 Author Posted July 23, 2008 One step at a time... First, does this work? #include <Array.au3> $path = "JobInfo.txt" Global $JobInfo _filereadtoarray($path, $JobInfo) _ArrayDisplay($JobInfo, "$JobInfo") muttleyHi again! Re - your file read to array... This: $path = FileOpen("JobInfo.txt",0) _filereadtoarray($path, $JobInfo) Should be: $path = "JobInfo.txt" filereadtoarray($path, $JobInfo) Yep that fixes my FileReadToArray issue!! Thanks! Any thoughts on the StringReg Alternative?
PsaltyDS Posted July 23, 2008 Posted July 23, 2008 Yep muttley that fixes my FileReadToArray issue!!Thanks!Any thoughts on the StringReg Alternative?Rewrite the short piece we are working on with the corrected _FileReadToArray() usage, and all the data required for us to run it: - a few values for $Job- Close the loop with WEnd or Next, etc.- Add required #includesIf we can't run it, we can't test it. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Kovitt Posted July 23, 2008 Author Posted July 23, 2008 (edited) Rewrite the short piece we are working on with the corrected _FileReadToArray() usage, and all the data required for us to run it: - a few values for $Job - Close the loop with WEnd or Next, etc. - Add required #includes If we can't run it, we can't test it. muttley#Include <File.au3> #Include <Array.au3> #include <GUIConstantsEx.au3> Dim $Job[10], $JobInfo[100], $JobArray[10], $JobInfoFinal, $path, $JobNum $Job[0] = 523 $Job[1] = 526 $Job[2] = 532 $Job[3] = 576 $Job[4] = 592 $Job[5] = 598 $Job_Instance[0] = 12 $Job_Instance[1] = 546 $Job_Instance[2] = 987 $Job_Instance[3] = 0 $Job_Instance[4] = 365 $Job_Instance[5] = 212 $JobNum = _ArrayMaxIndex($Job_Instance) $path = "JobInfo.txt" for $x=0 to 9 $JobArray[$x] = 0 Next _filereadtoarray($path, $JobInfo) ; $JobArray = StringRegExp($JobInfo, '(?:\s{1,})(' & $Job[$JobNum] &')(?:\s{1,})([0-9]{1,})(?:\s{1,})([0-9]{1,})') ; If @error = 0 Then ; $JobInfoFinal = $JobArray[0] & " " & $JobArray[1] & " " & $JobArray[2] ; EndIf ; MsgBox(0,"Session ID", $JobInfoFinal) This good? Thanks soo much for helping me out! Edit: Script did not provide enough infoJobInfo.txt Edited July 23, 2008 by Kovitt
PsaltyDS Posted July 23, 2008 Posted July 23, 2008 CODE#Include <File.au3> #Include <Array.au3> #include <GUIConstantsEx.au3> Dim $Job[10], $JobInfo[100], $JobArray[10], $JobInfoFinal, $path, $JobNum $Job[0] = 523 $Job[1] = 526 $Job[2] = 532 $Job[3] = 576 $Job[4] = 592 $Job[5] = 598 $Job_Instance[0] = 12 $Job_Instance[1] = 546 $Job_Instance[2] = 987 $Job_Instance[3] = 0 $Job_Instance[4] = 365 $Job_Instance[5] = 212 $JobNum = _ArrayMaxIndex($Job_Instance) $path = "JobInfo.txt" for $x=0 to 9 $JobArray[$x] = 0 Next _filereadtoarray($path, $JobInfo) ; $JobArray = StringRegExp($JobInfo, '(?:\s{1,})(' & $Job[$JobNum] &')(?:\s{1,})([0-9]{1,})(?:\s{1,})([0-9]{1,})') ; If @error = 0 Then ; $JobInfoFinal = $JobArray[0] & " " & $JobArray[1] & " " & $JobArray[2] ; EndIf ; MsgBox(0,"Session ID", $JobInfoFinal) This good? Thanks soo much for helping me out! Edit: Script did not provide enough info OK, it looks like you want to loop through the lines in the file, looking for each of the numbers in the $Job array. This runs: expandcollapse popup#include <File.au3> #include <Array.au3> #include <GUIConstantsEx.au3> ; Simulate _FileReadToArray() Dim $JobInfo[12] = [11, _ " JOB SID SERIAL#", _ "---------- ---------- ----------", _ " 532 187 4448", _ " 241 447 13965", _ " 281 271 61865", _ " 530 818 45848", _ " 529 530 37572", _ " 533 740 60799", _ " 141 128 47172", _ "", _ "7 rows selected."] Dim $Job[6], $JobArray, $JobInfoFinal, $path $Job[0] = 523 $Job[1] = 526 $Job[2] = 532 $Job[3] = 576 $Job[4] = 592 $Job[5] = 598 $path = "JobInfo.txt" ; This file read simulated above ; _FileReadToArray($path, $JobInfo) For $j = 1 To $JobInfo[0] For $n = 0 To UBound($Job) - 1 $JobArray = StringRegExp($JobInfo[$j], '(?:\s{1,})(' & $Job[$n] & ')(?:\s{1,})([0-9]{1,})(?:\s{1,})([0-9]{1,})', 1) If @error = 0 Then $JobInfoFinal = $JobArray[0] & " " & $JobArray[1] & " " & $JobArray[2] MsgBox(0, "Session ID", "Input line no." & $j & " = " & $JobInfo[$j] & @CRLF & _ "$Job[" & $n & "] = " & $Job[$n] & @CRLF & _ "RegExp match = " & $JobInfoFinal) ExitLoop EndIf Next Next I removed the _FileReadToArray() so the test script wouldn't require multiple files to test with. The $JobInfo array statically created should look exactly like the result from _FileReadToArray(). This runs fine for me, and finds one match with "532". muttley Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Kovitt Posted July 23, 2008 Author Posted July 23, 2008 OK, it looks like you want to loop through the lines in the file, looking for each of the numbers in the $Job array. This runs: expandcollapse popup#include <File.au3> #include <Array.au3> #include <GUIConstantsEx.au3> ; Simulate _FileReadToArray() Dim $JobInfo[12] = [11, _ " JOB SID SERIAL#", _ "---------- ---------- ----------", _ " 532 187 4448", _ " 241 447 13965", _ " 281 271 61865", _ " 530 818 45848", _ " 529 530 37572", _ " 533 740 60799", _ " 141 128 47172", _ "", _ "7 rows selected."] Dim $Job[6], $JobArray, $JobInfoFinal, $path $Job[0] = 523 $Job[1] = 526 $Job[2] = 532 $Job[3] = 576 $Job[4] = 592 $Job[5] = 598 $path = "JobInfo.txt" ; This file read simulated above ; _FileReadToArray($path, $JobInfo) For $j = 1 To $JobInfo[0] For $n = 0 To UBound($Job) - 1 $JobArray = StringRegExp($JobInfo[$j], '(?:\s{1,})(' & $Job[$n] & ')(?:\s{1,})([0-9]{1,})(?:\s{1,})([0-9]{1,})', 1) If @error = 0 Then $JobInfoFinal = $JobArray[0] & " " & $JobArray[1] & " " & $JobArray[2] MsgBox(0, "Session ID", "Input line no." & $j & " = " & $JobInfo[$j] & @CRLF & _ "$Job[" & $n & "] = " & $Job[$n] & @CRLF & _ "RegExp match = " & $JobInfoFinal) ExitLoop EndIf Next Next I removed the _FileReadToArray() so the test script wouldn't require multiple files to test with. The $JobInfo array statically created should look exactly like the result from _FileReadToArray(). This runs fine for me, and finds one match with "532". Thank you sooo much for the help! *I don't know if you noticed my edited post above with a more detailed script* My question is if that works for you , then how come I get an error with: $JobArray = StringRegExp($JobInfo, '(?:\s{1,})(' & $Job[$JobNum] &')(?:\s{1,})([0-9]{1,})(?:\s{1,})([0-9]{1,})') I don't need to loop through jobs because I already know which job I need it to select. The one with the same [#] as $JobNum. I keep getting an error with my stringreg and yours looks almost Identical. muttley Again I really appreciate all the help you have provided!
PsaltyDS Posted July 23, 2008 Posted July 23, 2008 My question is if that works for you , then how come I get an error with: $JobArray = StringRegExp($JobInfo, '(?:\s{1,})(' & $Job[$JobNum] &')(?:\s{1,})([0-9]{1,})(?:\s{1,})([0-9]{1,})') I don't need to loop through jobs because I already know which job I need it to select. The one with the same [#] as $JobNum. I keep getting an error with my stringreg and yours looks almost Identical. muttley Again I really appreciate all the help you have provided! $JobInfo is an array, so it cannot be the input string for StringRegExp(): $JobArray = StringRegExp($JobInfo, '(?:\s{1,})(' & $Job[$JobNum] &')(?:\s{1,})([0-9]{1,})(?:\s{1,})([0-9]{1,})') In my code you see that as an array reference, vice trying to pass the entire array: $JobInfo[$j] Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Kovitt Posted July 23, 2008 Author Posted July 23, 2008 My string reg doesn't work properly : ( My StringReg is $JobArray = StringRegExp($JobInfo, "(?:\s{1,})("& $Job[$JobNum] &")(?:\s{1,})([0-9]{1,})(?:\s{1,})([0-9]{1,})",1) If @error = 0 Then $JobInfoFinal = $JobArray[0] & " " & $JobArray[1] & " " & $JobArray[2] MsgBox(0,"Session ID", $JobInfoFinal) ;_ArrayDisplay($JobArray) EndIf It is searching through an array that contains: JOB SID SERIAL# ---------- ---------- ---------- 532 187 4448 241 447 13965 281 271 61865 530 818 45848 529 530 37572 533 740 60799 141 128 47172 7 rows selected. $Job[$JobNum] = 141 So I need it to pull: 141 128 47172 What have I done wrong?
Paulie Posted July 23, 2008 Posted July 23, 2008 I'm confused... You have a 2D array thats 7x3 You are StringRegExp on the array? StringRegExp works on stings, not arrays...
martin Posted July 23, 2008 Posted July 23, 2008 My string reg doesn't work properly : ( My StringReg is $JobArray = StringRegExp($JobInfo, "(?:\s{1,})("& $Job[$JobNum] &")(?:\s{1,})([0-9]{1,})(?:\s{1,})([0-9]{1,})",1) If @error = 0 Then $JobInfoFinal = $JobArray[0] & " " & $JobArray[1] & " " & $JobArray[2] MsgBox(0,"Session ID", $JobInfoFinal) ;_ArrayDisplay($JobArray) EndIf It is searching through an array that contains: JOB SID SERIAL# ---------- ---------- ---------- 532 187 4448 241 447 13965 281 271 61865 530 818 45848 529 530 37572 533 740 60799 141 128 47172 7 rows selected. $Job[$JobNum] = 141 So I need it to pull: 141 128 47172 What have I done wrong? Try this $JobInfo = FileRead("regstring1.txt"); I put your sample in this file so I could test $jobnum = "141" $JobArray = StringRegExp($JobInfo, $jobnum &"(?:\s{1,})([0-9]{1,})(?:\s{1,})([0-9]{1,})",1) If @error = 0 Then $JobInfoFinal = $jobnum & " " & $JobArray[0] & " " & $JobArray[1]; & " " & $JobArray[2] MsgBox(0,"Session ID", $JobInfoFinal) EndIf Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Moderators SmOke_N Posted July 23, 2008 Moderators Posted July 23, 2008 Try keeping to one topic:#include <array.au3> Global $s_text = ClipGet() Global $a_job_num[7] = [532, 241, 281, 530, 529, 533, 141] For $i = 0 To 6 $a_job_info = StringRegExp($s_text, "\s+(" & $a_job_num[$i] & ")\s+(\d+)\s+(\d+)(?:\z|\r)", 3) If Not @error Then _ArrayDisplay($a_job_info, "Loop: " & $i + 1) EndIf Next Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Kovitt Posted July 24, 2008 Author Posted July 24, 2008 Try keeping to one topic:#include <array.au3> Global $s_text = ClipGet() Global $a_job_num[7] = [532, 241, 281, 530, 529, 533, 141] For $i = 0 To 6 $a_job_info = StringRegExp($s_text, "\s+(" & $a_job_num[$i] & ")\s+(\d+)\s+(\d+)(?:\z|\r)", 3) If Not @error Then _ArrayDisplay($a_job_info, "Loop: " & $i + 1) EndIf NextoÝ÷ Ûú®¢×¶¸vØb±«¢+ؽÈÀÌØí¤ôÀѼU½Õ¹ ÀÌØí)½Ì¤´Ä($$$$$ÀÌØí)½ÉÉäôMÑÉ¥¹IáÀ ÀÌØí)½%¹¼°ÅÕ½ÐìÀäÈí̬ ÅÕ½ÐìµÀìÀÌØí)½lÀÌØí)½9ÕµtµÀìÅÕ½Ðì¤ÀäÈí̬ ÀäÈí¬¤ÀäÈí̬ ÀäÈí¬¤ üèÀäÈíéðÀäÈíȤÅÕ½Ðì°Ì¤($$$$$%9½ÐÉɽÈQ¡¸($$$$$$%}ÉÉå¥ÍÁ±ä ÀÌØí}©½}¥¹¼°ÅÕ½Ðí1½½ÀèÅÕ½ÐìµÀìÀÌØí¤¬Ä¤($$$$$%¹%($$$$%9áÐ Because I already know what the Job I'm looking for, is there like a StringSearch or something? Thanks for all the help!
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