Machsupport Forum
Mach Discussion => General Mach Discussion => Topic started by: jimpinder on September 21, 2007, 11:55:57 AM
-
Can somebody help me -
My machine is working fine. I am competant enough to write GCode to run it.
I have started to write Macros in Visual Basic - eg rough a bar down to a finished radius - putting in the start and finish radius in User DRO's, but the trouble with Macros is when you put them into Mach3 as, say , M204 or whatever, you cannot see the result on the toolpath generator - so it is a bit of pot luck when you run it.
What I wish to do is write my Visual Basic script, then have it output a file to a GCode file for Mach 3. When I pick up the GCode file in Mach 3 it will show me the tool path and I can go through all the checks before I run it.
I have the Vis Basic scripter writing to a file, using "Open....etc" Write#1 "etc etc" but Vis Basic also writes the inverted comas into the GCode, which Mach3 will not accept. What is the format to get Visual Basic writing to a file that is acceptable to Mach3, please !!!
-
Hi Jim - been a looooooooong time but - use Print instead of Write.
(to anyone - what - no FSO?)
-
Thanks for that, Stirling - I did try that, but it seemed as though I didn't get any output at all to the file.
I will try again, and come back.
-
Yes !! Just tried it with a "Quick brown fox" writing and printing - that does the trick.
Thanks Stirling.
-
Jim,
For what you are wanting to do, it is far, far, far, better to make yourself a "Wizard" and have it post the G code to your Mach control. If you download a copy of Screen3 you can then open up the current Wizards in lathe or mill and look at how people are doing just what your talking about!!!
I have one posted up here called "CNC Saw", you could open up that screen set in Screen3 and see an example, note cnc saw is a cnc control as opposed to wizard. You could also look under VB stuff and I posted up a Multithreading wizard for lathe, you could look at that for an example as well.
Scott
-
Thanks Scott - I'll have alook at that.
I think I went down the Visual Basic route because I have done a bit of computer programming in the past - and thats how I think.
One more question - to anybody - how do you name a subroutine is Vis Basic - and then call it.
It seems to be happy when I use CALL to call it, but I cannot work out how to name it.
-
somewehre in the body of your code put your call then your sub call below it.
Sub Main()
some code things
Call Subroutine_Name(perameters if any)
Sub Subroutine_Name(perameters if any)
your sub code here........
End Sub
Main
scott
-
the CALL statement isn't needed.
foo "hello"
bar
MsgBox mySquare(3)
Sub foo (s As String)
MsgBox s
End Sub
Sub bar()
MsgBox "in bar"
End Sub
Function mySquare(i As Integer) As Integer
mySquare=i*i
End Function
-
Thanks Gentlemen - I'll work on that !!!
Jim Pinder
-
No !! I am not having much sucess. I appear to have written it as has been suggested, in fact I think I have tried just about every combination, without success.
As soon as I start stepping through it, I get syntax error - usually with one of the "Sub" words highlighted.
Do subs need to be declared, as in some PIC chip syntax ???
I have attached my script, if anyone would mind having a look at it. Basically it turns a handrail stanchion from a piece of 10 mm bar (or any start diameter) - the inputs are from DRO on a page of Mach3 Turn I have ammended.
The maths might be a bit out, ( I don't think so, but until I get the syntax right, I can't check it.)
Jim Pinder
Any replies could come direct to jimpinder@tiscali.co.uk
-
Hi Jim
do while condition
statements
loop
missing an "end if"
last "End" keyword if used at all should come after the main code and before the subs. i.e.
main code statements
End
Subs
Me thinks maybe you're more used to C than this VB abomination :-)
-
also just noticed your presradius decrement is = instead of -
and
StartRadius never used and PresRadius never initialized
-
Speaking for my Dad :- Whoops!!!!! It was an eroor with while and wend...... I have now fixed it working okay...
-
Thanks Stirling - I was away yesterday, running the railway, and also thinking about it, and realised that I had not written the code correctly with while and wend, and if and end if and I wondered if that was where the fault lay. I telephoned my daughter who was also working on the same prog, and she sorted it - it works OK now.
Yes - Vis Basic is completely new - my last major brush with code was Pascal (some years ago) and recently some Microchip PIC chip programming for a signalling system.
The trouble is you are always playing catch-up. Still - Mach3 is first class, and has - and will - make a big difference to my engineering.
Jim
-
pleased you got it all sorted Jim. Yes VB/VB script - what can I say... it turned cat skinning into an art form ;D