loading
 
Scripting problem
Dashie from Singapore  [1 posts]
13 year
I am having some problem with VB scripting? I'm trying to send a value to PIC using serial port in order to control the movement of two  motors. may i know how to set the variable to 0 when there is no object detected?  below example of my code.

cogX = GetVariable("COG_X")
cogArea = GetVariable("COG_AREA")

SetVariable "X_Value", xValue
SetVariable "Area_Value", areaValue

if cogArea < 3000 then
        areaValue = 1

else
    if cogArea > 3300 then
        areaValue = 2
else
        areaValue = 0
    
end if
end if


if cogX < 150 then
        xValue = 3


else
    if cogX > 160 then
        xValue = 4

else
        xValue = 0
        
end if
end if




Anonymous 13 year
Using COG_AREA is one way, COG_BOX_SIZE is another that we typically use ... but either should work out ok.

Try moving

SetVariable "X_Value", xValue
SetVariable "Area_Value", areaValue

to AFTER you set the values and that should work much better. More like

cogArea = GetVariable("COG_AREA")
if cogArea = 0 then
  SetVariable "X_Value", 0
  SetVariable "Area_Value", 0
else

  cogX = GetVariable("COG_X")

  if cogArea < 3000 then
        areaValue = 1
  elseif cogArea > 3300 then
        areaValue = 2
  else
        areaValue = 0
  end if

  if cogX < 150 then
    xValue = 3
  elseif cogX > 160 then
    xValue = 4
  else
    xValue = 0
  end if
  
  SetVariable "X_Value", xValue
  SetVariable "Area_Value", areaValue

end if

STeven.
Anonymous 13 year
Your code work like a charm.
Thx steven :)

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