VB Script
7 year
I want to process an image and display the result as pass or fail depending on the area of blob remains. I have problem with VB script which continuously display fail. I have used Set module where I have chosen result and given values Pass and Fail and then used VB script module with the following code.

area = GetVariable("AREA")
If area<1000 then
SetVariable "Result",'Pass'
Elseif  area>1000 then
SetVariable "Result",'Fail'
End if

After which I have used display module to display Result. It continuously results in Fail. Why is that so? Give u guide Steven. Thanks in advance

Steven Gentner from United States  [1446 posts] 7 year
You may want to switch one of the statements to either

if area <= 1000


elseif area >= 1000

since if you happen to have an area of 1000 neither statement will trigger.

But that's not your current issue. What is most likely happening is that your are is ALWAYS larger than 1000. Have you looked at the value of Area using the Watch module to see if it does change around 1000? Sometimes very dark pixels which are hard to see may be counted as an area ... since any non-black, i.e. any pixel not perfectly equal to 0,0,0 will be counted as part of the area. You can solve this by adding a Threshold at 128 to ensure you have a perfectly black and white image before running the AREA stats.

Anonymous  [6 posts] 7 year
I tried the threshold on the images to ensure the end result remain in the white and black pixels but it does not seem to work. Trials made to achieve the desired output but in vain. I think I am  messing with the variable thing so you can have a look again on what I have done.
After having done with the processing of Image (includes threshold and blob size filter) I use Set Variable where I take Result as the variable with no value chosen. Set once is tick. Then I use VB script program where I entered the following code (giving the value to Result variable )

area = GetVariable("AREA")
if area<=1000 then
SetStrVariable "Result", 'Pass'
elseif area>1000 then
SetVariable "Result" , 'Fail'

The program when Reload and Run does give an error  Syntax error but I continue as error (not understanding the error ).
After which I use Display variable and select Result. It ends up displaying Result only, not its value i.e Pass or Fail.
Can you  now figure out anything which I am missing?
Steven Gentner from United States  [1446 posts] 7 year
VBscript is a bit different than JScript where the single quotes are NOT understood. Use double quotes to indicate a string as in:

area = GetVariable("AREA")
if area<=1000 then
  SetVariable "Result", "Pass"
elseif area>1000 then
  SetVariable "Result" , "Fail"
end if

When you get an error, its best to spend some time trying to fix it as ignoring it will almost always guarantee failure.

Note, if VBscript isn't your thing, you can also use the Set_Variable module to do something similar. See attached. Note, the VBScript example is DISABLED and just included so you can have a good copy of the above code.

Finally, please include your actual robofile as its very likely other things are wrong elsewhere than just the VBscript part.



This forum thread has been closed due to inactivity (more than 4 months) or number of replies (more than 50 messages). Please start a New Post and enter a new forum thread with the appropriate title.

 New Post   Forum Index