Welcome, Guest. Please login or register.
Did you miss your activation email?
May 26, 2012, 09:07:15 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 1 Guest are viewing this topic.
M250cnc
Active Member

Offline Offline

Posts: 591




View Profile
« on: August 27, 2010, 11:00:10 AM »

Mach version 3.42 on a lathe

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

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
Logged

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

The Bad Thing About Mach3, Is It's Too Configurable
ger21
Global Moderator
*
Offline Offline

Posts: 2,616



View Profile WWW
« Reply #1 on: August 27, 2010, 11:18:20 AM »

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
Logged

M250cnc
Active Member

Offline Offline

Posts: 591




View Profile
« Reply #2 on: August 27, 2010, 11:55:59 AM »

Thanks Gerry

Yes i can see how not having the axis letter could be a problem  Roll Eyes

I just tried fixing that and i got nothing

I tried all of your suggestion, but still nothing  Cry
Logged

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

The Bad Thing About Mach3, Is It's Too Configurable
ger21
Global Moderator
*
Offline Offline

Posts: 2,616



View Profile WWW
« Reply #3 on: August 27, 2010, 12: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
Logged

ger21
Global Moderator
*
Offline Offline

Posts: 2,616



View Profile WWW
« Reply #4 on: August 27, 2010, 12:37:03 PM »

Try:

 Code (Movement)
Logged

DaveCVI
V4 Screen Contributor

Offline Offline

Posts: 532



View Profile WWW
« Reply #5 on: August 27, 2010, 01: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:
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, 01:10:14 PM by DaveCVI » Logged

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

Posts: 2,616



View Profile WWW
« Reply #6 on: August 27, 2010, 02:26:29 PM »

Quote
HI,
the string concatenation operator in basic is the "&"
The Cypress manual shows that it's "+" ??

+ also works in VBA.
Logged

DaveCVI
V4 Screen Contributor

Offline Offline

Posts: 532



View Profile WWW
« Reply #7 on: August 27, 2010, 03: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

Logged

Author of the MachStdMill Extensions for Mach3
www.CalypsoVentures.com
M250cnc
Active Member

Offline Offline

Posts: 591




View Profile
« Reply #8 on: August 27, 2010, 03: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
Logged

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

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

Offline Offline

Posts: 591




View Profile
« Reply #9 on: August 28, 2010, 10: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
Logged

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

The Bad Thing About Mach3, Is It's Too Configurable
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!