Hello Guest it is December 26, 2024, 11:26:21 AM

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

0 Members and 1 Guest are viewing this topic.

VB Code On A Button Help Required
« on: August 27, 2010, 12:00:10 PM »
Mach version 3.42 on a lathe

I think these newer Mach versions are all Boolean and Double Bubble Trouble  ;D

I think anyone who knows what they are doing "Unlike Me" should be able to sort this mess out.

When i press the BUTTON nothing happens

X_Distance = GetUserDRO ( 2011 )
Code "G04 P.25"
Code "G01 X_Distance F.10"

Pretty Please
The Good Thing About Mach3, Is It's very Configurable

The Bad Thing About Mach3, Is It's Too Configurable

Offline ger21

*
  • *
  •  6,295 6,295
    • The CNC Woodworker
Re: VB Code On A Button Help Required
« Reply #1 on: August 27, 2010, 12:18:20 PM »
There may be two issues.
1) there's no Axis letter (X?)
2) I think the X_Dist needs to be converted into a string and combined into another string which would be the complete line.
Something like this, but I don't know the exact syntax, as I've never done this in Mach.

Movement = "G01 X" + cstr(X_Distance) + " F.10"
Code Movement
Gerry

2010 Screenset
http://www.thecncwoodworker.com/2010.html

JointCAM Dovetail and Box Joint software
http://www.g-forcecnc.com/jointcam.html
Re: VB Code On A Button Help Required
« Reply #2 on: August 27, 2010, 12:55:59 PM »
Thanks Gerry

Yes i can see how not having the axis letter could be a problem  ::)

I just tried fixing that and i got nothing

I tried all of your suggestion, but still nothing  :'(
The Good Thing About Mach3, Is It's very Configurable

The Bad Thing About Mach3, Is It's Too Configurable

Offline ger21

*
  • *
  •  6,295 6,295
    • The CNC Woodworker
Re: VB Code On A Button Help Required
« Reply #3 on: August 27, 2010, 01:15:41 PM »
I'm not 100% sure you can do it like I describe in Mach3.

Here's some info from the VB Manual. Looks like it should work. Maybe the CStr is case sensitive??

Quote
CStr(expression)
Converts any valid expression to a String.
Example:
Sub Main
Dim Y As Integer
Y = 25
Print Y
If VarType(Y) = 2 Then
X = CStr(Y) 'converts Y To a Str
X = X + "hello" 'It is now possible to combine Y with strings
Print X
End If
End Sub
Gerry

2010 Screenset
http://www.thecncwoodworker.com/2010.html

JointCAM Dovetail and Box Joint software
http://www.g-forcecnc.com/jointcam.html

Offline ger21

*
  • *
  •  6,295 6,295
    • The CNC Woodworker
Re: VB Code On A Button Help Required
« Reply #4 on: August 27, 2010, 01:37:03 PM »
Try:

 Code (Movement)
Gerry

2010 Screenset
http://www.thecncwoodworker.com/2010.html

JointCAM Dovetail and Box Joint software
http://www.g-forcecnc.com/jointcam.html
Re: VB Code On A Button Help Required
« Reply #5 on: August 27, 2010, 02:03:26 PM »
HI,
the string concatenation operator in basic is the "&"

instead of
Code "G01 X_Distance F.10"

you want
Code "G01 X" &  X_Distance & " F.10"

But that is not yet quite good enough as X_Distance can turn into a string that has exponents etc. within it...

To solve that, I have a little helper routine that I use for this:
Code: [Select]
Function GCN(ByVal VBNum) As String
' GCodeNumber: a small util to take a double, format it and return it as a string
' this is needed so that all numbers put into strings that will be sent to Code will not
' have things of the form: X0.123456e-9   - which is not legal gcode format
GCN = Format(VBNum, "#########0.000000") ' 6 sig digits to right of decimal point should be enough
End Function ' GCN
so I would have written the initial line as
Code "G01 X" &  GCN(X_Distance) & " F.10"

Dave
« Last Edit: August 27, 2010, 02:10:14 PM by DaveCVI »
Author of the MachStdMill Extensions for Mach3
www.CalypsoVentures.com

Offline ger21

*
  • *
  •  6,295 6,295
    • The CNC Woodworker
Re: VB Code On A Button Help Required
« Reply #6 on: August 27, 2010, 03:26:29 PM »
Quote
HI,
the string concatenation operator in basic is the "&"
The Cypress manual shows that it's "+" ??

+ also works in VBA.
Gerry

2010 Screenset
http://www.thecncwoodworker.com/2010.html

JointCAM Dovetail and Box Joint software
http://www.g-forcecnc.com/jointcam.html
Re: VB Code On A Button Help Required
« Reply #7 on: August 27, 2010, 04:20:01 PM »
Hi,
Yes, there's more than one way to skin the cat -

I use '&' for concatenation in basic and never use '+'. 
It's enough of a habit that I had forgotten that '+' also works (usually) as given in the Cypress manual page 39:
'+' or '&' can be used for string concatenation

I scratched my head and eventualy remembered why I got into that habit; '+' as it is also an arithmetic operator.
By using '&' instead of '+',  I don't have to worry about cypress attempting to add two numbers together...  The '+', '-' and '&' operators all are shown with the same operator precedence (page 40).
Rather than test and determine cypress's  actions for odd corner cases, I found it simpler to avoid the issue -

From page 8:
"If a string and a number are concatenated the result is a string. To be sure your concatenation works regardless of the data type involved use the & operator. The & will not perform arithmetic on your numeric values it will simply concatenate them as if they were strings."

Dave

Author of the MachStdMill Extensions for Mach3
www.CalypsoVentures.com
Re: VB Code On A Button Help Required
« Reply #8 on: August 27, 2010, 04:29:12 PM »
Dave & Gerry

Thank you for you help, i will try it out tomorrow and I'm sure it will work and i will report back
The Good Thing About Mach3, Is It's very Configurable

The Bad Thing About Mach3, Is It's Too Configurable
Re: VB Code On A Button Help Required
« Reply #9 on: August 28, 2010, 11:21:41 AM »

   GCN = Format(VBNum, "#########0.000000")      ' 6 sig digits to right of decimal point should be enough
Dave

Dave i tried with your helper but i got an error on the line in the quote

As i will be manually adding the number i will only have a max of two digits after the decimal

Here is the code

X_Distance = GetUserDRO ( 2011 )

Code "G04 P.25"

Code "G01 X" & (X_Distance)

I took away the feed rate in code so it runs at the the current feedrate in either G94 or G95 mode
The Good Thing About Mach3, Is It's very Configurable

The Bad Thing About Mach3, Is It's Too Configurable