SRL Archive - Help

Try-catch in Simba?


djborec

2012-09-08 07:32:42

Hello, I need to read some numbers from screen, I managed to read them and then I use StrToInt to convert them into Integer.

However ,the number that I am reading can be anything from 0 to 99999 so sometimes StrToInt returns error ,because OCR sometimes return String that is not number. (_9) for example or something.

So is there try-catch for SIMBA,so I can avoid to have script stopped ,because of this error.

weequ

2012-09-08 07:35:50

I think so but I'm not sure because I have never used. However you could use GetNumbers(String) and after that only use StrToInt if the length of the string is above zero.

riwu

2012-09-08 07:41:12

Use 'Try' instead.
Eg.
Try
StrToInt(NumInString);
Except
//some procedure to grab the number again? or Exit depending on your script structure.
end;
This will prevent a runtime error terminating the script.

djborec

2012-09-08 07:43:21

riwu, I have been looking for this ,thanks

masterBB

2012-09-08 07:50:00

A better way would be StrToIntDef(NumInString, -1);

This would return -1 when the number couldn't be read.

Master BAW

2012-09-08 19:09:51

I have a similar question: my script crashes when it does something wrong with this function.

DTMFromString

is it possible to try+except with this function? I don't want my script to crash when I'm away

Geo

2012-09-08 19:31:37

Some good suggestions above.

You could also use

result := ExtracFromStr(GetTextAtExWrap(), numbers)


then convert to an int with


StrToInt(result)

riwu

2012-09-08 21:29:13

From: Master BAW
I have a similar question: my script crashes when it does something wrong with this function.

DTMFromString

is it possible to try+except with this function? I don't want my script to crash when I'm away

How did DTMFromString cause a runtime error? If you think the problem definitely lies with it, you probably you didn't free the DTM and hence the memory leak caused the script to crash.

Master BAW

2012-09-09 06:33:16

From: riwu
How did DTMFromString cause a runtime error? If you think the problem definitely lies with it, you probably you didn't free the DTM and hence the memory leak caused the script to crash.


It was probably because I ran multiple of the same script in the same simba. In different simba's it works and doesn't crash on this function. (I know it crashes on this function because I see this function marked in orange in the script everytime the script has stopped)
but I didn't see an error yet because other scripts in the same simba continue and put text in the debug log…

anyway I am using multiple simba's now and I believe it's fine now. If I get another error like it I WILL see the error, and then I will post it here :)