Machsupport Forum

Mach Discussion => VB and the development of wizards => Topic started by: MachineMaster on March 18, 2009, 01:28:18 PM

Title: VB syntax
Post by: MachineMaster on March 18, 2009, 01:28:18 PM
OK, I'm new at this so I am askin for help. I printed out the Mach Script Language Reference, all 139 pages.
I now have a macro that I have written.

a = GetVar (500)
b = GetVar (501)
c = GetVar (502)
d = GetVar (503)

a= a+1
If a>9 Then b=b+1
If a>9 Then a=0

If b>9 Then c=c+1
If b>9 Then b=0

If c>9 Then d=d+1
If c>9 Then c=0   

Print " " &d &c &b &a
SetVar 500, a
SetVar 501, b
SetVar 502, c
SetVar 503, d
End

I had help writing it. The reason I am writing is this macro does what I need but no where in the 139 pages do I find
GetVar, SetVar or a reference to variables in the 500 - 600 range being persistent.
That leads me to think that the 139 pages that I printed are not what I should be studying.
Where do I find the REAL language reference?

Darrell
Title: Re: VB syntax
Post by: ger21 on March 18, 2009, 01:37:03 PM
http://www.machsupport.com/MachCustomizeWiki/index.php?title=Mach_specific_Subroutines/Functions_grouped_by_purpose
Title: Re: VB syntax
Post by: poppabear on March 18, 2009, 01:48:59 PM
note you have to put a "End If" to follow your If statements. i.e.

if a<(a+1) then
your code here
end if

scott
Title: Re: VB syntax
Post by: MachineMaster on March 18, 2009, 02:18:58 PM
Scot,
Do you mean an End If after every If statement or an End If after the last If statement in my code?
Title: Re: VB syntax
Post by: poppabear on March 18, 2009, 02:28:00 PM
after every if
Title: Re: VB syntax
Post by: ger21 on March 18, 2009, 03:29:15 PM
If it's on one line, you shouldn't need an End If. At least you don't in regular VB.
Title: Re: VB syntax
Post by: MachineMaster on March 18, 2009, 07:55:52 PM
Thanks for all the replies. I am still looking for a good language reference. The Wiki page mentioned does have information not in the Mach Script Language Reference but there still seems to be a lot missing. Most needed for me are actual examples.
I am still not sure if I am supposed to be looking for VB Scripting or VB Programming or is there a difference?
Is VB something I need to buy or is there a free version?
Programming Macros interests me a lot as I have been using AHHA software's built in macro language for years and this looks to have even more possibilities.
Title: Re: VB syntax
Post by: vmax549 on March 19, 2009, 09:59:54 PM
Darrel there is NOT alot published on the EXTRAS that were added in .  THere is a little in the Customising Mach manual that gives the very basics.

You just have to ask if you need to know something and HOPEFULLY someone has already figured out a way.  OR collectively we work on it to come up with a solution or two. (;-)

Hopefully someone creative willl come along and take ALL the post and sort through them and put them in a search engine type arrangement, then we may have a decent library of functions .

Just a thought, (;-) TP
Title: Re: VB syntax
Post by: MachineMaster on March 20, 2009, 03:11:31 PM
I have been unable to find any where the syntax for using variables in G code in a Macro.
I can declare a variable
V= GetVar (550)
and Print V will print the value that I have stored in 550 but if I use

V= GetVar (550)
Code "G90 G00 XV YV" or
Code "G90 G00 X&V Y&V"

it runs ok in the script window but Mach gives the error

No digits found where real number should be

What am I doing wrong?
Title: Re: VB syntax
Post by: ger21 on March 20, 2009, 03:26:47 PM
Try this:

Code "G90 G00 X " &V & " Y " &V
Title: Re: VB syntax
Post by: MachineMaster on March 20, 2009, 03:54:43 PM
I finally figured it out by just using one variable in one line of code until I got that to work and then added a second variable and worked at it until I got it to work. This is the result

