beestinga Posted July 5, 2006 Share Posted July 5, 2006 OK, so I want to take a pixelchecksum, find it in a file, and read the first two characters of that line. If it doesn't find the value in the file, it's supposed to prompt the user and write what the user says it is so that it will find it next time around. For some reason, though, it's getting stuck in the While loop. When I put a msg box or traytip dialog into the while loop, it keeps bringing that up, so for some reason it's not exiting out of the loop. Right now, sum1.txt is empty so FileReadLine should be setting @error to -1 (Since it's reaching the end of the file without finding the appropriate value). Let me know what you think! $checksum1 = PixelChecksum(385, 70, 410, 300) $file1 = FileOpen("sum1.txt", 0) SetError(0) While $value1 = 0 $line = String(FileReadLine($file1)) If @error = -1 Then ExitLoop If @error = 1 Then ExitLoop If _IsAcceptable($checksum1, $line) = 1 Then $value1 = StringLeft($line, 2) EndIf WEnd If @error = -1 Then $value1 = InputBox("Value 1", "Please enter value #1") FileWriteLine($file1, $value1 & ": " & $checksum1) $value1 = StringLeft($value1, 2) EndIf Func _IsAcceptable($sNumber, $sString) If StringInStr($sString, String($sNumber)) Then Return 1 Return 0 EndFunc ;==>_IsAcceptable Link to comment Share on other sites More sharing options...
PsaltyDS Posted July 5, 2006 Share Posted July 5, 2006 OK, so I want to take a pixelchecksum, find it in a file, and read the first two characters of that line. If it doesn't find the value in the file, it's supposed to prompt the user and write what the user says it is so that it will find it next time around. For some reason, though, it's getting stuck in the While loop. When I put a msg box or traytip dialog into the while loop, it keeps bringing that up, so for some reason it's not exiting out of the loop. Right now, sum1.txt is empty so FileReadLine should be setting @error to -1 (Since it's reaching the end of the file without finding the appropriate value). Let me know what you think! $checksum1 = PixelChecksum(385, 70, 410, 300) $file1 = FileOpen("sum1.txt", 0) SetError(0) While $value1 = 0 $line = String(FileReadLine($file1)) If @error = -1 Then ExitLoop If @error = 1 Then ExitLoop If _IsAcceptable($checksum1, $line) = 1 Then $value1 = StringLeft($line, 2) EndIf WEnd If @error = -1 Then $value1 = InputBox("Value 1", "Please enter value #1") FileWriteLine($file1, $value1 & ": " & $checksum1) $value1 = StringLeft($value1, 2) EndIf Func _IsAcceptable($sNumber, $sString) If StringInStr($sString, String($sNumber)) Then Return 1 Return 0 EndFunc ;==>_IsAcceptable I'm not sure your @error values last as long as you want them to unchanged. Try it this way: $checksum1 = PixelChecksum(385, 70, 410, 300) $file1 = FileOpen("sum1.txt", 0) While $value1 = 0 $line = FileReadLine($file1) $err_sav = @error If $err_sav = -1 Then ExitLoop If $err_sav = 1 Then ExitLoop $line = String($line) If _IsAcceptable($checksum1, $line) = 1 Then $value1 = StringLeft($line, 2) ; If left two chars are "00" continue loop? EndIf WEnd If $err_sav = -1 Then $value1 = InputBox("Value 1", "Please enter value #1") FileWriteLine($file1, $value1 & ": " & $checksum1) $value1 = StringLeft($value1, 2) EndIf Func _IsAcceptable($sNumber, $sString) If StringInStr($sString, String($sNumber)) Then Return 1 Return 0 EndFunc ;==>_IsAcceptable 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 Link to comment Share on other sites More sharing options...
beestinga Posted July 5, 2006 Author Share Posted July 5, 2006 I'm not sure your @error values last as long as you want them to unchanged. Try it this way:So, does @error set itself back to 0 immediately? I had put seterror(0) outside the loop to reset it, but is that necessary?When the documentation said that it sets @error to -1 or 1, I thought that you could then reference it as such. I will test this out whenever I get home tonight.Thanks. Link to comment Share on other sites More sharing options...
PsaltyDS Posted July 5, 2006 Share Posted July 5, 2006 So, does @error set itself back to 0 immediately? I had put seterror(0) outside the loop to reset it, but is that necessary?When the documentation said that it sets @error to -1 or 1, I thought that you could then reference it as such. I will test this out whenever I get home tonight.Thanks.You can use @error immediately after a function, but it only last until the next function. So save it to a variable if you want to do multiple steps with it. From the help file on SetError(): "When entering a function @error is set to 0. Unless SetError() is called, then @error will remain 0 after the function has ended. This means that in order for @error to be set after a function, it must be explicitly set. This also means you may need to backup the status of @error in a variable if you are testing it in a While-WEnd loop." 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 Link to comment Share on other sites More sharing options...
beestinga Posted July 5, 2006 Author Share Posted July 5, 2006 That makes perfect sense and will probably rectify my problem. I will try it out whenever I get a chance. Thanks for pointing that out to me! Link to comment Share on other sites More sharing options...
beestinga Posted July 5, 2006 Author Share Posted July 5, 2006 So, I'm using the below $checksum1 = PixelChecksum(385, 70, 410, 300) $file1 = FileOpen("sum1.txt", 0) $x = 1 While $value1 = 0 $line = FileReadLine($file1,$x) $err_sav = @error If $err_sav = -1 Then ExitLoop If $err_sav = 1 Then ExitLoop $x = $x + 1 $line = String($line) If _IsAcceptable($checksum1, $line) = 1 Then $value1 = StringLeft($line, 2) ; If left two chars are "00" continue loop? EndIf WEnd If $err_sav = -1 Then $value1 = InputBox("Value 1", "Please enter value #1") FileWriteLine($file1, $value1 & ": " & $checksum1) $value1 = StringLeft($value1, 2) EndIf Func _IsAcceptable($sNumber, $sString) If StringInStr($sString, String($sNumber)) Then Return 1 Return 0 EndFunc ;==>_IsAcceptable For some reason, though, It's messing up. For example,. if the value it should retrieve is "8 ", it will sometimes retrieve a "10" Also, other times it will prompt for user intervention on values that it already has. I know this from going through the text file and repeatedly removing duplicates (it has the same checksum value next to the dupes as well). These screw-ups are, from my observation, entirely random and I can't figure out why they happen. Is it possible for two different "images" or collections of pixels to return the same checksum? Perhaps if it's a small area and both images are very similar? I'm using pixelchecksum as a poor/stupid man's OCR. Link to comment Share on other sites More sharing options...
PsaltyDS Posted July 6, 2006 Share Posted July 6, 2006 So, I'm using the below $checksum1 = PixelChecksum(385, 70, 410, 300) $file1 = FileOpen("sum1.txt", 0) $x = 1 While $value1 = 0 $line = FileReadLine($file1,$x) $err_sav = @error If $err_sav = -1 Then ExitLoop If $err_sav = 1 Then ExitLoop $x = $x + 1 $line = String($line) If _IsAcceptable($checksum1, $line) = 1 Then $value1 = StringLeft($line, 2) ; If left two chars are "00" continue loop? EndIf WEnd If $err_sav = -1 Then $value1 = InputBox("Value 1", "Please enter value #1") FileWriteLine($file1, $value1 & ": " & $checksum1) $value1 = StringLeft($value1, 2) EndIf Func _IsAcceptable($sNumber, $sString) If StringInStr($sString, String($sNumber)) Then Return 1 Return 0 EndFunc ;==>_IsAcceptableoÝ÷ ØZ+²æ¬¢{a¢è!"Ýý²g¬²)àºhìZ^ûazö¥¹è².ÚÞ¶¸½è¬ªê-ò«¨¶+pYl¢gg¬ëkëÞj«¨·]*º@Ê(¶«¶)²+pYi®©µú+ºÇ«{^®÷§¶*'¢{Ú笶֥æʬ"IèÂØb±úè "a® Ø^µìm~)^jwkzµçeÊ·¦¢ø§Û©'µë"¶¬¶¬jgç$²é¯j[ìm¶ayÛ©zƬÁéeN¬zÇ+{©±ªÞ~º&*±êïjبéí·¥Ê¶§vÒj}ýµø º·¨ºÜ!ÊØ^Ê©¥éȲ+i¢Ë"nW¢»p¡Ø}êÞÚ®¢Ø¦j¬ªê-¢·(W¶*'²é¥²Ú+zÛ«Ø^±©r˦=êáj"~+wöƬ©ej·jw[¢Øb¨±ªÞ½êò²)¢ªÈßÙ®²)à¦,^È^rK.«¦+þËn¦'fj}ý°àþ«¨µâ!j÷§¢'^j0ºxª¹ì¨º·!yÉvÇ+yéìyËb¢{æî¶Ø^"ríì!¢W)àzÇ¥ë&y§f×"!j÷§ßÛaiÖ§ÉÊ}ç²zÖ(º·©y«méh¢§¶)hê¶ÞzØb!j^T^i׫®ÞÆ+lØCN§ÊÆ+e¢ZÖ¬ú+znµúèØ^ºÇ«jwZ¦§vÊ&zØbh¶W·!ûazW¶Ü(r«iË^®Ê¶¥w«y§bËkx¢¹éè·G±Û,r¸©µhZ¶+-ë"xjw¡ú®¢Ý4ªê-jËayø«²Ûp¡ÈZ§-z»"Ø^)ÞæN¼¢h²)©'òÔá{MúÆö¥¹è¬gyç^u·jë)^Eæ.)ÞjZÞiܬµêl¶èºmçâê'zX§y«Z¶)J-¢-«hºÔáxqÇ©µ¦åyû§rبåʬ¢w¥w¨}§-¹©¡×¡Ú,¢Ë²Øº×¶Â«zØ^~éܶ*'Á«jY^t¥²!jxvØ^µë-x(}ê뢻hi,"µÈ «²Özg§µ©Ýw(®+j׶ºw-éz·è®g¢q8b²+2¢êÛ$¡÷(uçè¬Cjëh×6If $err_sav = -1 Then $value1 = InputBox("Value 1", "Please enter value #1") FileWriteLine($file1, $value1 & ": " & $checksum1) $value1 = StringLeft($value1, 2) EndIfoÝ÷ Øhmºw^®ËZ۶اMú½©n{[h¶¥yûmÂ!j¶µêì®(!µ·¢·Æ+bazÇ+CܨºgÚ,j÷· ªÚr׫²)íçââ-Áæ¤yØ©"az«²Ø¨¦åy«,ºjmí«r¢éj{m¢ë¶¥yûmÂ!j¶µêì¡ûazë¯lznµ8^ë.جjÇèZ0±«¢+ØÀÌØí¡ÍÕ´ÄôMÑÉ¥¹¡A¥á± ¡ÍÕ´ ÌàÔ°ÜÀ°ÐÄÀ°ÌÀÀ¤¤(ÀÌØí¥±Äô¥±=Á¸ ÅÕ½ÐíÍմĹÑáÐÅÕ½Ðì°À¤)]¡¥±Ä($ÀÌØí±¥¹ô¥±I1¥¹ ÀÌØí¥±Ä¤(%MÝ¥Ñ ÉɽÈ($% ÍÀ쥱±¥¹É¹½Éµ±±ä($$$ÀÌØí±¥¹ôMÑÉ¥¹ ÀÌØí±¥¹¤($$%%MÑÉ¥¹%¹MÑÈ ÀÌØí±¥¹°ÀÌØí¡ÍմĤQ¡¸($$$%%MÑÉ¥¹1Ð ÀÌØí±¥¹°È¤±ÐìÐìÅÕ½ÐìÀÀÅÕ½ÐìQ¡¸á¥Ñ1½½À($$%¹%($$$($% Í´Äì=($$$ÀÌØíÙ±ÕÄô%¹ÁÕÑ ½à ÅÕ½ÐíY±ÕÄÅÕ½Ðì°ÅÕ½ÐíA±Í¹ÑÈÙ±ÕÄÅÕ½Ðì¤($$$ÀÌØíÙ±ÕÄôMÑÉ¥¹1Ð ÀÌØíÙ±ÕİȤ($$$ì]É¥ÑÅÕ½ÐíÙØ踸¸ÅÕ½Ðì($$$ì%]¡ÉÙØô±ÐÈ¡É̽ÕÍÈ¥¹ÁÕÐ($$$ì%¸¸¸ô¹ÜÁ¥á°¡ÍÕ´($$%¥±]É¥Ñ1¥¹ ÀÌØí¥±Ä°ÀÌØíÙ±ÕĵÀìÅÕ½ÐìèÅÕ½ÐìµÀìÀÌØí¡ÍմĤ($$%á¥Ñ1½½À($$$($% ÍÄìÉɽÈ($$%5Í ½à ÄØ°ÅÕ½ÐíÉɽÈÌÌìÅÕ½Ðì°ÅÕ½ÐíÉɽÈÉ¥¹±¥¹É½´ÍմĹÑáÐÌÌìá¥Ñ¥¹¸¸¸ÅÕ½Ðì¤($$%á¥Ñ1½½À(%¹MÝ¥Ñ )]¹()¥± ±½Í ÀÌØí¥±Ä Still doesn't make sense to me, so maybe I just made it worse... 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 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