Machsupport Forum

Mach Discussion => General Mach Discussion => Topic started by: Deon Gerber on January 13, 2006, 03:58:07 PM

Title: Wizard and VB Script questions (Brian Barker)
Post by: Deon Gerber on January 13, 2006, 03:58:07 PM
Hi all

Art ......First question for you! Is there a way of adding a user field for naming the file that he will be busy with ,instead of using the default name inside the vb script in the wizard.

The other questions are for any other members that are willing to help!!
I am busy with a specialised wizard for my company's use, it consist of three different simple operations.This is operations we use every day but to different measurements.
I've made three different pages in Screen designer to set the measurements. They are almost without bugs when used separately.

Now my problem.........I would love to throw all three's G code
together when exiting from the posting from the wizard instead of taking time to copy and paste.

The little I know about VB and wizards come from looking at other and then trying on my own, so I don't know as much as it sounds like.

Can some one assist me in some sample VB to link to pages and operations together.

Any help will be greatly appreciated.
Thanks for a stunning forum.

Deon Gerber.
 ???
Title: Re: Wizard and VB Script questions (Brian Barker)
Post by: Brian Barker on January 13, 2006, 08:43:17 PM
Deon,
Thank you for the post!
On the screen you are going to need to have a button to make a new File and this will have the open teach file that you have been using.

when you would like to add to the program you can use the AppendTeachFile "File.tap" .
For now get this running with the file.tap and we will worry about changing the name of the file latter:) For an example please look at the Teach wizard.

Please see what that will do for you and we will go from there, I think this is going to be fun to get this running for you!
Title: Re: Wizard and VB Script questions (Brian Barker)
Post by: Deon Gerber on January 14, 2006, 07:12:38 AM
Hi Brian

Thanks for the time and effort in trying to help. I also downloaded the VBScript manual at machsupport.com. I will see how far I get before getting stuck and will then again give you a shout.

Thanks
Deon ;D
Title: Re: Wizard and VB Script questions (Brian Barker)
Post by: Brian Barker on January 14, 2006, 08:22:40 AM
Anytime! I just need to see where you are at before I start telling you what to do :)

There are no dumb questions, other than the one that you didn't ask!
Title: Re: Wizard and VB Script questions (Brian Barker)
Post by: Deon Gerber on January 14, 2006, 09:42:44 AM
Hi Brian

Well this is how I am doing so far. Here follow some snips of VB I am using wth comments next to them in brackets. The comments is not included in the script , Thye are there for you to see what I am up to.


OpenTeachFile "turn.tap"
CloseTeachFile                                          (Button for adding user file name)
call LoadTeachFile()

OpenTeachFile "turn.tap"
Call DoOEMbutton (2)                               (Selecting first operation) 

OpenTeachFile "turn.tap"
Code "G18 G40 G49 G90 G94 G80"         (Starting Code for first operation)
G0 X100Z150
Code "M3"

G0 X100Z150
Code "M5"
CloseTeachFile
Call LoadTeachFile()                                  (End and posting Code for first operation)
Call DoOEMbutton(1)
End Sub

OpenTeachFile  "turn.tap"
Call LoadTeachFile()                                  (Selecting second operation)
Call DoOEMButton (3)

call LoadTeachFile()
appendTeachFile "turn.tap"
G0 X100Z150                                             (Starting code for second operation)
Code "M3"

G0X100Z150
Code "M5"
Code "M30"
CloseTeachFile                                           (Ending and posting second operation)
Call LoadTeachFile
End Sub
Main

Well now for what is hapening when I run the wizard. At the moment there are no VB errors given when run.

1.   The script for the File name button seems to work but I can't see some physical evedence of that. Again I guese it only uses the name in the script . As you said we will look at giving a user to enter a name at a later stage.

2.   It looks like the second operation over writes the first operation when posting. Maybe my sequence or somthing els is wrong.

Please have a look and get me on the right track.

Thanks
Deon
Title: Re: Wizard and VB Script questions (Brian Barker)
Post by: Deon Gerber on January 14, 2006, 09:48:17 AM
Hi Brian