V = GetVar (550)
V1 = V/2.
Code "G90 G92 X0. Y0."
Code "G01 X"&V1 & "Y"&V1
Code "G03 X.0 Y"&V & "I-"&V1 & "J.0 G90"
Code "G03 X.0 Y"&V & "I.0 J-"&V & "G90"
Code "G03 X-"&V1 & "Y"&V1 & "I.0 J-"&V1 & "G90"
Code "G01 G90 X.0 Y.0"
Code "G92.1"
End          

I had to get all of the quotes and &s in the right place.
The way it works is you put "&variable where the number would go and if there is more G code to follow on the same line it looks like this

Code "G01 X"&variable &"Y"&variable &"Z-.25"

There needs to be a space between variable and &"
Title: Re: VB syntax
Post by: MachineMaster on March 20, 2009, 03:56:41 PM
Looks like I was typing while you were posting. Your answer is exactly what I figured out.
Title: Re: VB syntax
Post by: poppabear on March 20, 2009, 06:03:41 PM
V = GetVar(550)
U = GetVar(551)

Code "G90 G00 X" & V & " Y" & U

'scott
Title: Re: VB syntax
Post by: vmax549 on March 20, 2009, 06:54:29 PM
OH boy that is going to be wicked to follow(;-) and sometimes MACH struggles badly with mixed code.

You could transfer the  VBvars over to Gcode vars and run in native gcode.

NOTE I don't thinkYou can run code such as   & "I.0 J-"&V1  Mach may  throw an error with the   "J-" not followed by a real number. You may have to convert the Var to a Neg number.

V = GetVar (550)
V1 = V/2.
Code "G90 G92 X0. Y0."
Code "G01 X"&V1 & "Y"&V1
Code "G03 X.0 Y"&V & "I-"&V1 & "J.0 G90"
Code "G03 X.0 Y"&V & "I.0 J-"&V & "G90"
Code "G03 X-"&V1 & "Y"&V1 & "I.0 J-"&V1 & "G90"
Code "G01 G90 X.0 Y.0"
Code "G92.1"
End         


This Type programming will run fine and not cause any MACH confusion(;-)


SetParam(1, GetVar (550))
SetParam(2,( 1/2))
Code "G90 G92 X0. Y0."
Code "G01 X[#2] Y[#2]"
Code "G03 X.0 Y[#1] I.0 J.0 G90"
Code "G03 X.0 Y[#1] I.0 J[-1*#1]G90"
Code "G03 X[-1*#2] Y[#2] I.0 J[-1*#2]G90"
Code "G01 G90 X.0 Y.0"
Code "G92.1"
End

(;-) TP         
Title: Re: VB syntax
Post by: poppabear on March 20, 2009, 07:29:50 PM
TP,

  SetParam is not the one you want, that is for setting machine parameters for motor tuning, etc.

