Machsupport Forum

Mach Discussion => VB and the development of wizards => Topic started by: jdmaya on November 21, 2012, 10:36:12 AM

Title: Problem Vb Script
Post by: jdmaya on November 21, 2012, 10:36:12 AM
Hello group.
I have the following code attached to a button:

If getuserled(1000)=0 Then
   setuserled(1000,1)
   avance = getuserdro(1000)
   If avance < 5 Then
      avance = 5
   End If
   
   If avance > 500 Then
      avance = 500
   End If
   
   porcentaje = avance/14
   setoemdro(3,porcentaje)
   setuserdro(1001,avance)
   jogon(0,1)
Else
   setuserled(1000,0)
   setuserled(1001,0)
   setuserdro(1001,getuserdro(1000))
   jogoff(0)
End If

when I run it step by step from the Vb Script editor the program works perfectly.
when I run the program from the button does not work.
which may be the problem?

thanks for the help.
Title: Re: Problem Vb Script
Post by: Ya-Nvr-No on November 21, 2012, 11:39:35 AM
I would think you need to let the screen update, so you need some way to pause the program like a Sleep(1000) command between set commands. That's why it works in single step, it has time to keep up with your keyboard.

or try a series of lines like this before the next set command.

While IsMoving ()
Sleep 100
Wend
Title: Re: Problem Vb Script
Post by: jdmaya on November 21, 2012, 12:51:14 PM
insert the code after the jogon(0,1) command, the program still does not work.
jogon(0,1)
while ismoving()
sleep 1000
wend.

Pressing the button lights the led, it updates the job slow, the jogon(0,1) command is not executed.
Title: Re: Problem Vb Script
Post by: Ya-Nvr-No on November 21, 2012, 12:55:31 PM
just try the sleep command there leave out the ...... while ismoving() wend
Title: Re: Problem Vb Script
Post by: ger21 on November 21, 2012, 05:51:09 PM
For User LED's, you need to use GetOEMLED() instead of GetUserLED(). SetUserLED() is correct.
I'd try it like this:

If Not GetOEMLED(1000) Then
  SetUserLED(1000,1)
   avance = getuserdro(1000)
   If avance < 5 Then
      avance = 5
   End If
   
   If avance > 500 Then
      avance = 500
   End If
   
   porcentaje = avance/14
   setoemdro(3,porcentaje)
 Sleep(125)
   setuserdro(1001,avance)
 Sleep(125)
   jogon(0,1)
Else
   setuserled(1000,0)
   setuserled(1001,0)
   setuserdro(1001,getuserdro(1000))
 Sleep(125)
   jogoff(0)
End If