One other thing I noticed was that when going from the first to the second operation, the code and tool pathe dispay window of the second operation is empty .
The first operation are not displayed. Thats why I think it gets overwrited.

Thanks
Deon
Title: Re: Wizard and VB Script questions (Brian Barker)
Post by: Brian Barker on January 14, 2006, 10:25:30 AM
Try this :) as you can see I have changed "OpenTeachFile" to  "AppendTeachFile". you need one OpenTeachFile to start the file and after that you are going to stick everything on the end of the file.



OpenTeachFile "turn.tap"
CloseTeachFile                                          (Button for adding user file name)
call LoadTeachFile()

AppendTeachFile"turn.tap"
Call DoOEMbutton (2)                               (Selecting first operation)

AppendTeachFile "turn.tap"
Code "G18 G40 G49 G90 G94 G80"         (Starting Code for first operation)
G0 X100Z150
Code "M3"

G0 X100Z150
Code "M5"
CloseTeachFile
Call LoadTeachFile()                                  (End and posting Code for first operation)
Call DoOEMbutton(1)
End Sub

AppendTeachFile "turn.tap"
Call LoadTeachFile()                                  (Selecting second operation)
Call DoOEMButton (3)

call LoadTeachFile()
appendTeachFile "turn.tap"
G0 X100Z150                                             (Starting code for second operation)
Code "M3"

G0X100Z150
Code "M5"
Code "M30"
CloseTeachFile                                           (Ending and posting second operation)
Call LoadTeachFile
End Sub
Main

After you are all done with the file we are going to add a SAVE code button that will give you a chance to chnge the file name.
Title: Re: Wizard and VB Script questions (Brian Barker)
Post by: Deon Gerber on January 14, 2006, 11:54:12 AM
Hi Brian

You are a star. The Script runs like a dream adding everything together. Now last problem to solve.......The ability for the user to specify his own file name.

You must help because my head is full of holes solving the previous one.

Thanks
Deon
Title: Re: Wizard and VB Script questions (Brian Barker)
Post by: Brian Barker on January 14, 2006, 12:23:32 PM
Put this in a button :) This is going to make your head hurt ....

This should do it
Brian


Begin Dialog FILERENAME 15,42, 213, 62, "File Save"
  Text 20,12,60,12, "Enter File Name:"
  TextBox 84,12,100,12,  .EditBox_1
  OKButton 36,36,37,12
  CancelButton 136,36,37,12
End Dialog


Dim Dlg1 As FILERENAME
Dlg1.EditBox_1 = "*.tap"
Button = Dialog (Dlg1)
 If Button = 0 Then
    Exit Sub
 End If   
 Newfilename = "C:\Mach3\GCode\" + Dlg1.EditBox_1
 FileCopy "C:\Mach3\GCode\turn.tap", Newfilename 
 MsgBox ("File Saved to" &  Newfilename )
Title: Re: Wizard and VB Script questions (Brian Barker)
Post by: Deon Gerber on January 14, 2006, 12:51:52 PM
Hi Brian

Thanks for all the help. I realy do apreciate it. One last question befor I log of.

I have not as yet tried this but just for info , will it be possible to do safty alert with the ticker acros different pages in a wizard.

Thanks Again

Deon
Title: Re: Wizard and VB Script questions (Brian Barker)
Post by: Brian Barker on January 14, 2006, 12:54:44 PM
Sure just use the same userlable.

Hope that helps
Brian
Title: Re: Wizard and VB Script questions (Brian Barker)
Post by: Deon Gerber on January 14, 2006, 01:00:22 PM
Me again

The save button . Where do you normaly put this. At the start page or at the end page.

Thanks
Deon
Title: Re: Wizard and VB Script questions (Brian Barker)
Post by: Brian Barker on January 14, 2006, 01:15:58 PM
End page :)

Title: Re: Wizard and VB Script questions (Brian Barker)
Post by: Brian Barker on January 14, 2006, 09:26:45 PM
How are you doing with the Save file thing??? Did it work as you had hoped?
Title: Re: Wizard and VB Script questions (Brian Barker)
Post by: Deon Gerber on January 19, 2006, 04:23:07 PM
Hi Brian

Finally it looks like my logging problems solved. My firewall and cookies seem to have been the problem. Well back to our thread....
Yes the file save works very nice.

The following is a thread I posted on the Yahoo group. I haven't got a answer yet, so I will post it here as well.

I'm busy doing a wizard that consist of about nine (9) pages.
My current setup equals Mac 3 Lathe ver 00.46. Diameter mode.

On page three (3) I do a facing cut. I have a ticker set to warn of
a toolcrash........

If XStart < = StockDia then
setTicker 20, "******WARNING*****"
Exit Sub
End If

setTicker 20, ""

Diacheck = 1
If IsDiameter() = 1 Then
XEnd = XEnd / 2
XStart = XStart / 2
DiaCheck = 2
End If

When stepping into the program with VBScipt editor and moving the cursor over the following ,This is the value being displayed
XStart Value = 51 StockDia = 48
Diacheck = 2

On this page everything works fine without any VB errors.

On page 5 I've got a similar setup for a OD Cut.

I've got the same ticker setup with the same values, but on this page I get the ticker warning. In trying to solve this problem I ran
this script over and over in the VB Script Editor. I found that the value for diacheck gets displayed as 1 and then all X Values are
halved. This readings is intermediate, but I always get the same
ticker warning.

This is what brought up the Art Code 9991 error.

During the whole testing process nothing on my side gets altered or changed .All Mach3 setup values stay the same.It looks like the Diameter mode gets changed on the inside of Mach or something.

Hope you can help me with this.
 
One other thing........Will it be possible to pop up a warning box where the user can choose to carry on or abort instead of the ticker that just aborts the process. A scenario comes to mind for internal turning where you can turn inside the chuck body past the safe zone for external turning.

Thanks for all your help.
Regards
Deon
Title: Re: Wizard and VB Script questions (Brian Barker)
Post by: Brian Barker on January 19, 2006, 05:39:21 PM
If you are gettting an Art code I am going to have to have Art look at that... This is how I do the error checking in many of the scripts that I write, so if you could send me the code I will test it and see if there is some thing odd in it.

I can help you with a dialog box for the error, I will post it latter:)
Title: Re: Wizard and VB Script questions (Brian Barker)
Post by: Deon Gerber on January 20, 2006, 01:37:28 AM
Hi Brian

I mailed you the Script.

Thanks
Deon
Title: Re: Wizard and VB Script questions (Brian Barker)
Post by: Deon Gerber on January 20, 2006, 05:13:24 AM
Hi Brian

I've just tried something very weird. I took my laptop and made a fresh Mach3 install. I made sure Diameter mode was set and all other values is Zero in the DRO's. I restarted and opened VBScipt editor and copied the VB file from my other PC( Just the Script.doc page #5, not the  complete Wizard) into VBScript editor.

Now My guess is that if I step into the program all values should be 0. Right!!!      Well not quit ...........Everything shows 0 except for FaceEnd(UserDRO1084) value 57 and of coarse Diacheck value 1.

Diacheck should show 2............ It looks like the values are getting trapped in the script.........

What do you think.
Title: Re: Wizard and VB Script questions (Brian Barker)
Post by: Brian Barker on January 20, 2006, 06:37:32 AM
Why are you checking for Dia mode? This can't change as you are running the lathe. I will have a look at your code and see if I can figure out what you are up to :)
Title: Re: Wizard and VB Script questions (Brian Barker)
Post by: Brian Barker on January 20, 2006, 06:58:22 AM
I changed the < to > because the logic was not following the Error message... Other than that it is running very we here.

 If XStart >= StockDia Then
    setTicker 20, "************** Check XStart is Smaller than Stock Diameter  *************"
 Exit Sub
End If

If ZStart >= FaceEnd Then
    setTicker 20, "************** Check ZStart is Smaller than Face Surface *************"
Exit Sub
End If
Title: Re: Wizard and VB Script questions (Brian Barker)
Post by: Deon Gerber on January 20, 2006, 12:33:07 PM
Hi Brian

Let me try to explain what I am trying to do......

Material clamped in chuck.......Zero 10mm away from chuck
                                          OD of Stock = 50
                                    Length of Stock = 60

                 Tool Change Position = X100Z150

XStart (50) ZStart(60) is where my tool will go to after the tool change.
Now If I ignore XStart <= StockDia The command will be something like 

 G0 X49 Z59   Then I am going to crash!!!!!!!!

This is where the problem with DiaCheck also comes in .......If mach see DiaCheck as "1" XStart wil be divided by 2.

Now even if I enter XStart as 99 I will still get the error because devided by two it is 49.5 and will show as .......

XSrart(49.5) <= StockDia(50)     True or False. The same go's for the ZStart.....

You see this is realy getting screwed up now.
Title: Re: Wizard and VB Script questions (Brian Barker)
Post by: Brian Barker on January 20, 2006, 12:57:10 PM
I see!!! I think I know where you are going wrong. I will fix it and send it to you.
Title: Re: Wizard and VB Script questions (Brian Barker)
Post by: Deon Gerber on January 20, 2006, 03:43:49 PM
Hi Brian

Thanks ......

Can you just put something staight. I tried to get this cleared on the oyher forum but Art is very vague about this.
According to him there are only 254 UserDRO's and UserLED's. How are this implemented. I see in other wizards dro and led numbers like 1002 .....1098...... this is much higher than 254. Art tried to explain the implementation as ...1000,********* ,does mean you can start at 1000 and end at 1254.......

This is getting me in a knot.
Will UserDRO(1001) and UserLED(1001) clash or is this seen as two different OEMCodes. Both get spesified as OEMCODE 1001.

Do you get clashes of the same DRO numbers across different Wizards......Example UserDRO(1020) in a threading Wizard and UserDRO(1020) in another turn Wizard. If so I will have to go through all other wizards to see what has been used to see if I dont cross ref. I may sound a bit coo-coo but I have to know the nitty gritty to be sucsesfull in making a Wizard.

Thanks
Deon
Title: Re: Wizard and VB Script questions (Brian Barker)
Post by: Brian Barker on January 20, 2006, 04:25:18 PM
YES it is 1000 to 1254 in the dro range.

The UserDRO and OEM DRO are not the same thing... I know it is hard on the head...
Title: Re: Wizard and VB Script questions (Brian Barker)
Post by: Deon Gerber on January 21, 2006, 02:22:05 AM
So will it then be safe to say that UserDRO(1025) and UserLED(1025) will not clash in the same wizard........

And that UserDRO(1025) in the threading Wizard will not clash wth UserDRO(1025) in the Turn Wizard that I am busy making.
Title: Re: Wizard and VB Script questions (Brian Barker)
Post by: Brian Barker on January 21, 2006, 05:18:37 AM
Yes, I think you see how it works now :)
Title: Re: Wizard and VB Script questions (Brian Barker)
Post by: Deon Gerber on January 21, 2006, 03:42:52 PM
Hi Brian

It looks like I found away around my problem. The problem seems to be with the ticker. I REM'ed that specific one and the problem is gone. What I brought in as a safety device.......I have critical DRO's auto filled in by cross referencing to previous operations. This seems to work very well.(........Call SetUserDRO(1030,GetUserDRO(1084)+1)......)

Now How about that Dialog Box where the user can choose to validate or abort a setting.

Thanks a lot for your help.
Deon
Title: Re: Wizard and VB Script questions (Brian Barker)
Post by: Brian Barker on January 22, 2006, 09:23:24 AM
Try this in the script editor :)



X =1
y=3

Do While X<Y
Button = MsgBox("Dia must be smaller! Would you like to change it???",4,"Lathe program error...")
If Button = 7 Then
Exit Sub
End If
X = Question("Enter New Stock DIA")
Loop
Title: Re: Wizard and VB Script questions (Brian Barker)
Post by: Deon Gerber on January 23, 2006, 02:28:48 AM
Hi Brian

First of all thanks for all your effort and patience in some of the silly questions I am asking. I really do appreciate it.