you want:  SetVar(var#, value), and GetVar(var#)

these equate to the G Code  #parameter number.

I.e.    #6 = 10 written from G code or MDI
in VB, GetVar(6) would = 10

To set it, by VB would be: SetVar(6,12)  would set the G Code parameter 6 to value 12

you can check this in the VB scripter, and the "G code Var Monitor" window under "Operator" will also give the the value of that parameter/Var

scott
Title: Re: VB syntax
Post by: MachineMaster on March 20, 2009, 08:10:45 PM
Well I tried

GetVar (550)
SetVar(551,(550/2))
Code "G90 G92 X0. Y0."
Code "G01 X[#551] Y[#551]"
Code "G03 X.0 Y[#550] I.0 J.0 G90"
Code "G03 X.0 Y[#550] I.0 J[-1*#550]G90"
Code "G03 X[-1*#551] Y[#551] I.0 J[-1*#551]G90"
Code "G01 G90 X.0 Y.0"
Code "G92.1"
End   

and var #551 equaled 275 so I tried

v = GetVar (550)
v = v/2
SetVar(551,v)
Code "G90 G92 X0. Y0."
Code "G01 X[#551] Y[#551]"
Code "G03 X.0 Y[#550] I.0 J.0 G90"
Code "G03 X.0 Y[#550] I.0 J[-1*#550]G90"
Code "G03 X[-1*#551] Y[#551] I.0 J[-1*#551]G90"
Code "G01 G90 X.0 Y.0"
Code "G92.1"
End   

 and got the zero radius arc error  even though the var monitor shows that #551 was properly set.

so I tried just doing the
  
v = GetVar (550)
v = v/2
SetVar(551,v)
 in the M code and the rest in a G-code file

#550 = .5
G0G90X.25Y-.25
M79
G90 G92 X0. Y0."
G01 X[#551] Y[#551]"
G03 X.0 Y[#550] I.0 J.0 G90"
G03 X.0 Y[#550] I.0 J[-1*#550]G90"
G03 X[-1*#551] Y[#551] I.0 J[-1*#551]G90"
G01 G90 X.0 Y.0"
G92.1"

and still got the error. This code works

V = GetVar (550)
V1 = V/2.
Code "G90 G92 X0. Y0."
Code "G01 X"&V1 & "Y"&V1
Code "G03 X.0 Y"&V & "I-"&V1 & "J.0 G90"
Code "G03 X.0 Y"&V & "I.0 J-"&V & "G90"
Code "G03 X-"&V1 & "Y"&V1 & "I.0 J-"&V1 & "G90"
Code "G01 G90 X.0 Y.0"
Code "G92.1"
End 

and you call it from the G-code like this

#550 = .5
G0 G90 X.25 Y-.25
M79

It runs and does a nice hole milling cycle. #550 is set to the radius of the hole minus the radius of the tool.


Title: Re: VB syntax
Post by: vmax549 on March 20, 2009, 10:55:36 PM
As long as it works for YA go for it. (;-)


Now that I took the time to plot out exactly what you were doing(;-) Try this, it draws out the circle starting from the center point and does a small leadin arc CIRCLE and leadout arc then back to centerpoint.

Code"#550=.5"
Code"#551=[#550/2]"
Code"G90 G92 X0. Y0."
Code"G01 X[#551] Y[#551]"
Code"G03 X.0 Y[#550] I[-1* #551] J.0 G90"
Code"G03 X.0 Y[#550]I.0 J[-1*#550] G90"
Code"G03 X [-1*#551] Y[#551] I.0 J[-1*#551] G90"
Code"G01 G90 X.0 Y.0"
Code"G92.1"


YOu could also make the Macro programable for hole size and bit size By the use of Param1, Param2 to load the hole size and bit size into the macro or VARs on the fly

M500  P1.000 Q.250  (1.000" hole size, .250"bit)

Just another way to think about it, (;-) TP


PS:  We need to start a MACH TOOL BOX section to store all the neat code that shows up from time to time. (;-)
Title: Re: VB syntax
Post by: MachineMaster on March 21, 2009, 01:45:42 AM
The idea for this bit of code came from Bridgeport's G79 boring cycle. I took your code above and changed it to this

'M79.m1s
GetVar (550)
Code"#551=[#550/2]"
Code"G90 G92 X0. Y0."
Code"G01 X[#551] Y[#551]"
Code"G03 X.0 Y[#550] I[-1* #551] J.0 G90"
Code"G03 X.0 Y[#550]I.0 J[-1*#550] G90"
Code"G03 X [-1*#551] Y[#551] I.0 J[-1*#551] G90"
Code"G01 G90 X.0 Y.0"
Code"G92.1"
End

and it will bore any size hole by calling it like this

G0G90X1.Y1. (Position to hole center)
G01Z-.5 F10. (feed to depth)
#550 = 1.    (radius of hole-radius of tool)
M79
G0Z0

I use this code to bore multiple holes of different sizes in an enclosure.
Title: Re: VB syntax
Post by: vmax549 on March 21, 2009, 10:17:49 AM
OR you could make it programable like this



'M79.m1s
Setvar(550,Param1)
Code"#551=[#550/2]"
Code"G90 G92 X0. Y0."
Code"G01 X[#551] Y[#551]"
Code"G03 X.0 Y[#550] I[-1* #551] J.0 G90"
Code"G03 X.0 Y[#550]I.0 J[-1*#550] G90"
Code"G03 X [-1*#551] Y[#551] I.0 J[-1*#551] G90"
Code"G01 G90 X.0 Y.0"
Code"G92.1"
End

and it will bore any size hole by calling it like this

G0G90X1.Y1. (Position to hole center)
G01Z-.5 F10. (feed to depth)
M79 P1.000
G0Z0

Yep Parametric programing is FUN and can be very usefull . It would be nice to get a MACH collection of usefull macros. There are all type of macros out there for OTHER systems. There are macros to do serial numbers , engraving, elispes, facing, circles, squares, drill patterns. thread milling, TAPER thread milling, etc

 We have learned a few more unpublished mach tricks as well. Such as conditional programming inside Gcode with directional code. You can do the conditional part from a macro and from inside the macro you can redirect anywhere back inside the gcode by the use of a M98 call to the Oword in the gcode. Doing it this way allows you to move around inside the Gcode without the use of the M99(return). Also if you make the macro a simple phase it can be a generic programable macro that can be used many differrent ways.

M502 P3 Q1

' Macro.M1s
IF Param1 < Param2  Code" M98 P100"   The macro checks the condition of the statement and then redirects mach to the  O100 word in the Gcode file.

Note : mach limits us to ONLY 3 arguments doing it this way. It would be really NICE if we had a least 5 arguments instead of 3 OR 26 like is available in FANUC macroB

OF course you can always do it this way.

M502  #1=1 #2=2 #3=3 , etc  that way allows you as many var inputs as the single block will hold, It just looks UGLY .   

Just a thought, (;-) TP




Title: Re: VB syntax
Post by: poppabear on March 21, 2009, 10:25:48 AM
if you want you can "compact" your VB code if you want as well, for fun.
you have this:

v = GetVar (550)
v = v/2
SetVar(551,v)

Can be written like this:  

v = GetVar(550)/2
SetVar(551,v)

or

SetVar(551,(GetVar(550)/2))

'Nice Job on the Circle cycle too by the way!!!

'scott

Title: Re: VB syntax
Post by: poppabear on March 22, 2009, 10:14:56 AM
Jusst another side note:

you have to set the vars before you can use them.

you have this:

'M79.m1s
GetVar (550)
Code"#551=[#550/2]"

You need this:

'M79.m1s
Var1 = GetVar (550)
SetVar (551, (Var1/2))

'When ever you use a "Get" something, you have to set it = to something, OR, put the Get as the parameter of another function.
'for example

SetVar (551, (GetVar (550)/2))

'scott



Title: Re: VB syntax
Post by: MachineMaster on March 22, 2009, 11:50:50 AM
I think you may be missing the fact that

Code"#551=[#550/2]"

does set 551. In reality, I don't need

GetVar (550)

Variable 550 is set in the calling G-code and I could either set 551 as I am doing in the macro or with

#551=[#550/2]

in the G-code following the #550=  line.
Title: Re: VB syntax
Post by: MachineMaster on March 22, 2009, 04:21:03 PM
Hi

You appear to be confusing integers with strings and are showing a integer value within string quotes
The below is not strictly necessary but clearly shows the difference between the 2 types of data you are combining.
(   Str() converts an integer to a String and Val() does the reverse  )

Dim V As Double
Dim s1 As String

V= GetVar (550)

s1 = "G90 G00 X" &Str(V) & " Y" &Str(V)

Code s1

regards

Melee

Actually, when I first set V with

V= GetVar (550)

I am implicitly declaring V as Double. The same is true when I then set V1 with

V1=[V/2]

because the value being set is Double.
Title: Re: VB syntax
Post by: poppabear on March 22, 2009, 10:24:14 PM
Well all righty then, you got it all figured out then
Good luck

scott