Hello Guest it is November 30, 2020, 09:23:16 AM

Author Topic: VB Code On A Button Help Required  (Read 5266 times)

0 Members and 1 Guest are viewing this topic.

Re: VB Code On A Button Help Required
« Reply #10 on: August 28, 2010, 12:37:10 PM »

That's odd - below is a literal paste of a code fragment I just ran in mach to check -

Code: [Select]
Option Explicit
Dim X_Distance As Double

' entry point from mach
X_Distance = GetUserDRO (2011)

Code "G04 P.25"

MsgBox "hit OK to do " & Chr(13) &  "G01 X" & GCN(X_Distance)

Code "G01 X" & GCN(X_Distance)
Exit Sub

Function GCN(ByVal VBNum) As String
' GCodeNumber: a small util to take a VB double, format it and return it as a string
' this is needed so that all numbers ptu into strings that will be sent to CodeQ or CodeQW will not
' have things of the form: X0.123456e-9   - which is not legal gcode format
GCN = Format(VBNum, "#########0.00")
End Function ' GCN

Only difference was that I changed the format string to have only 2 digits to right of decimal as you requested.
I also added a debug msgbox just to see the string - looks fine, causes mach movement when the G01 is issued.

Note that I always use "option explicit" - that forces all variables to be declared before use.
This saves me from a typo creating a new variable of type variant on the fly. This should not make a difference to the code though.

Author of the MachStdMill Extensions for Mach3

Offline stirling

  • *
  •  2,188 2,188
  • UK
    • View Profile
    • www.razordance.co.uk
Re: VB Code On A Button Help Required
« Reply #11 on: August 30, 2010, 07:10:30 AM »
Guys - hope you don't mind me dropping in but there's no need for the conversions etc that you have going on. Exponent syntax is perfectly legal.

try this:

Code: [Select]
X_Distance = GetUserDRO ( 2011 )
Code "G04 P.25"
Code "G01 X" & X_Distance & " F.10"

Also you might want to take out thre Code "G04 P.25" as it serves no purpose so... try:

Code: [Select]
X_Distance = GetUserDRO ( 2011 )
Code "G01 X" & X_Distance & " F.10"

Of course depending on the following code (if any) you may need to add in a wait for the axis movement like:

Code: [Select]
X_Distance = GetUserDRO ( 2011 )
Code "G01 X" & X_Distance & " F.10"
while isMoving()
  sleep 100