I tried the dialog box. The way it is presented is what I have in mind......The only change I would like is for the answer this box, I would like the answer field to be a bit longer so that you can work with more characters than a one.

The implementation though is not there yet. I need it to ignore the warning if you choose to. At the moment it loops and comes up again if you want to carry on. When choose to change a setting it does not update and also continue to loop.

Hope you understand what I am getting at.

Thanks
Deon
Title: Re: Wizard and VB Script questions (Brian Barker)
Post by: Brian Barker on January 23, 2006, 08:32:08 AM
I can fit 123456789 in the box and if you keep typing it will hold MUCH more...

Also if you would like it to just keep going take out the do while loop and change the If like this:

X =1
y=3

If  X<Y Then
    Button = MsgBox("Dia must be smaller! Would you like to change it???",4,"Lathe program error...")
   If Button = 6 Then
   X = Question("Enter New Stock DIA")
   End If
End If


I think that is what you are looking for.
Title: Re: Wizard and VB Script questions (Brian Barker)
Post by: Deon Gerber on January 23, 2006, 09:40:06 AM
Hi Brian

I am so sorry about my ignorant comment about the size of the input field, I just had a quick look at it this morning. I don't mean to be full of crap. It seems like I was still asleep.
I do apologise.

Thanks
Deon
Title: Re: Wizard and VB Script questions (Brian Barker)
Post by: Brian Barker on January 23, 2006, 10:38:45 AM
No problem I do it all the time :)

How is the new logic working for you?
Title: Re: Wizard and VB Script questions (Brian Barker)
Post by: Deon Gerber on January 23, 2006, 12:33:16 PM
Hi Brian

Well I am so glad to see you are a softy at heart that can look beyond someone else's mistakes .......THANKS.

I am still busy figuring it out.......I managed to sort out the YES Button. It now allows me change a field.... then it auto updates that DRO and carry on with the processing of the script.

I have not been successful with the NO button as yet, but I am working on it. At the moment it is aborting the processing of the script. What I am actually trying to accomplish is for it to cancel the warning and to continue with processing the script.
This is what I added to auto update the DRO.


If  Tool = 0 Then
    Button = MsgBox("Possible wrong Tool!!!!! Would you like to change it???",4,"Lathe program error...")
   If Button = 7 Then
   Exit Sub
   End If
   X = Question("Enter New Tool Number")
   Call SetUserDRO(1092,X)
   End If
   If Button = 6 Then
   End If

This is how far I am but I will keep on trying until I crack it.

Will let you know when I succeed.

Thanks
Deon

Title: Re: Wizard and VB Script questions (Brian Barker)
Post by: Brian Barker on January 23, 2006, 08:43:25 PM
Here you are:

If  Tool = 0 Then
    Button = MsgBox("Possible wrong Tool!!!!! Would you like to change it???",4,"Lathe program error...")
   If Button = 6 Then 'Button = 6 when you press the "yes" button
   X = Question("Enter New Tool Number")
   Call SetUserDRO(1092,X)
End If
Title: Re: Wizard and VB Script questions (Brian Barker)
Post by: Deon Gerber on January 24, 2006, 03:09:38 AM
Hi Brian

EUREKA!!!!!!! Finally I think I've cracked it. I tried yours but it gave me a script error not on your part but right at the end of the complete script......End Sub. I'm not sure why?

In playing and shuffling it around I managed to get it working as I want it to. This is the changes I made......It may be a longer way or not a standard way but it works!!!!!!!

If  Tool = 0 Then
    Button = MsgBox("Possible wrong Tool!!!!! Would you like to change it???",4,"Lathe program error...")
   If Button = 7 Then
   End If
   If Button = 6 Then
   X = Question("Enter New Tool Number")
   Call SetUserDRO(1092,X)
   End If
End If


Just a word of encouragement to all out there that really would like to try his hand at making his own wizard, please go ahead and try.
Have a look at other wizards and try. It really is fun and satisfying. Like they say ,if at first you fail, try and try again.

There will always be someone on the forum willing to help. I personally knew nothing when I started out.

Once again Brian Thanks for the patience and help. Talk to you again soon.

Deon