OCRArea Var??

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
Shadow3641
Junior Coder
Posts: 26
Joined: Thu Nov 17, 2016 2:45 pm

OCRArea Var??

Post by Shadow3641 » Sat Oct 21, 2017 3:59 am

Ok, I have either found a bug, or I'm just missing something extremely silly.

I'm having an issue trying to run the results of the ORCArea through an IF statement. I have tried every combination that I can think of.

The Image that I'm scanning can have four words appear Freezing, Cold, Warm, and Boiling.

Code: Select all

Let>freezing=Freezing
Let>cold=Cold
Let>warm=Warm
Let>boiling=Boiling

OCRArea>373,108,475,128,strText

Let>temp={%strText%}

MessageModule>%temp%, %strText%, %freezing%

IF>{%temp%=%freezing%}
    //somecode
Else
    //somecode
Endif
In this example, the Message module will pop up as Freezing, Freezing, Freezing but the IF statement will still fail.

What am I missing?

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: OCRArea Var??

Post by Marcus Tettmar » Sat Oct 21, 2017 11:14 am

I don't think this is an issue with OCRArea. I think more likely there are spaces in the output or something you can't see which means that it's not exactly "Freezing". Try trimming the output.

I'd also try avoiding confusion by not having your variable the same name as the value. Gets confusing reading all that.

E.g. try this without OCRArea to prove your If should work if the values are what you think they are:

Code: Select all

Let>strFreezing=Freezing
Let>strText=Freezing
Let>temp=strText
If>{%temp%=%strFreezing%}
  Mdl>Correct!
Endif
This works as expected and the only difference is we are setting strText directly rather than via OCRArea. Therefore if the comparison fails then OCRArea MUST be returning something different. While it looks right in your MessageModal if for example the result is "Freezing " then you wouldn't notice that in the message but it would fail the comparison. So try:

Trim>strText,strText
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Shadow3641
Junior Coder
Posts: 26
Joined: Thu Nov 17, 2016 2:45 pm

Re: OCRArea Var??

Post by Shadow3641 » Sat Oct 21, 2017 2:47 pm

Yep, the Trim got it darn invisible char lol, and normally I don't use all those Var's I was just doing that to rule out all possibilities.

Here is the simplified version that works.

Code: Select all

OCRArea>373,108,475,128,strText

Trim>strText,strText

IF>%strText%="Freezing"
    //somecode
Else
    //somecode
Endif
Thanks again Marcus

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts