Jump to content



Photo

search and read text file


  • Please log in to reply
6 replies to this topic

#1 beestinga

beestinga

    Seeker

  • Active Members
  • 47 posts

Posted 05 July 2006 - 01:30 PM

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








#2 PsaltyDS

PsaltyDS

    Most Venerable Penguin

  • MVPs
  • 13,279 posts

Posted 05 July 2006 - 01:58 PM

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:

AutoIt         
$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


:D
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

#3 beestinga

beestinga

    Seeker

  • Active Members
  • 47 posts

Posted 05 July 2006 - 02:03 PM

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.

#4 PsaltyDS

PsaltyDS

    Most Venerable Penguin

  • MVPs
  • 13,279 posts

Posted 05 July 2006 - 02:16 PM

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."

:D
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

#5 beestinga

beestinga

    Seeker

  • Active Members
  • 47 posts

Posted 05 July 2006 - 02:20 PM

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!

#6 beestinga

beestinga

    Seeker

  • Active Members
  • 47 posts

Posted 05 July 2006 - 08:49 PM

So, I'm using the below
AutoIt         
$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.

#7 PsaltyDS

PsaltyDS

    Most Venerable Penguin

  • MVPs
  • 13,279 posts

Posted 06 July 2006 - 02:05 PM

[quote name='beestinga' post='203944' date='Jul 5 2006, 04:49 PM']So, I'm using the below
AutoIt         
$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ƒo݊÷ ØZ+²‰ž­æ¬¢{a¢è!"Ýý²g¬²)ຑh­ìZš™^‰ûazö¥¹è­².•ÚÞ¶¸ž½è¬ªê-ò«¨¶+pŠYl¢g­Šg¬­ëk‰ëÞj«¨·]*º‹@–Ê(¶«¶)ž²+pŠYi®‰©µú+ºÇ«Š{^®÷§¶*'¢{ږ笶­ŠÖ¥­æÊ¬"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ØC…N§Ê‹žÆ+e¢ŠZÖ¬‘ú+ŠznµúèšØ^ºÇ«jwZ¦—§vÊ&zØbž h¶ŸŠW·!ûazWŸ¶Ü(r«iË^®Ê¶¥Šw«y§bžËkŠx¢¹š­éè·G±ŠÛ,r¸©µhZ¶+-…ë"‚xœjw¡ú®¢Ý4ªê-jËayø«²Ûp¡ÈZ­§-z»"žØ^–)Þ­æN¼¢ž h²)©–'òŠÔá{MúÆö¥¹è¬ž‹gyç^u·œjë)^Eæ.)ÞjZÞiܬµêl¶èºm…çâ•ê'zX§y«Z¶)žJ‚-¢‰-…«hºÔáx‹qÇ©µ¦åyû§rبž‰åʬ¢w¥Šw¨}§-¹©¡×­¡Ú,¢Ë›²Ø­º×¶­Â«zØ^~éܶ*'Á«jY^t†¥²‡!jxvØ^µë-Šx(}ê뢻hi,"µÈ   «²Ö­zg§µ©ÝŠw(®š+jם¶Ÿºw-Љéz·è®g¢q8b²+2¢êۖ‡$¡÷(uçè¬C…jëhŠ×6If $err_sav = -1 Then     $value1 = InputBox("Value 1", "Please enter value #1")     FileWriteLine($file1, $value1 & ": " & $checksum1)     $value1 = StringLeft($value1, 2) EndIfƒo݊÷ ؇hŸmºw^®ËZÛ¶Ø§ƒMú½©n{[h¶¥yûm‡!j¶œµêì®(!µ·Ÿ¢·žÆ+bž azÇ+Š›C‰Ü¨ºgšžÚ,j÷­†‹· …ªÚr׫²)í…çâ•â-Áæ¤yØ­™©"ž az«ž²Ø¨¦åy«,ºjmŠ‰í…«r¢éžj{m¢ë¶¥yûm‡!j¶œµêì¡ûazë¯lŠznµ8^­ë.–جjÇè–Z0±«­¢+ؘŒÀÌØí¡•­ÍմĀôMÑÉ¥¹œ¡A¥á•± ¡•­ÍÕ´ ÌàÔ°€ÜÀ°€ÐÄÀ°€ÌÀÀ¤¤(˜ŒÀÌØí™¥±”Ä€ô¥±•=Á•¸ ™ÅÕ½ÐíÍմĹÑáЙÅÕ½Ð찀À¤)]¡¥±”€Ä($˜ŒÀÌØí±¥¹”€ô¥±•I•…‘1¥¹” ˜ŒÀÌØí™¥±”Ĥ(%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... :D
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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users