Welcome, Guest. Please login or register.
Did you miss your activation email?
May 26, 2012, 09:07:32 PM

Login with username, password and session length
Search:     Advanced search
* Home Help Search Calendar Links Login Register
+  Machsupport Forum
|-+  Mach Discussion
| |-+  General Mach Discussion
| | |-+  VB Code On A Button Help Required
Pages: « 1 2   Go Down
Print
Author Topic: VB Code On A Button Help Required  (Read 591 times)
0 Members and 2 Guests are viewing this topic.
DaveCVI
V4 Screen Contributor

Offline Offline

Posts: 532



View Profile WWW
« Reply #10 on: August 28, 2010, 11:37:10 AM »

Phil,

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


Code:
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.


Dave
Logged

Author of the MachStdMill Extensions for Mach3
www.CalypsoVentures.com
stirling
Global Moderator
*
Offline Offline

Posts: 1,190

UK


View Profile WWW
« Reply #11 on: August 30, 2010, 06: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:
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:
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:
X_Distance = GetUserDRO ( 2011 )
Code "G01 X" & X_Distance & " F.10"
while isMoving()
  sleep 100
wend

Ian
Logged
Pages: « 1 2   Go Up
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!