Changes 20110728

20110728

Also reference

This improvement iteration is to

Hardware:

- Bump centering of selected parts
- Fix offset machining of original lead screws

Software:

- Add right side heads & feeder bank to:
   - Excel GCode generator
   - Mach 3 VB dialogs

- Not all heads can reach all Feeders on the same side, added conditional formatting to excel to highlight incompatible combinations
   -HL3: FL9-25
   -HL2: FL5-23
   -HL1: FL2-21
   -HL0: FL1-18
   -HR3: FR7-25
   -HR2: FR5-23
   -HR1: FR3-21
   -HR0: FR1-19

- Add bump centering to Excel GCode generator
   - Add footprint column to each feeder entry
   - New worksheet 'footprints'

- Split Mach 3 VB dialog into separate dialogs
   - main
   - calibrate feeders
   - calibrate heads

mach3-vb-maindialog-201106.PNG  mach3-vb-calibrateheadsdialog-20110728.PNG  mach3-vb-calibratefeedersdialog-20110728.PNG 


 

Into the Excel GCode generator spreadsheet goes additional rows per right side heads, and right side feeders, adjust the named ranges and revise the column constants and thats it.

Mach 3 Dialog Cyprus VB:

Option Explicit

'20110728

Const G59BaseAddrX = 5221
Const G59BaseAddrY = 5222
Const G59AddrIncrement = 20
Const G59Rot0PCB1 = 50
Const G59Rot90PCB1 = 100
Const G59Rot180PCB1 = 150
Const G59Rot270PCB1 = 200

Const FeederGCodeBaseVarComponentsRequired = 100
Const FeederGCodeBaseVarComponentsMax = 200

Const FeederGCodeBaseVarX = 300
Const FeederGCodeBaseVarY = 400

Const HeadGCodeBaseVarX = 1000
Const HeadGCodeBaseVarY = 1020

Const HeadGCodeBaseVarSmallBumpLeftX = 1100
Const HeadGCodeBaseVarSmallBumpRightX = 1120
Const HeadGCodeBaseVarSmallBumpTopY = 1140
Const HeadGCodeBaseVarSmallBumpBottomY = 1160

Const HeadGCodeBaseVarLargeBumpLeftX = 1200
Const HeadGCodeBaseVarLargeBumpRightX = 1220
Const HeadGCodeBaseVarLargeBumpTopY = 1240
Const HeadGCodeBaseVarLargeBumpBottomY = 1260

'Dialog return values
Dim returnMain
Dim returnCalibrateFeeders
Dim returnCalibrateHeads

Dim strTemp

'State machine as can't get nested dialogs to work
Dim currentDialog
Const currentDialogIsMain = 1
Const currentDialogIsCalibrateFeeders = 2
Const currentDialogIsCalibrateHeads = 3
Const currentDialogIsNone = 10

Sub Main

    Begin Dialog dlgCalibrateFeeders 510, 400, "Feeder calibration", .dialogCalibrateFeeders

        Text 10, 20, 35, 10, "FL25"
        Text 10, 30, 35, 10, "FL24"
        Text 10, 40, 35, 10, "FL23"
        Text 10, 50, 35, 10, "FL22"
        Text 10, 60, 35, 10, "FL21"
        Text 10, 70, 35, 10, "FL20"
        Text 10, 80, 35, 10, "FL19"
        Text 10, 90, 35, 10, "FL18"
        Text 10, 100, 35, 10, "FL17"
        Text 10, 110, 35, 10, "FL16"
        Text 10, 120, 35, 10, "FL15"
        Text 10, 130, 35, 10, "FL14"
        Text 10, 140, 35, 10, "FL13"
        Text 10, 150, 35, 10, "FL12"
        Text 10, 160, 35, 10, "FL11"
        Text 10, 170, 35, 10, "FL10"
        Text 10, 180, 35, 10, "FL9"
        Text 10, 190, 35, 10, "FL8"
        Text 10, 200, 35, 10, "FL7"
        Text 10, 210, 35, 10, "FL6"
        Text 10, 220, 35, 10, "FL5"
        Text 10, 230, 35, 10, "FL4"
        Text 10, 240, 35, 10, "FL3"
        Text 10, 250, 35, 10, "FL2"
        Text 10, 260, 35, 10, "FL1"
        
        Text 260, 20, 35, 10, "FR25"
        Text 260, 30, 35, 10, "FR24"
        Text 260, 40, 35, 10, "FR23"
        Text 260, 50, 35, 10, "FR22"
        Text 260, 60, 35, 10, "FR21"
        Text 260, 70, 35, 10, "FR20"
        Text 260, 80, 35, 10, "FR19"
        Text 260, 90, 35, 10, "FR18"
        Text 260, 100, 35, 10, "FR17"
        Text 260, 110, 35, 10, "FR16"
        Text 260, 120, 35, 10, "FR15"
        Text 260, 130, 35, 10, "FR14"
        Text 260, 140, 35, 10, "FR13"
        Text 260, 150, 35, 10, "FR12"
        Text 260, 160, 35, 10, "FR11"
        Text 260, 170, 35, 10, "FR10"
        Text 260, 180, 35, 10, "FR9"
        Text 260, 190, 35, 10, "FR8"
        Text 260, 200, 35, 10, "FR7"
        Text 260, 210, 35, 10, "FR6"
        Text 260, 220, 35, 10, "FR5"
        Text 260, 230, 35, 10, "FR4"
        Text 260, 240, 35, 10, "FR3"
        Text 260, 250, 35, 10, "FR2"
        Text 260, 260, 35, 10, "FR1"

        Text 40, 10, 20, 10, "Goto?"
        PushButton 40, 20, 150, 10, "Goto", .btnGotoFeeder25
        PushButton 40, 30, 150, 10, "Goto", .btnGotoFeeder24
        PushButton 40, 40, 150, 10, "Goto", .btnGotoFeeder23
        PushButton 40, 50, 150, 10, "Goto", .btnGotoFeeder22
        PushButton 40, 60, 150, 10, "Goto", .btnGotoFeeder21
        PushButton 40, 70, 150, 10, "Goto", .btnGotoFeeder20
        PushButton 40, 80, 150, 10, "Goto", .btnGotoFeeder19
        PushButton 40, 90, 150, 10, "Goto", .btnGotoFeeder18
        PushButton 40, 100, 150, 10, "Goto", .btnGotoFeeder17
        PushButton 40, 110, 150, 10, "Goto", .btnGotoFeeder16
        PushButton 40, 120, 150, 10, "Goto", .btnGotoFeeder15
        PushButton 40, 130, 150, 10, "Goto", .btnGotoFeeder14
        PushButton 40, 140, 150, 10, "Goto", .btnGotoFeeder13
        PushButton 40, 150, 150, 10, "Goto", .btnGotoFeeder12
        PushButton 40, 160, 150, 10, "Goto", .btnGotoFeeder11
        PushButton 40, 170, 150, 10, "Goto", .btnGotoFeeder10
        PushButton 40, 180, 150, 10, "Goto", .btnGotoFeeder9
        PushButton 40, 190, 150, 10, "Goto", .btnGotoFeeder8
        PushButton 40, 200, 150, 10, "Goto", .btnGotoFeeder7
        PushButton 40, 210, 150, 10, "Goto", .btnGotoFeeder6
        PushButton 40, 220, 150, 10, "Goto", .btnGotoFeeder5
        PushButton 40, 230, 150, 10, "Goto", .btnGotoFeeder4
        PushButton 40, 240, 150, 10, "Goto", .btnGotoFeeder3
        PushButton 40, 250, 150, 10, "Goto", .btnGotoFeeder2
        PushButton 40, 260, 150, 10, "Goto", .btnGotoFeeder1
        
        Text 290, 10, 20, 10, "Goto?"
        PushButton 290, 20, 150, 10, "Goto", .btnGotoFeeder50
        PushButton 290, 30, 150, 10, "Goto", .btnGotoFeeder49
        PushButton 290, 40, 150, 10, "Goto", .btnGotoFeeder48
        PushButton 290, 50, 150, 10, "Goto", .btnGotoFeeder47
        PushButton 290, 60, 150, 10, "Goto", .btnGotoFeeder46
        PushButton 290, 70, 150, 10, "Goto", .btnGotoFeeder45
        PushButton 290, 80, 150, 10, "Goto", .btnGotoFeeder44
        PushButton 290, 90, 150, 10, "Goto", .btnGotoFeeder43
        PushButton 290, 100, 150, 10, "Goto", .btnGotoFeeder42
        PushButton 290, 110, 150, 10, "Goto", .btnGotoFeeder41
        PushButton 290, 120, 150, 10, "Goto", .btnGotoFeeder40
        PushButton 290, 130, 150, 10, "Goto", .btnGotoFeeder39
        PushButton 290, 140, 150, 10, "Goto", .btnGotoFeeder38
        PushButton 290, 150, 150, 10, "Goto", .btnGotoFeeder37
        PushButton 290, 160, 150, 10, "Goto", .btnGotoFeeder36
        PushButton 290, 170, 150, 10, "Goto", .btnGotoFeeder35
        PushButton 290, 180, 150, 10, "Goto", .btnGotoFeeder34
        PushButton 290, 190, 150, 10, "Goto", .btnGotoFeeder33
        PushButton 290, 200, 150, 10, "Goto", .btnGotoFeeder32
        PushButton 290, 210, 150, 10, "Goto", .btnGotoFeeder31
        PushButton 290, 220, 150, 10, "Goto", .btnGotoFeeder30
        PushButton 290, 230, 150, 10, "Goto", .btnGotoFeeder29
        PushButton 290, 240, 150, 10, "Goto", .btnGotoFeeder28
        PushButton 290, 250, 150, 10, "Goto", .btnGotoFeeder27
        PushButton 290, 260, 150, 10, "Goto", .btnGotoFeeder26

        Text 200, 10, 20, 15, "Origin?"
        PushButton 200, 20, 30, 10, "Set", .btnSetFeeder25
        PushButton 200, 30, 30, 10, "Set", .btnSetFeeder24
        PushButton 200, 40, 30, 10, "Set", .btnSetFeeder23
        PushButton 200, 50, 30, 10, "Set", .btnSetFeeder22
        PushButton 200, 60, 30, 10, "Set", .btnSetFeeder21
        PushButton 200, 70, 30, 10, "Set", .btnSetFeeder20
        PushButton 200, 80, 30, 10, "Set", .btnSetFeeder19
        PushButton 200, 90, 30, 10, "Set", .btnSetFeeder18
        PushButton 200, 100, 30, 10, "Set", .btnSetFeeder17
        PushButton 200, 110, 30, 10, "Set", .btnSetFeeder16
        PushButton 200, 120, 30, 10, "Set", .btnSetFeeder15
        PushButton 200, 130, 30, 10, "Set", .btnSetFeeder14
        PushButton 200, 140, 30, 10, "Set", .btnSetFeeder13
        PushButton 200, 150, 30, 10, "Set", .btnSetFeeder12
        PushButton 200, 160, 30, 10, "Set", .btnSetFeeder11
        PushButton 200, 170, 30, 10, "Set", .btnSetFeeder10
        PushButton 200, 180, 30, 10, "Set", .btnSetFeeder9
        PushButton 200, 190, 30, 10, "Set", .btnSetFeeder8
        PushButton 200, 200, 30, 10, "Set", .btnSetFeeder7
        PushButton 200, 210, 30, 10, "Set", .btnSetFeeder6
        PushButton 200, 220, 30, 10, "Set", .btnSetFeeder5
        PushButton 200, 230, 30, 10, "Set", .btnSetFeeder4
        PushButton 200, 240, 30, 10, "Set", .btnSetFeeder3
        PushButton 200, 250, 30, 10, "Set", .btnSetFeeder2
        PushButton 200, 260, 30, 10, "Set", .btnSetFeeder1
        
        Text 450, 10, 20, 15, "Origin?"
        PushButton 450, 20, 30, 10, "Set", .btnSetFeeder50
        PushButton 450, 30, 30, 10, "Set", .btnSetFeeder49
        PushButton 450, 40, 30, 10, "Set", .btnSetFeeder48
        PushButton 450, 50, 30, 10, "Set", .btnSetFeeder47
        PushButton 450, 60, 30, 10, "Set", .btnSetFeeder46
        PushButton 450, 70, 30, 10, "Set", .btnSetFeeder45
        PushButton 450, 80, 30, 10, "Set", .btnSetFeeder44
        PushButton 450, 90, 30, 10, "Set", .btnSetFeeder43
        PushButton 450, 100, 30, 10, "Set", .btnSetFeeder42
        PushButton 450, 110, 30, 10, "Set", .btnSetFeeder41
        PushButton 450, 120, 30, 10, "Set", .btnSetFeeder40
        PushButton 450, 130, 30, 10, "Set", .btnSetFeeder39
        PushButton 450, 140, 30, 10, "Set", .btnSetFeeder38
        PushButton 450, 150, 30, 10, "Set", .btnSetFeeder37
        PushButton 450, 160, 30, 10, "Set", .btnSetFeeder36
        PushButton 450, 170, 30, 10, "Set", .btnSetFeeder35
        PushButton 450, 180, 30, 10, "Set", .btnSetFeede34
        PushButton 450, 190, 30, 10, "Set", .btnSetFeede33
        PushButton 450, 200, 30, 10, "Set", .btnSetFeede32
        PushButton 450, 210, 30, 10, "Set", .btnSetFeede31
        PushButton 450, 220, 30, 10, "Set", .btnSetFeede30
        PushButton 450, 230, 30, 10, "Set", .btnSetFeeder29
        PushButton 450, 240, 30, 10, "Set", .btnSetFeeder28
        PushButton 450, 250, 30, 10, "Set", .btnSetFeeder27
        PushButton 450, 260, 30, 10, "Set", .btnSetFeeder26

        OkButton 410, 290, 70, 10

    End Dialog

    Begin Dialog dlgCalibrateHeads 510, 420, "Head calibration", .dialogCalibrateHeads

        Text 10, 20, 200, 10,  "HL3", .HL3
        PushButton 10, 30, 30, 10, "Go G55", .btnGotoG55HL3
        PushButton 10, 40, 30, 10, "Go G56", .btnGotoG56HL3
        PushButton 40, 30, 20, 10, "Set", .btnSetG55HL3
        PushButton 40, 40, 20, 10, "Set", .btnSetG56HL3
        Text 80, 30, 50, 10,  "Small bump"
        PushButton 130, 30, 30, 10, "Go G58", .btnHL3GoSmallBumpTOP
        PushButton 160, 30, 20, 10, "Set", .btnHL3SetSmallBumpTOP
        PushButton 180, 40, 30, 10, "Go G58", .btnHL3GoSmallBumpRIGHT
        PushButton 210, 40, 20, 10, "Set", .btnHL3SetSmallBumpRIGHT
        PushButton 80, 40, 30, 10, "Go G58", .btnHL3GoSmallBumpLEFT
        PushButton 110, 40, 20, 10, "Set", .btnHL3SetSmallBumpLEFT
        PushButton 130, 50, 30, 10, "Go G58", .btnHL3GoSmallBumpBOTTOM
        PushButton 160, 50, 20, 10, "Set", .btnHL3SetSmallBumpBOTTOM
        Text 80, 70, 50, 10,  "Large bump"
        PushButton 130, 70, 30, 10, "Go G58", .btnHL3GoLargeBumpTOP
        PushButton 160, 70, 20, 10, "Set", .btnHL3SetLargeBumpTOP
        PushButton 180, 80, 30, 10, "Go G58", .btnHL3GoLargeBumpRIGHT
        PushButton 210, 80, 20, 10, "Set", .btnHL3SetLargeBumpRIGHT
        PushButton 80, 80, 30, 10, "Go G58", .btnHL3GoLargeBumpLEFT
        PushButton 110, 80, 20, 10, "Set", .btnHL3SetLargeBumpLEFT
        PushButton 130, 90, 30, 10, "Go G58", .btnHL3GoLargeBumpBOTTOM
        PushButton 160, 90, 20, 10, "Set", .btnHL3SetLargeBumpBOTTOM
        
        Text 270, 20, 200, 10,  "HR3", .HR3
        PushButton 270, 30, 30, 10, "Go G55", .btnGotoG55HR3
        PushButton 270, 40, 30, 10, "Go G57", .btnGotoG57HR3
        PushButton 300, 30, 20, 10, "Set", .btnSetG55HR3
        PushButton 300, 40, 20, 10, "Set", .btnSetG57HR3
        Text 340, 30, 50, 10,  "Small bump"
        PushButton 390, 30, 30, 10, "Go G58", .btnHR3GoSmallBumpTOP
        PushButton 420, 30, 20, 10, "Set", .btnHR3SetSmallBumpTOP
        PushButton 440, 40, 30, 10, "Go G58", .btnHR3GoSmallBumpRIGHT
        PushButton 470, 40, 20, 10, "Set", .btnHR3SetSmallBumpRIGHT
        PushButton 340, 40, 30, 10, "Go G58", .btnHR3GoSmallBumpLEFT
        PushButton 370, 40, 20, 10, "Set", .btnHR3SetSmallBumpLEFT
        PushButton 390, 50, 30, 10, "Go G58", .btnHR3GoSmallBumpBOTTOM
        PushButton 420, 50, 20, 10, "Set", .btnHR3SetSmallBumpBOTTOM
        Text 340, 70, 50, 10,  "Large bump"
        PushButton 390, 70, 30, 10, "Go G58", .btnHR3GoLargeBumpTOP
        PushButton 420, 70, 20, 10, "Set", .btnHR3SetLargeBumpTOP
        PushButton 440, 80, 30, 10, "Go G58", .btnHR3GoLargeBumpRIGHT
        PushButton 470, 80, 20, 10, "Set", .btnHR3SetLargeBumpRIGHT
        PushButton 340, 80, 30, 10, "Go G58", .btnHR3GoLargeBumpLEFT
        PushButton 370, 80, 20, 10, "Set", .btnHR3SetLargeBumpLEFT
        PushButton 390, 90, 30, 10, "Go G58", .btnHR3GoLargeBumpBOTTOM
        PushButton 420, 90, 20, 10, "Set", .btnHR3SetLargeBumpBOTTOM
        
        Text 10, 110, 200, 10,  "HL2", .HL2
        PushButton 10, 120, 30, 10, "Go G55", .btnGotoG55HL2
        PushButton 10, 130, 30, 10, "Go G56", .btnGotoG56HL2
        PushButton 40, 120, 20, 10, "Set", .btnSetG55HL2
        PushButton 40, 130, 20, 10, "Set", .btnSetG56HL2
        Text 80, 120, 50, 10,  "Small bump"
        PushButton 130, 120, 30, 10, "Go G58", .btnHL2GoSmallBumpTOP
        PushButton 160, 120, 20, 10, "Set", .btnHL2SetSmallBumpTOP
        PushButton 180, 130, 30, 10, "Go G58", .btnHL2GoSmallBumpRIGHT
        PushButton 210, 130, 20, 10, "Set", .btnHL2SetSmallBumpRIGHT
        PushButton 80, 130, 30, 10, "Go G58", .btnHL2GoSmallBumpLEFT
        PushButton 110, 130, 20, 10, "Set", .btnHL2SetSmallBumpLEFT
        PushButton 130, 140, 30, 10, "Go G58", .btnHL2GoSmallBumpBOTTOM
        PushButton 160, 140, 20, 10, "Set", .btnHL2SetSmallBumpBOTTOM
        Text 80, 160, 50, 10,  "Large bump"
        PushButton 130, 160, 30, 10, "Go G58", .btnHL2GoLargeBumpTOP
        PushButton 160, 160, 20, 10, "Set", .btnHL2SetLargeBumpTOP
        PushButton 180, 170, 30, 10, "Go G58", .btnHL2GoLargeBumpRIGHT
        PushButton 210, 170, 20, 10, "Set", .btnHL2SetLargeBumpRIGHT
        PushButton 80, 170, 30, 10, "Go G58", .btnHL2GoLargeBumpLEFT
        PushButton 110, 170, 20, 10, "Set", .btnHL2SetLargeBumpLEFT
        PushButton 130, 180, 30, 10, "Go G58", .btnHL2GoLargeBumpBOTTOM
        PushButton 160, 180, 20, 10, "Set", .btnHL2SetLargeBumpBOTTOM
        
        Text 270, 110, 200, 10,  "HR2", .HR2
        PushButton 270, 120, 30, 10, "Go G55", .btnGotoG55HR2
        PushButton 270, 130, 30, 10, "Go G57", .btnGotoG57HR2
        PushButton 300, 120, 20, 10, "Set", .btnSetG55HR2
        PushButton 300, 130, 20, 10, "Set", .btnSetG57HR2
        Text 340, 120, 50, 10,  "Small bump"
        PushButton 390, 120, 30, 10, "Go G58", .btnHR2GoSmallBumpTOP
        PushButton 420, 120, 20, 10, "Set", .btnHR2SetSmallBumpTOP
        PushButton 440, 130, 30, 10, "Go G58", .btnHR2GoSmallBumpRIGHT
        PushButton 470, 130, 20, 10, "Set", .btnHR2SetSmallBumpRIGHT
        PushButton 340, 130, 30, 10, "Go G58", .btnHR2GoSmallBumpLEFT
        PushButton 370, 130, 20, 10, "Set", .btnHR2SetSmallBumpLEFT
        PushButton 390, 140, 30, 10, "Go G58", .btnHR2GoSmallBumpBOTTOM
        PushButton 420, 140, 20, 10, "Set", .btnHR2SetSmallBumpBOTTOM
        Text 340, 160, 140, 10,  "Large bump"
        PushButton 390, 160, 30, 10, "Go G58", .btnHR2GoLargeBumpTOP
        PushButton 420, 160, 20, 10, "Set", .btnHR2SetLargeBumpTOP
        PushButton 440, 170, 30, 10, "Go G58", .btnHR2GoLargeBumpRIGHT
        PushButton 470, 170, 20, 10, "Set", .btnHR2SetLargeBumpRIGHT
        PushButton 340, 170, 30, 10, "Go G58", .btnHR2GoLargeBumpLEFT
        PushButton 370, 170, 20, 10, "Set", .btnHR2SetLargeBumpLEFT
        PushButton 390, 180, 30, 10, "Go G58", .btnHR2GoLargeBumpBOTTOM
        PushButton 420, 180, 20, 10, "Set", .btnHR2SetLargeBumpBOTTOM
        
        Text 10, 200, 200, 10,  "HL1", .HL1
        PushButton 10, 210, 30, 10, "Go G55", .btnGotoG55HL1
        PushButton 10, 220, 30, 10, "Go G56", .btnGotoG56HL1
        PushButton 40, 210, 20, 10, "Set", .btnSetG55HL1
        PushButton 40, 220, 20, 10, "Set", .btnSetG56HL1
        Text 80, 210, 50, 10,  "Small bump"
        PushButton 130, 210, 30, 10, "Go G58", .btnHL1GoSmallBumpTOP
        PushButton 160, 210, 20, 10, "Set", .btnHL1SetSmallBumpTOP
        PushButton 180, 220, 30, 10, "Go G58", .btnHL1GoSmallBumpRIGHT
        PushButton 210, 220, 20, 10, "Set", .btnHL1SetSmallBumpRIGHT
        PushButton 80, 220, 30, 10, "Go G58", .btnHL1GoSmallBumpLEFT
        PushButton 110, 220, 20, 10, "Set", .btnHL1SetSmallBumpLEFT
        PushButton 130, 230, 30, 10, "Go G58", .btnHL1GoSmallBumpBOTTOM
        PushButton 160, 230, 20, 10, "Set", .btnHL1SetSmallBumpBOTTOM
        Text 80, 250, 50, 10,  "Large bump"
        PushButton 130, 250, 30, 10, "Go G58", .btnHL1GoLargeBumpTOP
        PushButton 160, 250, 20, 10, "Set", .btnHL1SetLargeBumpTOP
        PushButton 180, 260, 30, 10, "Go G58", .btnHL1GoLargeBumpRIGHT
        PushButton 210, 260, 20, 10, "Set", .btnHL1SetLargeBumpRIGHT
        PushButton 80, 260, 30, 10, "Go G58", .btnHL1GoLargeBumpLEFT
        PushButton 110, 260, 20, 10, "Set", .btnHL1SetLargeBumpLEFT
        PushButton 130, 270, 30, 10, "Go G58", .btnHL1GoLargeBumpBOTTOM
        PushButton 160, 270, 20, 10, "Set", .btnHL1SetLargeBumpBOTTOM
        
        Text 270, 200, 200, 10,  "HR1", .HR1
        PushButton 270, 210, 30, 10, "Go G55", .btnGotoG55HR1
        PushButton 270, 220, 30, 10, "Go G57", .btnGotoG57HR1
        PushButton 300, 210, 20, 10, "Set", .btnSetG55HR1
        PushButton 300, 220, 20, 10, "Set", .btnSetG57HR1
        Text 340, 210, 50, 10,  "Small bump"
        PushButton 390, 210, 30, 10, "Go G58", .btnHR1GoSmallBumpTOP
        PushButton 420, 210, 20, 10, "Set", .btnHR1SetSmallBumpTOP
        PushButton 440, 220, 30, 10, "Go G58", .btnHR1GoSmallBumpRIGHT
        PushButton 470, 220, 20, 10, "Set", .btnHR1SetSmallBumpRIGHT
        PushButton 340, 220, 30, 10, "Go G58", .btnHR1GoSmallBumpLEFT
        PushButton 370, 220, 20, 10, "Set", .btnHR1SetSmallBumpLEFT
        PushButton 390, 230, 30, 10, "Go G58", .btnHR1GoSmallBumpBOTTOM
        PushButton 420, 230, 20, 10, "Set", .btnHR1SetSmallBumpBOTTOM
        Text 340, 250, 140, 10,  "Large bump"
        PushButton 390, 250, 30, 10, "Go G58", .btnHR1GoLargeBumpTOP
        PushButton 420, 250, 20, 10, "Set", .btnHR1SetLargeBumpTOP
        PushButton 440, 260, 30, 10, "Go G58", .btnHR1GoLargeBumpRIGHT
        PushButton 470, 260, 20, 10, "Set", .btnHR1SetLargeBumpRIGHT
        PushButton 340, 260, 30, 10, "Go G58", .btnHR1GoLargeBumpLEFT
        PushButton 370, 260, 20, 10, "Set", .btnHR1SetLargeBumpLEFT
        PushButton 390, 270, 30, 10, "Go G58", .btnHR1GoLargeBumpBOTTOM
        PushButton 420, 270, 20, 10, "Set", .btnHR1SetLargeBumpBOTTOM
        
            Text 10, 290, 200, 10,  "HL0", .HL0
        PushButton 10, 300, 30, 10, "Go G55", .btnGotoG55HL0
        PushButton 10, 310, 30, 10, "Go G56", .btnGotoG56HL0
        PushButton 40, 300, 20, 10, "Set", .btnSetG55HL0
        PushButton 40, 310, 20, 10, "Set", .btnSetG56HL0
        Text 80, 300, 50, 10,  "Small bump"
        PushButton 130, 300, 30, 10, "Go G58", .btnHL0GoSmallBumpTOP
        PushButton 160, 300, 20, 10, "Set", .btnHL0SetSmallBumpTOP
        PushButton 180, 310, 30, 10, "Go G58", .btnHL0GoSmallBumpRIGHT
        PushButton 210, 310, 20, 10, "Set", .btnHL0SetSmallBumpRIGHT
        PushButton 80, 310, 30, 10, "Go G58", .btnHL0GoSmallBumpLEFT
        PushButton 110, 310, 20, 10, "Set", .btnHL0SetSmallBumpLEFT
        PushButton 130, 320, 30, 10, "Go G58", .btnHL0GoSmallBumpBOTTOM
        PushButton 160, 320, 20, 10, "Set", .btnHL0SetSmallBumpBOTTOM
        Text 80, 340, 50, 10,  "Large bump"
        PushButton 130, 340, 30, 10, "Go G58", .btnHL0GoLargeBumpTOP
        PushButton 160, 340, 20, 10, "Set", .btnHL0SetLargeBumpTOP
        PushButton 180, 350, 30, 10, "Go G58", .btnHL0GoLargeBumpRIGHT
        PushButton 210, 350, 20, 10, "Set", .btnHL0SetLargeBumpRIGHT
        PushButton 80, 350, 30, 10, "Go G58", .btnHL0GoLargeBumpLEFT
        PushButton 110, 350, 20, 10, "Set", .btnHL0SetLargeBumpLEFT
        PushButton 130, 360, 30, 10, "Go G58", .btnHL0GoLargeBumpBOTTOM
        PushButton 160, 360, 20, 10, "Set", .btnHL0SetLargeBumpBOTTOM
        
        Text 270, 290, 200, 10,  "HR0", .HR0
        PushButton 270, 300, 30, 10, "Go G55", .btnGotoG55HR0
        PushButton 270, 310, 30, 10, "Go G57", .btnGotoG57HR0
        PushButton 300, 300, 20, 10, "Set", .btnSetG55HR0
        PushButton 300, 310, 20, 10, "Set", .btnSetG57HR0
        Text 340, 300, 50, 10,  "Small bump"
        PushButton 390, 300, 30, 10, "Go G58", .btnHR0GoSmallBumpTOP
        PushButton 420, 300, 20, 10, "Set", .btnHR0SetSmallBumpTOP
        PushButton 440, 310, 30, 10, "Go G58", .btnHR0GoSmallBumpRIGHT
        PushButton 470, 310, 20, 10, "Set", .btnHR0SetSmallBumpRIGHT
        PushButton 340, 310, 30, 10, "Go G58", .btnHR0GoSmallBumpLEFT
        PushButton 370, 310, 20, 10, "Set", .btnHR0SetSmallBumpLEFT
        PushButton 390, 320, 30, 10, "Go G58", .btnHR0GoSmallBumpBOTTOM
        PushButton 420, 320, 20, 10, "Set", .btnHR0SetSmallBumpBOTTOM
        Text 340, 340, 140, 10,  "Large bump"
        PushButton 390, 340, 30, 10, "Go G58", .btnHR0GoLargeBumpTOP
        PushButton 420, 340, 20, 10, "Set", .btnHR0SetLargeBumpTOP
        PushButton 440, 350, 30, 10, "Go G58", .btnHR0GoLargeBumpRIGHT
        PushButton 470, 350, 20, 10, "Set", .btnHR0SetLargeBumpRIGHT
        PushButton 340, 350, 30, 10, "Go G58", .btnHR0GoLargeBumpLEFT
        PushButton 370, 350, 20, 10, "Set", .btnHR0SetLargeBumpLEFT
        PushButton 390, 360, 30, 10, "Go G58", .btnHR0GoLargeBumpBOTTOM
        PushButton 420, 360, 20, 10, "Set", .btnHR0SetLargeBumpBOTTOM
        
        Text 10, 400, 350, 10,  .Message
        

        OkButton 380, 400, 70, 10

    End Dialog

    Begin Dialog dlgMain 510, 420, "Main", .dialogMain

        Text 210, 20, 35, 10, "FL25"
        Text 210, 30, 35, 10, "FL24"
        Text 210, 40, 35, 10, "FL23"
        Text 210, 50, 35, 10, "FL22"
        Text 210, 60, 35, 10, "FL21"
        Text 210, 70, 35, 10, "FL20"
        Text 210, 80, 35, 10, "FL19"
        Text 210, 90, 35, 10, "FL18"
        Text 210, 100, 35, 10, "FL17"
        Text 210, 110, 35, 10, "FL16"
        Text 210, 120, 35, 10, "FL15"
        Text 210, 130, 35, 10, "FL14"
        Text 210, 140, 35, 10, "FL13"
        Text 210, 150, 35, 10, "FL12"
        Text 210, 160, 35, 10, "FL11"
        Text 210, 170, 35, 10, "FL10"
        Text 210, 180, 35, 10, "FL9"
        Text 210, 190, 35, 10, "FL8"
        Text 210, 200, 35, 10, "FL7"
        Text 210, 210, 35, 10, "FL6"
        Text 210, 220, 35, 10, "FL5"
        Text 210, 230, 35, 10, "FL4"
        Text 210, 240, 35, 10, "FL3"
        Text 210, 250, 35, 10, "FL2"
        Text 210, 260, 35, 10, "FL1"
        
        Text 360, 20, 35, 10, "FR25"
        Text 360, 30, 35, 10, "FR24"
        Text 360, 40, 35, 10, "FR23"
        Text 360, 50, 35, 10, "FR22"
        Text 360, 60, 35, 10, "FR21"
        Text 360, 70, 35, 10, "FR20"
        Text 360, 80, 35, 10, "FR19"
        Text 360, 90, 35, 10, "FR18"
        Text 360, 100, 35, 10, "FR17"
        Text 360, 110, 35, 10, "FR16"
        Text 360, 120, 35, 10, "FR15"
        Text 360, 130, 35, 10, "FR14"
        Text 360, 140, 35, 10, "FR13"
        Text 360, 150, 35, 10, "FR12"
        Text 360, 160, 35, 10, "FR11"
        Text 360, 170, 35, 10, "FR10"
        Text 360, 180, 35, 10, "FR9"
        Text 360, 190, 35, 10, "FR8"
        Text 360, 200, 35, 10, "FR7"
        Text 360, 210, 35, 10, "FR6"
        Text 360, 220, 35, 10, "FR5"
        Text 360, 230, 35, 10, "FR4"
        Text 360, 240, 35, 10, "FR3"
        Text 360, 250, 35, 10, "FR2"
        Text 360, 260, 35, 10, "FR1"
        
        Text 240, 10, 50, 10, "Status"
        Text 240, 20, 50, 10,  .StatusFeeder25
        Text 240, 30, 50, 10,  .StatusFeeder24
        Text 240, 40, 50, 10,  .StatusFeeder23
        Text 240, 50, 50, 10,  .StatusFeeder22
        Text 240, 60, 50, 10,  .StatusFeeder21
        Text 240, 70, 50, 10,  .StatusFeeder20
        Text 240, 80, 50, 10,  .StatusFeeder19
        Text 240, 90, 50, 10,  .StatusFeeder18
        Text 240, 100, 50, 10,  .StatusFeeder17
        Text 240, 110, 50, 10,  .StatusFeeder16
        Text 240, 120, 50, 10,  .StatusFeeder15
        Text 240, 130, 50, 10,  .StatusFeeder14
        Text 240, 140, 50, 10,  .StatusFeeder13
        Text 240, 150, 50, 10,  .StatusFeeder12
        Text 240, 160, 50, 10,  .StatusFeeder11
        Text 240, 170, 50, 10,  .StatusFeeder10
        Text 240, 180, 50, 10,  .StatusFeeder9
        Text 240, 190, 50, 10,  .StatusFeeder8
        Text 240, 200, 50, 10,  .StatusFeeder7
        Text 240, 210, 50, 10,  .StatusFeeder6
        Text 240, 220, 50, 10,  .StatusFeeder5
        Text 240, 230, 50, 10,  .StatusFeeder4
        Text 240, 240, 50, 10,  .StatusFeeder3
        Text 240, 250, 50, 10,  .StatusFeeder2
        Text 240, 260, 50, 10,  .StatusFeeder1
        
        Text 390, 10, 50, 10, "Status"
        Text 390, 20, 50, 10,  .StatusFeeder50
        Text 390, 30, 50, 10,  .StatusFeeder49
        Text 390, 40, 50, 10,  .StatusFeeder48
        Text 390, 50, 50, 10,  .StatusFeeder47
        Text 390, 60, 50, 10,  .StatusFeeder46
        Text 390, 70, 50, 10,  .StatusFeeder45
        Text 390, 80, 50, 10,  .StatusFeeder44
        Text 390, 90, 50, 10,  .StatusFeeder43
        Text 390, 100, 50, 10,  .StatusFeeder42
        Text 390, 110, 50, 10,  .StatusFeeder41
        Text 390, 120, 50, 10,  .StatusFeeder40
        Text 390, 130, 50, 10,  .StatusFeeder39
        Text 390, 140, 50, 10,  .StatusFeeder38
        Text 390, 150, 50, 10,  .StatusFeeder37
        Text 390, 160, 50, 10,  .StatusFeeder36
        Text 390, 170, 50, 10,  .StatusFeeder35
        Text 390, 180, 50, 10,  .StatusFeeder34
        Text 390, 190, 50, 10,  .StatusFeeder33
        Text 390, 200, 50, 10,  .StatusFeeder32
        Text 390, 210, 50, 10,  .StatusFeeder31
        Text 390, 220, 50, 10,  .StatusFeeder30
        Text 390, 230, 50, 10,  .StatusFeeder29
        Text 390, 240, 50, 10,  .StatusFeeder28
        Text 390, 250, 50, 10,  .StatusFeeder27
        Text 390, 260, 50, 10,  .StatusFeeder26
        
        TextBox 305, 10, 20, 10, .flnewcount
        PushButton 305, 20, 40, 10, "Reset", .btnResetCountFeeder25
        PushButton 305, 30, 40, 10, "Reset", .btnResetCountFeeder24
        PushButton 305, 40, 40, 10, "Reset", .btnResetCountFeeder23
        PushButton 305, 50, 40, 10, "Reset", .btnResetCountFeeder22
        PushButton 305, 60, 40, 10, "Reset", .btnResetCountFeeder21
        PushButton 305, 70, 40, 10, "Reset", .btnResetCountFeeder20
        PushButton 305, 80, 40, 10, "Reset", .btnResetCountFeeder19
        PushButton 305, 90, 40, 10, "Reset", .btnResetCountFeeder18
        PushButton 305, 100, 40, 10, "Reset", .btnResetCountFeeder17
        PushButton 305, 110, 40, 10, "Reset", .btnResetCountFeeder16
        PushButton 305, 120, 40, 10, "Reset", .btnResetCountFeeder15
        PushButton 305, 130, 40, 10, "Reset", .btnResetCountFeeder14
        PushButton 305, 140, 40, 10, "Reset", .btnResetCountFeeder13
        PushButton 305, 150, 40, 10, "Reset", .btnResetCountFeeder12
        PushButton 305, 160, 40, 10, "Reset", .btnResetCountFeeder11
        PushButton 305, 170, 40, 10, "Reset", .btnResetCountFeeder10
        PushButton 305, 180, 40, 10, "Reset", .btnResetCountFeeder9
        PushButton 305, 190, 40, 10, "Reset", .btnResetCountFeeder8
        PushButton 305, 200, 40, 10, "Reset", .btnResetCountFeeder7
        PushButton 305, 210, 40, 10, "Reset", .btnResetCountFeeder6
        PushButton 305, 220, 40, 10, "Reset", .btnResetCountFeeder5
        PushButton 305, 230, 40, 10, "Reset", .btnResetCountFeeder4
        PushButton 305, 240, 40, 10, "Reset", .btnResetCountFeeder3
        PushButton 305, 250, 40, 10, "Reset", .btnResetCountFeeder2
        PushButton 305, 260, 40, 10, "Reset", .btnResetCountFeeder1
        
        TextBox 455, 10, 20, 10, .frnewcount
        PushButton 455, 20, 40, 10, "Reset", .btnResetCountFeeder50
        PushButton 455, 30, 40, 10, "Reset", .btnResetCountFeeder49
        PushButton 455, 40, 40, 10, "Reset", .btnResetCountFeeder48
        PushButton 455, 50, 40, 10, "Reset", .btnResetCountFeeder47
        PushButton 455, 60, 40, 10, "Reset", .btnResetCountFeeder46
        PushButton 455, 70, 40, 10, "Reset", .btnResetCountFeeder45
        PushButton 455, 80, 40, 10, "Reset", .btnResetCountFeeder44
        PushButton 455, 90, 40, 10, "Reset", .btnResetCountFeeder43
        PushButton 455, 100, 40, 10, "Reset", .btnResetCountFeeder42
        PushButton 455, 110, 40, 10, "Reset", .btnResetCountFeeder41
        PushButton 455, 120, 40, 10, "Reset", .btnResetCountFeeder40
        PushButton 455, 130, 40, 10, "Reset", .btnResetCountFeeder39
        PushButton 455, 140, 40, 10, "Reset", .btnResetCountFeeder38
        PushButton 455, 150, 40, 10, "Reset", .btnResetCountFeeder37
        PushButton 455, 160, 40, 10, "Reset", .btnResetCountFeeder36
        PushButton 455, 170, 40, 10, "Reset", .btnResetCountFeeder35
        PushButton 455, 180, 40, 10, "Reset", .btnResetCountFeeder34
        PushButton 455, 190, 40, 10, "Reset", .btnResetCountFeeder33
        PushButton 455, 200, 40, 10, "Reset", .btnResetCountFeeder32
        PushButton 455, 210, 40, 10, "Reset", .btnResetCountFeeder31
        PushButton 455, 220, 40, 10, "Reset", .btnResetCountFeeder30
        PushButton 455, 230, 40, 10, "Reset", .btnResetCountFeeder29
        PushButton 455, 240, 40, 10, "Reset", .btnResetCountFeeder28
        PushButton 455, 250, 40, 10, "Reset", .btnResetCountFeeder27
        PushButton 455, 260, 40, 10, "Reset", .btnResetCountFeeder26
        
        PushButton 10, 20, 90, 10, "Init Head Vars", .btnInitHeadVars
        PushButton 10, 30, 90, 10, "Init Feeder Vars", .btnInitFeederVars
        PushButton 100, 20, 90, 10, "Zero feeder counters", .btnzerofeeders ' not implemented yet
        
        Text         10, 50, 200, 10, " G55 Up looking camera origin"
        PushButton 10, 60, 90, 10, "Go Origin", .btnGoG55Origin
        PushButton 100, 60, 90, 10, "Set here", .btnSetG55Origin
        PushButton 10, 70, 90, 10, "Go X70 Y275 Y0", .btnGoG55High
        
        Text         10, 90, 200, 10, " G58 Bump centering origin"
        PushButton 10, 100, 90, 10, "Go Origin", .btnGoG58Origin
        PushButton 100, 100, 90, 10, "Set here", .btnSetG58Origin

        Text 10, 120, 200, 10, " G56 Left / G57 right feeder bank origins"
        PushButton 10, 130, 90, 10, "Go G56 Origin", .btnGoG56Origin
        PushButton 100, 130, 90, 10, "Set G56 here", .btnSetG56Origin
        PushButton 10, 140, 90, 10, "Go G57 Origin", .btnGoG57Origin
        PushButton 100, 140, 90, 10, "Set G57 here", .btnSetG57Origin
        
        Text        10, 170, 200, 10, "0 Rotation"
        PushButton 10, 180, 90, 10, "Go Origin", .btngo0
        PushButton 100, 180, 90, 10, "Go Origin move 4mm", .btngo04mm
        PushButton 10, 190, 90, 10, "Set origin here", .btnset0
        PushButton 100, 190, 90, 10, "Set origin + 4mm offset", .btnset04mm
        PushButton 10, 200, 90, 10, "Run Pick Place", .btnrun0
        
        Text        10, 230, 200, 10, "90 Rotation"
        PushButton 10, 240, 90, 10, "Go Origin", .btngo90
        PushButton 100, 240, 90, 10, "Go Origin move 4mm", .btngo904mm
        PushButton 10, 250, 90, 10, "Set origin here", .btnset90
        PushButton 100, 250, 90, 10, "Set origin + 4mm offset", .btnset904mm
        PushButton 10, 260, 90, 10, "Run Pick Place", .btnrun90

        Text        10, 290, 200, 10, "180 Rotation"
        PushButton 10, 300, 90, 10, "Go Origin", .btngo180
        PushButton 100, 300, 90, 10, "Go Origin move 4mm", .btngo1804mm
        PushButton 10, 310, 90, 10, "Set origin here", .btnset180
        PushButton 100, 310, 90, 10, "Set origin + 4mm offset", .btnset1804mm
        PushButton 10, 320, 90, 10, "Run Pick Place", .btnrun180
    
        Text        10, 350,200, 10, "270 Rotation"
        PushButton 10, 360, 90, 10, "Go Origin", .btngo270
        PushButton 100, 360, 90, 10, "Go Origin move 4mm", .btngo2704mm
        PushButton 10, 370, 90, 10, "Set origin here", .btnset270
        PushButton 100, 370, 90, 10, "Set origin + 4mm offset", .btnset2704mm
        PushButton 10, 380, 90, 10, "Run Pick Place", .btnrun270
        
        PushButton 200, 400, 70, 10, "Calibrate Feeders", .btnCalibrateFeeders    ' no specific handler needed
        PushButton 280, 400, 70, 10, "Calibrate Heads", .btnCalibrateHeads    ' no specific handler needed    
        PushButton 400, 400, 40, 10, "Refresh", .btnrefresh    ' no specific handler needed
        OkButton 455, 400, 40, 10

    End Dialog

    ' MAIN
    currentDialog = currentDialogIsMain

    Do While currentDialog <> currentDialogIsNone
        Select Case currentDialog
            Case currentDialogIsMain
                returnMain = Dialog(dlgMain)
            Case currentDialogIsCalibrateFeeders
                returnCalibrateFeeders = Dialog(dlgCalibrateFeeders)
            Case currentDialogIsCalibrateHeads
                returnCalibrateHeads = Dialog(dlgCalibrateHeads)
            
        End Select
    Loop

End Sub


Function dialogCalibrateFeeders( ControlID$, Action%, SuppValue%)

    dialogCalibrateFeeders = 1
    If Action = 2 Then
        If ControlID$ = "Ok" Or ControlID$ = "Cancel" Then
            dialogCalibrateFeeders = 0
            currentDialog = currentDialogIsMain
            
        Else
            'MsgBox(ControlID$)
            Select Case ControlID$
            
                Case "btnGotoFeeder50"
                    GotoFeeder(50)
                Case "btnGotoFeeder49"
                    GotoFeeder(49)
                Case "btnGotoFeeder48"
                    GotoFeeder(48)
                Case "btnGotoFeeder47"
                    GotoFeeder(47)
                Case "btnGotoFeeder46"
                    GotoFeeder(46)
                Case "btnGotoFeeder45"
                    GotoFeeder(45)
                Case "btnGotoFeeder44"
                    GotoFeeder(44)
                Case "btnGotoFeeder43"
                    GotoFeeder(43)
                Case "btnGotoFeeder42"
                    GotoFeeder(42)
                Case "btnGotoFeeder41"
                    GotoFeeder(41)
                Case "btnGotoFeeder40"
                    GotoFeeder(40)
                Case "btnGotoFeeder39"
                    GotoFeeder(39)
                Case "btnGotoFeeder38"
                    GotoFeeder(38)
                Case "btnGotoFeeder37"
                    GotoFeeder(37)
                Case "btnGotoFeeder36"
                    GotoFeeder(36)
                Case "btnGotoFeeder35"
                    GotoFeeder(35)
                Case "btnGotoFeeder34"
                    GotoFeeder(34)
                Case "btnGotoFeeder33"
                    GotoFeeder(33)
                Case "btnGotoFeeder32"
                    GotoFeeder(32)
                Case "btnGotoFeeder31"
                    GotoFeeder(31)
                Case "btnGotoFeeder30"
                    GotoFeeder(30)
                Case "btnGotoFeeder29"
                    GotoFeeder(29)
                Case "btnGotoFeeder28"
                    GotoFeeder(28)
                Case "btnGotoFeeder27"
                    GotoFeeder(27)
                Case "btnGotoFeeder26"
                    GotoFeeder(26)
                    
                Case "btnGotoFeeder25"
                    GotoFeeder(25)
                Case "btnGotoFeeder24"
                    GotoFeeder(24)
                Case "btnGotoFeeder23"
                    GotoFeeder(23)
                Case "btnGotoFeeder22"
                    GotoFeeder(22)
                Case "btnGotoFeeder21"
                    GotoFeeder(21)
                Case "btnGotoFeeder20"
                    GotoFeeder(20)
                Case "btnGotoFeeder19"
                    GotoFeeder(19)
                Case "btnGotoFeeder18"
                    GotoFeeder(18)
                Case "btnGotoFeeder17"
                    GotoFeeder(17)
                Case "btnGotoFeeder16"
                    GotoFeeder(16)
                Case "btnGotoFeeder15"
                    GotoFeeder(15)
                Case "btnGotoFeeder14"
                    GotoFeeder(14)
                Case "btnGotoFeeder13"
                    GotoFeeder(13)
                Case "btnGotoFeeder12"
                    GotoFeeder(12)
                Case "btnGotoFeeder11"
                    GotoFeeder(11)
                Case "btnGotoFeeder10"
                    GotoFeeder(10)
                Case "btnGotoFeeder9"
                    GotoFeeder(9)
                Case "btnGotoFeeder8"
                    GotoFeeder(8)
                Case "btnGotoFeeder7"
                    GotoFeeder(7)
                Case "btnGotoFeeder6"
                    GotoFeeder(6)
                Case "btnGotoFeeder5"
                    GotoFeeder(5)
                Case "btnGotoFeeder4"
                    GotoFeeder(4)
                Case "btnGotoFeeder3"
                    GotoFeeder(3)
                Case "btnGotoFeeder2"
                    GotoFeeder(2)
                Case "btnGotoFeeder1"
                    GotoFeeder(1)
    
                Case "btnSetFeeder50"
                    SetFeeder(50)
                Case "btnSetFeeder49"
                    SetFeeder(49)
                Case "btnSetFeeder48"
                    SetFeeder(48)
                Case "btnSetFeeder47"
                    SetFeeder(47)
                Case "btnSetFeeder46"
                    SetFeeder(46)
                Case "btnSetFeeder45"
                    SetFeeder(45)
                Case "btnSetFeeder44"
                    SetFeeder(44)
                Case "btnSetFeeder43"
                    SetFeeder(43)
                Case "btnSetFeeder42"
                    SetFeeder(42)
                Case "btnSetFeeder41"
                    SetFeeder(41)
                Case "btnSetFeeder40"
                    SetFeeder(40)
                Case "btnSetFeeder39"
                    SetFeeder(39)
                Case "btnSetFeeder38"
                    SetFeeder(38)
                Case "btnSetFeeder37"
                    SetFeeder(37)
                Case "btnSetFeeder36"
                    SetFeeder(36)
                Case "btnSetFeeder35"
                    SetFeeder(35)
                Case "btnSetFeeder34"
                    SetFeeder(34)
                Case "btnSetFeeder33"
                    SetFeeder(33)
                Case "btnSetFeeder32"
                    SetFeeder(32)
                Case "btnSetFeeder31"
                    SetFeeder(31)
                Case "btnSetFeeder30"
                    SetFeeder(30)
                Case "btnSetFeeder29"
                    SetFeeder(29)
                Case "btnSetFeeder28"
                    SetFeeder(28)
                Case "btnSetFeeder27"
                    SetFeeder(27)
                Case "btnSetFeeder26"
                    SetFeeder(26)
    
                Case "btnSetFeeder25"
                    SetFeeder(25)
                Case "btnSetFeeder24"
                    SetFeeder(24)
                Case "btnSetFeeder23"
                    SetFeeder(23)
                Case "btnSetFeeder22"
                    SetFeeder(22)
                Case "btnSetFeeder21"
                    SetFeeder(21)
                Case "btnSetFeeder20"
                    SetFeeder(20)
                Case "btnSetFeeder19"
                    SetFeeder(19)
                Case "btnSetFeeder18"
                    SetFeeder(18)
                Case "btnSetFeeder17"
                    SetFeeder(17)
                Case "btnSetFeeder16"
                    SetFeeder(16)
                Case "btnSetFeeder15"
                    SetFeeder(15)
                Case "btnSetFeeder14"
                    SetFeeder(14)
                Case "btnSetFeeder13"
                    SetFeeder(13)
                Case "btnSetFeeder12"
                    SetFeeder(12)
                Case "btnSetFeeder11"
                    SetFeeder(11)
                Case "btnSetFeeder10"
                    SetFeeder(10)
                Case "btnSetFeeder9"
                    SetFeeder(09)
                Case "btnSetFeeder8"
                    SetFeeder(08)
                Case "btnSetFeeder7"
                    SetFeeder(07)
                Case "btnSetFeeder6"
                    SetFeeder(06)
                Case "btnSetFeeder5"
                    SetFeeder(05)
                Case "btnSetFeeder4"
                    SetFeeder(04)
                Case "btnSetFeeder3"
                    SetFeeder(03)
                Case "btnSetFeeder2"
                    SetFeeder(02)
                Case "btnSetFeeder1"
                    SetFeeder(01)

            End Select
        End If
    End If
    
    If Action = 1 Or Action = 2 Then
        ' redisplay values
        Dim count As Integer
        Dim temp
        Dim feederID
        For count = 1 To 25 ' FL ID 0 to 25
            DlgText "btnGotoFeeder" & count, "Goto G56 X:" & CStr(GetVar(FeederGCodeBaseVarX + count)) & " Y: " & CStr(GetVar(FeederGCodeBaseVarY + count))
        Next
        
        For count = 26 To 50
            DlgText "btnGotoFeeder" & count, "Goto G57 X:" & CStr(GetVar(FeederGCodeBaseVarX + count)) & " Y: " & CStr(GetVar(FeederGCodeBaseVarY + count))
        Next        

    End If
    
    DlgEnable "btnGotoFeeder25", 0
    DlgEnable "btnGotoFeeder24", 0
    DlgEnable "btnGotoFeeder23", 0
    
    DlgEnable "btnGotoFeeder3", 0
    DlgEnable "btnGotoFeeder2", 0
    DlgEnable "btnGotoFeeder1", 0
    
    DlgEnable "btnGotoFeeder50", 0
    DlgEnable "btnGotoFeeder49", 0
    DlgEnable "btnGotoFeeder48", 0
    
    DlgEnable "btnGotoFeeder28", 0
    DlgEnable "btnGotoFeeder27", 0
    DlgEnable "btnGotoFeeder26", 0
    
End Function


Function dialogCalibrateHeads( ControlID$, Action%, SuppValue%)

    dialogCalibrateHeads = 1
    If Action = 2 Then
        If ControlID$ = "Ok" Or ControlID$ = "Cancel" Then
            dialogCalibrateHeads = 0
            currentDialog = currentDialogIsMain

        Else
            'MsgBox(ControlID$)
            Select Case ControlID$
                Case "btnGotoG55HL3"
                    GoHead "G55", 3
                Case "btnGotoG55HL2"
                    GoHead "G55", 2
                Case "btnGotoG55HL1"
                    GoHead "G55", 1
                Case "btnGotoG55HL0"
                    GoHead "G55", 0
                Case "btnGotoG55HR3"
                    GoHead "G55", 13
                Case "btnGotoG55HR2"
                    GoHead "G55", 12
                Case "btnGotoG55HR1"
                    GoHead "G55", 11
                Case "btnGotoG55HR0"
                    GoHead "G55", 10
                    
                Case "btnGotoG56HL3"
                    GoHead "G56", 3
                Case "btnGotoG56HL2"
                    GoHead "G56", 2
                Case "btnGotoG56HL1"
                    GoHead "G56", 1
                Case "btnGotoG56HL0"
                    GoHead "G56", 0
                    
                Case "btnGotoG57HR3"
                    GoHead "G57", 13
                Case "btnGotoG57HR2"
                    GoHead "G57", 12
                Case "btnGotoG57HR1"
                    GoHead "G57", 11
                Case "btnGotoG57HR0"
                    GoHead "G57", 10
                    
                Case "btnSetG55HL3"
                    SetHead "G55", 3
                Case "btnSetG55HL2"
                    SetHead "G55", 2
                Case "btnSetG55HL1"
                    SetHead "G55", 1
                Case "btnSetG55HL0"
                    SetHead "G55", 0
                Case "btnSetG55HR3"
                    SetHead "G55", 13
                Case "btnSetG55HR2"
                    SetHead "G55", 12
                Case "btnSetG55HR1"
                    SetHead "G55", 11
                Case "btnSetG55HR0"
                    SetHead "G55", 10
                    
                Case "btnSetG56HL3"
                    SetHead "G56", 3
                Case "btnSetG56HL2"
                    SetHead "G56", 2
                Case "btnSetG56HL1"
                    SetHead "G56", 1
                Case "btnSetG56HL0"
                    SetHead "G56", 0
                    
                Case "btnSetG57HR3"
                    SetHead "G57", 13
                Case "btnSetG57HR2"
                    SetHead "G57", 12
                Case "btnSetG57HR1"
                    SetHead "G57", 11
                Case "btnSetG57HR0"
                    SetHead "G57", 10
                    
                    
                Case "btnHL3GoSmallBumpTOP"
                    GoSmallBumpTOP(3)
                Case "btnHL2GoSmallBumpTOP"
                    GoSmallBumpTOP(2)
                Case "btnHL1GoSmallBumpTOP"
                    GoSmallBumpTOP(1)
                Case "btnHL0GoSmallBumpTOP"
                    GoSmallBumpTOP(0)
                Case "btnHR3GoSmallBumpTOP"
                    GoSmallBumpTOP(13)
                Case "btnHR2GoSmallBumpTOP"
                    GoSmallBumpTOP(12)
                Case "btnHR1GoSmallBumpTOP"
                    GoSmallBumpTOP(11)
                Case "btnHR0GoSmallBumpTOP"
                    GoSmallBumpTOP(10)
                    
                Case "btnHL3GoSmallBumpBottom"
                    GoSmallBumpBottom(3)
                Case "btnHL2GoSmallBumpBottom"
                    GoSmallBumpBottom(2)
                Case "btnHL1GoSmallBumpBottom"
                    GoSmallBumpBottom(1)
                Case "btnHL0GoSmallBumpBottom"
                    GoSmallBumpBottom(0)
                Case "btnHR3GoSmallBumpBottom"
                    GoSmallBumpBottom(13)
                Case "btnHR2GoSmallBumpBottom"
                    GoSmallBumpBottom(12)
                Case "btnHR1GoSmallBumpBottom"
                    GoSmallBumpBottom(11)
                Case "btnHR0GoSmallBumpBottom"
                    GoSmallBumpBottom(10)
                    
                Case "btnHL3GoSmallBumpLeft"
                    GoSmallBumpLeft(3)
                Case "btnHL2GoSmallBumpLeft"
                    GoSmallBumpLeft(2)
                Case "btnHL1GoSmallBumpLeft"
                    GoSmallBumpLeft(1)
                Case "btnHL0GoSmallBumpLeft"
                    GoSmallBumpLeft(0)
                Case "btnHR3GoSmallBumpLeft"
                    GoSmallBumpLeft(13)
                Case "btnHR2GoSmallBumpLeft"
                    GoSmallBumpLeft(12)
                Case "btnHR1GoSmallBumpLeft"
                    GoSmallBumpLeft(11)
                Case "btnHR0GoSmallBumpLeft"
                    GoSmallBumpLeft(10)
                
                Case "btnHL3GoSmallBumpRight"
                    GoSmallBumpRight(3)
                Case "btnHL2GoSmallBumpRight"
                    GoSmallBumpRight(2)
                Case "btnHL1GoSmallBumpRight"
                    GoSmallBumpRight(1)
                Case "btnHL0GoSmallBumpRight"
                    GoSmallBumpRight(0)
                Case "btnHR3GoSmallBumpRight"
                    GoSmallBumpRight(13)
                Case "btnHR2GoSmallBumpRight"
                    GoSmallBumpRight(12)
                Case "btnHR1GoSmallBumpRight"
                    GoSmallBumpRight(11)
                Case "btnHR0GoSmallBumpRight"
                    GoSmallBumpRight(10)
                    
                Case "btnHL3SetSmallBumpTop"
                    SetSmallBumpTop(3)
                Case "btnHL2SetSmallBumpTop"
                    SetSmallBumpTop(2)
                Case "btnHL1SetSmallBumpTop"
                    SetSmallBumpTop(1)
                Case "btnHL0SetSmallBumpTop"
                    SetSmallBumpTop(0)
                Case "btnHR3SetSmallBumpTop"
                    SetSmallBumpTop(13)
                Case "btnHR2SetSmallBumpTop"
                    SetSmallBumpTop(12)
                Case "btnHR1SetSmallBumpTop"
                    SetSmallBumpTop(11)
                Case "btnHR0SetSmallBumpTop"
                    SetSmallBumpTop(10)
                    
                Case "btnHL3SetSmallBumpBottom"
                    SetSmallBumpBottom(3)
                Case "btnHL2SetSmallBumpBottom"
                    SetSmallBumpBottom(2)
                Case "btnHL1SetSmallBumpBottom"
                    SetSmallBumpBottom(1)
                Case "btnHL0SetSmallBumpBottom"
                    SetSmallBumpBottom(0)
                Case "btnHR3SetSmallBumpBottom"
                    SetSmallBumpBottom(13)
                Case "btnHR2SetSmallBumpBottom"
                    SetSmallBumpBottom(12)
                Case "btnHR1SetSmallBumpBottom"
                    SetSmallBumpBottom(11)
                Case "btnHR0SetSmallBumpBottom"
                    SetSmallBumpBottom(10)
                    
                Case "btnHL3SetSmallBumpLeft"
                    SetSmallBumpLeft(3)
                Case "btnHL2SetSmallBumpLeft"
                    SetSmallBumpLeft(2)
                Case "btnHL1SetSmallBumpLeft"
                    SetSmallBumpLeft(1)
                Case "btnHL0SetSmallBumpLeft"
                    SetSmallBumpLeft(0)
                Case "btnHR3SetSmallBumpLeft"
                    SetSmallBumpLeft(13)
                Case "btnHR2SetSmallBumpLeft"
                    SetSmallBumpLeft(12)
                Case "btnHR1SetSmallBumpLeft"
                    SetSmallBumpLeft(11)
                Case "btnHR0SetSmallBumpLeft"
                    SetSmallBumpLeft(10)
                
                Case "btnHL3SetSmallBumpRight"
                    SetSmallBumpRight(3)
                Case "btnHL2SetSmallBumpRight"
                    SetSmallBumpRight(2)
                Case "btnHL1SetSmallBumpRight"
                    SetSmallBumpRight(1)
                Case "btnHL0SetSmallBumpRight"
                    SetSmallBumpRight(0)
                Case "btnHR3SetSmallBumpRight"
                    SetSmallBumpRight(13)
                Case "btnHR2SetSmallBumpRight"
                    SetSmallBumpRight(12)
                Case "btnHR1SetSmallBumpRight"
                    SetSmallBumpRight(11)
                Case "btnHR0SetSmallBumpRight"
                    SetSmallBumpRight(10)
                    
                Case "btnHL3GoLargeBumpTOP"
                    GoLargeBumpTOP(3)
                Case "btnHL2GoLargeBumpTOP"
                    GoLargeBumpTOP(2)
                Case "btnHL1GoLargeBumpTOP"
                    GoLargeBumpTOP(1)
                Case "btnHL0GoLargeBumpTOP"
                    GoLargeBumpTOP(0)
                Case "btnHR3GoLargeBumpTOP"
                    GoLargeBumpTOP(13)
                Case "btnHR2GoLargeBumpTOP"
                    GoLargeBumpTOP(12)
                Case "btnHR1GoLargeBumpTOP"
                    GoLargeBumpTOP(11)
                Case "btnHR0GoLargeBumpTOP"
                    GoLargeBumpTOP(10)
                    
                Case "btnHL3GoLargeBumpBottom"
                    GoLargeBumpBottom(3)
                Case "btnHL2GoLargeBumpBottom"
                    GoLargeBumpBottom(2)
                Case "btnHL1GoLargeBumpBottom"
                    GoLargeBumpBottom(1)
                Case "btnHL0GoLargeBumpBottom"
                    GoLargeBumpBottom(0)
                Case "btnHR3GoLargeBumpBottom"
                    GoLargeBumpBottom(13)
                Case "btnHR2GoLargeBumpBottom"
                    GoLargeBumpBottom(12)
                Case "btnHR1GoLargeBumpBottom"
                    GoLargeBumpBottom(11)
                Case "btnHR0GoLargeBumpBottom"
                    GoLargeBumpBottom(10)
                    
                Case "btnHL3GoLargeBumpLeft"
                    GoLargeBumpLeft(3)
                Case "btnHL2GoLargeBumpLeft"
                    GoLargeBumpLeft(2)
                Case "btnHL1GoLargeBumpLeft"
                    GoLargeBumpLeft(1)
                Case "btnHL0GoLargeBumpLeft"
                    GoLargeBumpLeft(0)
                Case "btnHR3GoLargeBumpLeft"
                    GoLargeBumpLeft(13)
                Case "btnHR2GoLargeBumpLeft"
                    GoLargeBumpLeft(12)
                Case "btnHR1GoLargeBumpLeft"
                    GoLargeBumpLeft(11)
                Case "btnHR0GoLargeBumpLeft"
                    GoLargeBumpLeft(10)
                
                Case "btnHL3GoLargeBumpRight"
                    GoLargeBumpRight(3)
                Case "btnHL2GoLargeBumpRight"
                    GoLargeBumpRight(2)
                Case "btnHL1GoLargeBumpRight"
                    GoLargeBumpRight(1)
                Case "btnHL0GoLargeBumpRight"
                    GoLargeBumpRight(0)
                Case "btnHR3GoLargeBumpRight"
                    GoLargeBumpRight(13)
                Case "btnHR2GoLargeBumpRight"
                    GoLargeBumpRight(12)
                Case "btnHR1GoLargeBumpRight"
                    GoLargeBumpRight(11)
                Case "btnHR0GoLargeBumpRight"
                    GoLargeBumpRight(10)
                    
                Case "btnHL3SetLargeBumpTop"
                    SetLargeBumpTop(3)
                Case "btnHL2SetLargeBumpTop"
                    SetLargeBumpTop(2)
                Case "btnHL1SetLargeBumpTop"
                    SetLargeBumpTop(1)
                Case "btnHL0SetLargeBumpTop"
                    SetLargeBumpTop(0)
                Case "btnHR3SetLargeBumpTop"
                    SetLargeBumpTop(13)
                Case "btnHR2SetLargeBumpTop"
                    SetLargeBumpTop(12)
                Case "btnHR1SetLargeBumpTop"
                    SetLargeBumpTop(11)
                Case "btnHR0SetLargeBumpTop"
                    SetLargeBumpTop(10)
                    
                Case "btnHL3SetLargeBumpBottom"
                    SetLargeBumpBottom(3)
                Case "btnHL2SetLargeBumpBottom"
                    SetLargeBumpBottom(2)
                Case "btnHL1SetLargeBumpBottom"
                    SetLargeBumpBottom(1)
                Case "btnHL0SetLargeBumpBottom"
                    SetLargeBumpBottom(0)
                Case "btnHR3SetLargeBumpBottom"
                    SetLargeBumpBottom(13)
                Case "btnHR2SetLargeBumpBottom"
                    SetLargeBumpBottom(12)
                Case "btnHR1SetLargeBumpBottom"
                    SetLargeBumpBottom(11)
                Case "btnHR0SetLargeBumpBottom"
                    SetLargeBumpBottom(10)
                    
                Case "btnHL3SetLargeBumpLeft"
                    SetLargeBumpLeft(3)
                Case "btnHL2SetLargeBumpLeft"
                    SetLargeBumpLeft(2)
                Case "btnHL1SetLargeBumpLeft"
                    SetLargeBumpLeft(1)
                Case "btnHL0SetLargeBumpLeft"
                    SetLargeBumpLeft(0)
                Case "btnHR3SetLargeBumpLeft"
                    SetLargeBumpLeft(13)
                Case "btnHR2SetLargeBumpLeft"
                    SetLargeBumpLeft(12)
                Case "btnHR1SetLargeBumpLeft"
                    SetLargeBumpLeft(11)
                Case "btnHR0SetLargeBumpLeft"
                    SetLargeBumpLeft(10)
                
                Case "btnHL3SetLargeBumpRight"
                    SetLargeBumpRight(3)
                Case "btnHL2SetLargeBumpRight"
                    SetLargeBumpRight(2)
                Case "btnHL1SetLargeBumpRight"
                    SetLargeBumpRight(1)
                Case "btnHL0SetLargeBumpRight"
                    SetLargeBumpRight(0)
                Case "btnHR3SetLargeBumpRight"
                    SetLargeBumpRight(13)
                Case "btnHR2SetLargeBumpRight"
                    SetLargeBumpRight(12)
                Case "btnHR1SetLargeBumpRight"
                    SetLargeBumpRight(11)
                Case "btnHR0SetLargeBumpRight"
                    SetLargeBumpRight(10)
                
                    
            End Select
        End If
    End If

    If Action = 1 Or Action = 2 Then
        ' redisplay values
        Dim count As Integer
        Dim temp
        For count = 1 To 25
        
        Next

        DlgText "HL3", "HL3 X: " & CStr(getvar(1003)) & " Y: " & CStr(getvar(1023))
        DlgText "HL2", "HL2 X: " & CStr(getvar(1002)) & " Y: " & CStr(getvar(1022))
        DlgText "HL1", "HL1 X: " & CStr(getvar(1001)) & " Y: " & CStr(getvar(1021))
        DlgText "HL0", "HL0 X: " & CStr(getvar(1000)) & " Y: " & CStr(getvar(1020))
        DlgText "HR3", "HR3 X: " & CStr(getvar(1013)) & " Y: " & CStr(getvar(1033))
        DlgText "HR2", "HR2 X: " & CStr(getvar(1012)) & " Y: " & CStr(getvar(1032))
        DlgText "HR1", "HR1 X: " & CStr(getvar(1011)) & " Y: " & CStr(getvar(1031))
        DlgText "HR0", "HR0 X: " & CStr(getvar(1010)) & " Y: " & CStr(getvar(1030))        
    End If

End Function



Function dialogMain( ControlID$, Action%, SuppValue%)

    Dim count As Integer
    dialogMain = 1
    
    If Action = 2 Then
        If ControlID$ = "Ok" Or ControlID$ = "Cancel" Then
            dialogMain = 0
            currentDialog = currentDialogIsNone
        Else
            'MsgBox(ControlID$)
            Select Case ControlID$
                Case "btnResetCountFeeder50"
                    SetVar (50, DlgText("frnewcount"))
                Case "btnResetCountFeeder48"
                    SetVar (49, DlgText("frnewcount"))
                Case "btnResetCountFeeder48"
                    SetVar (48, DlgText("frnewcount"))
                Case "btnResetCountFeeder47"
                    SetVar (47, DlgText("frnewcount"))
                Case "btnResetCountFeeder46"
                    SetVar (46, DlgText("frnewcount"))
                Case "btnResetCountFeeder45"
                    SetVar (45, DlgText("frnewcount"))
                Case "btnResetCountFeeder44"
                    SetVar (44, DlgText("frnewcount"))
                Case "btnResetCountFeeder43"
                    SetVar (43, DlgText("frnewcount"))
                Case "btnResetCountFeeder42"
                    SetVar (42, DlgText("frnewcount"))
                Case "btnResetCountFeeder41"
                    SetVar (41, DlgText("frnewcount"))
                Case "btnResetCountFeeder40"
                    SetVar (40, DlgText("frnewcount"))
                Case "btnResetCountFeeder39"
                    SetVar (39, DlgText("frnewcount"))
                Case "btnResetCountFeeder38"
                    SetVar (38, DlgText("frnewcount"))
                Case "btnResetCountFeeder37"
                    SetVar (37, DlgText("frnewcount"))
                Case "btnResetCountFeeder36"
                    SetVar (36, DlgText("frnewcount"))
                Case "btnResetCountFeeder35"
                    SetVar (35, DlgText("frnewcount"))
                Case "btnResetCountFeeder34"
                    SetVar (34, DlgText("frnewcount"))
                Case "btnResetCountFeeder33"
                    SetVar (33, DlgText("frnewcount"))
                Case "btnResetCountFeeder32"
                    SetVar (32, DlgText("frnewcount"))
                Case "btnResetCountFeeder31"
                    SetVar (31, DlgText("frnewcount"))
                Case "btnResetCountFeeder30"
                    SetVar (30, DlgText("frnewcount"))
                Case "btnResetCountFeeder29"
                    SetVar (29, DlgText("frnewcount"))
                Case "btnResetCountFeeder28"
                    SetVar (28, DlgText("frnewcount"))
                Case "btnResetCountFeeder27"
                    SetVar (27, DlgText("frnewcount"))
                Case "btnResetCountFeeder26"
                    SetVar (26, DlgText("frnewcount"))
                Case "btnResetCountFeeder25"
                    SetVar (25, DlgText("flnewcount"))
                Case "btnResetCountFeeder24"
                    SetVar (24, DlgText("flnewcount"))
                Case "btnResetCountFeeder23"
                    SetVar (23, DlgText("flnewcount"))
                Case "btnResetCountFeeder22"
                    SetVar (22, DlgText("flnewcount"))
                Case "btnResetCountFeeder21"
                    SetVar (21, DlgText("flnewcount"))
                Case "btnResetCountFeeder20"
                    SetVar (20, DlgText("flnewcount"))
                Case "btnResetCountFeeder19"
                    SetVar (19, DlgText("flnewcount"))
                Case "btnResetCountFeeder18"
                    SetVar (18, DlgText("flnewcount"))
                Case "btnResetCountFeeder17"
                    SetVar (17, DlgText("flnewcount"))
                Case "btnResetCountFeeder16"
                    SetVar (16, DlgText("flnewcount"))
                Case "btnResetCountFeeder15"
                    SetVar (15, DlgText("flnewcount"))
                Case "btnResetCountFeeder14"
                    SetVar (14, DlgText("flnewcount"))
                Case "btnResetCountFeeder13"
                    SetVar (13, DlgText("flnewcount"))
                Case "btnResetCountFeeder12"
                    SetVar (12, DlgText("flnewcount"))
                Case "btnResetCountFeeder11"
                    SetVar (11, DlgText("flnewcount"))
                Case "btnResetCountFeeder10"
                    SetVar (10, DlgText("flnewcount"))
                Case "btnResetCountFeeder9"
                    SetVar (09, DlgText("flnewcount"))
                Case "btnResetCountFeeder8"
                    SetVar (08, DlgText("flnewcount"))
                Case "btnResetCountFeeder7"
                    SetVar (07, DlgText("flnewcount"))
                Case "btnResetCountFeeder6"
                    SetVar (06, DlgText("flnewcount"))
                Case "btnResetCountFeeder5"
                    SetVar (05, DlgText("flnewcount"))
                Case "btnResetCountFeeder4"
                    SetVar (04, DlgText("flnewcount"))
                Case "btnResetCountFeeder3"
                    SetVar (03, DlgText("flnewcount"))
                Case "btnResetCountFeeder2"
                    SetVar (02, DlgText("flnewcount"))
                Case "btnResetCountFeeder1"
                    SetVar (01, DlgText("flnewcount"))

                Case "btnInitHeadVars"
                    Code("M98 P1")
                Case "btnInitFeederVars"
                    Code("M98 P2")
                    
                Case "btnZeroFeeders"
                    For count = 1 To 50
                        SetVar (count, 0)
                    Next
                    
                Case "btnGoG55Origin"
                    code("G0 G90 G55 X0 Y0")
                Case "btnSetG55Origin"
                    SetG59OffSetToCurrentPosition(2)    ' G55 is G59 offset 2
                Case "btnGoG55High"
                    code("G0 G90 G55 X70 Y275")

                Case "btnGoG56Origin"
                    code("G0 G90 G56 X0 Y0")
                Case "btnSetG56Origin"
                    SetG59OffSetToCurrentPosition(3)    ' G56 is G59 offset 3
                    
                Case "btnGoG57Origin"
                    code("G0 G90 G57 X0 Y0")
                Case "btnSetG57Origin"
                    SetG59OffSetToCurrentPosition(4)    ' G57 is G59 offset 4
                    
                Case "btnGoG58Origin"
                    code("G0 G90 G58 X0 Y0")
                Case "btnSetG58Origin"
                    SetG59OffSetToCurrentPosition(5)    ' G57 is G59 offset 4

                Case "btngo0"
                    Code("G0 G59 P" & G59Rot0PCB1)
                    Code("X0 Y0")
                Case "btngo90"
                    Code("G0 G59 P" & G59Rot90PCB1)
                    Code("X0 Y0")
                Case "btngo180"
                    Code("G0 G59 P" & G59Rot180PCB1)
                    Code("X0 Y0")
                Case "btngo270"
                    Code("G0 G59 P" & G59Rot270PCB1)
                    Code("X0 Y0")
                    
                Case "btngo04mm"
                    Code("G0 G59 P" & G59Rot0PCB1)
                    Code("G90 X4 Y4")
                Case "btngo904mm"
                    Code("G0 G59 P" & G59Rot90PCB1)
                    Code("G90 X4 Y-4")
                Case "btngo1804mm"
                    Code("G0 G59 P" & G59Rot180PCB1)
                    Code("G90 X-4 Y-4")
                    WaitForMove
                Case "btngo2704mm"
                    Code("G0 G59 P" & G59Rot270PCB1)
                    Code("G90 X-4 Y4")
                    
                Case "btnset0"
                    SetG59OffSetToCurrentPosition(G59Rot0PCB1)
                Case "btnset90"
                    SetG59OffSetToCurrentPosition(G59Rot90PCB1)
                Case "btnset180"
                    SetG59OffSetToCurrentPosition(G59Rot180PCB1)
                Case "btnset270"
                    SetG59OffSetToCurrentPosition(G59Rot270PCB1)
                    
                Case "btnset04mm"
                    SetG59OffSetToCurrentPosition(G59Rot0PCB1)
                    Code("G0 G59 P" & G59Rot0PCB1)
                    Code("G91 X-4 Y-4")
                    WaitForMove
                    Code("G90")
                    SetG59OffSetToCurrentPosition(G59Rot0PCB1)
                Case "btnset904mm"
                    SetG59OffSetToCurrentPosition(G59Rot90PCB1)
                    Code("G0 G59 P" & G59Rot90PCB1)
                    Code("G91 X-4 Y4")
                    WaitForMove
                    Code("G90")
                    SetG59OffSetToCurrentPosition(G59Rot90PCB1)
                Case "btnset1804mm"
                    SetG59OffSetToCurrentPosition(G59Rot180PCB1)
                    Code("G0 G59 P" & G59Rot180PCB1)
                    Code("G91 X4 Y4")
                    WaitForMove
                    Code("G90")
                    SetG59OffSetToCurrentPosition(G59Rot180PCB1)
                Case "btnset2704mm"
                    SetG59OffSetToCurrentPosition(G59Rot270PCB1)
                    Code("G0 G59 P" & G59Rot270PCB1)
                    Code("G91 X4 Y-4")
                    WaitForMove
                    Code("G90")
                    SetG59OffSetToCurrentPosition(G59Rot270PCB1)
                    
                Case "btnrun0"
                    setvar(2000, G59Rot0PCB1)
                    Code("M98 P0") 'Call PCB function
                Case "btnrun90"
                    setvar(2000, G59Rot90PCB1)
                    Code("M98 P90") 'Call PCB function
                Case "btnrun180"
                    setvar(2000, G59Rot180PCB1)
                    Code("M98 P180") 'Call PCB function
                Case "btnrun270"
                    setvar(2000, G59Rot270PCB1)
                    Code("M98 P270") 'Call PCB function
                
                Case "btnCalibrateFeeders"
                ' Sub menus
                    currentDialog = currentDialogIsCalibrateFeeders
                    dialogMain = 0
                Case "btnCalibrateHeads"
                ' Sub menus
                    currentDialog = currentDialogIsCalibrateHeads
                    dialogMain = 0

            End Select
        End If
    End If
    If Action = 1 Or Action = 2 Then
        ' redisplay values
        
        DlgText "flnewcount", 0
        DlgText "frnewcount", 0
            
        Dim temp
        Dim feederID
        For count = 1 To 50
            temp = GetVar(FeederGCodeBaseVarComponentsMax + count) - GetVar(count)
            DlgText "StatusFeeder" & count,CStr(GetVar(FeederGCodeBaseVarComponentsRequired + count)) + " of " + CStr(temp) & " : " & CStr(GetVar(FeederGCodeBaseVarComponentsMax + count)) & " - " & CStr(GetVar(count))
            DlgEnable "StatusFeeder" & count, 0
            
            DlgText "btnResetCountFeeder" & count, "Reset (" & CStr(GetVar(count)) & ")"

        Next
    End If

End Function
         
         
Sub SetG59OffSetToCurrentPosition(G59Offset As Integer)
    ' Set G59 offset to current position
    SetVar(G59BaseAddrX + (G59AddrIncrement * (G59Offset - 1)), GetParam("XMachine"))
    SetVar(G59BaseAddrY + (G59AddrIncrement * (G59Offset - 1)), GetParam("YMachine"))
End Sub  


Sub WaitForMove()
    While ismoving()
    sleep 100
    Wend
End Sub      

' Feeder functions
Sub GotoFeeder(feederID)
    If feederID >= 1 And feederID <= 26 Then
        Code("G56 G0 X[#" + CStr(FeederGCodeBaseVarX + feederID) + "] Y[#" + CStr(FeederGCodeBaseVarY + feederID) + "]")
    End If
    If feederID >= 26 And feederID <= 50 Then
        Code("G57 G0 X[#" + CStr(FeederGCodeBaseVarX + feederID) + "] Y[#" + CStr(FeederGCodeBaseVarY + feederID) + "]")
    End If
End Sub

Sub SetFeeder(feederID)
    If feederID >= 1 And feederID <= 26 Then
        Code("G56")
    End If
    If feederID >= 26 And feederID <= 50 Then
        Code("G57")
    End If
    Code("#" + CStr(FeederGCodeBaseVarX + feederID) + " = " & getparam("XDRO"))
    Code("#" + CStr(FeederGCodeBaseVarY + feederID) + " = " & getparam("YDRO"))
End Sub

'Head functions
Sub SetHead(origin, headID)
    Code(origin)
    Code("#" + CStr(HeadGCodeBaseVarX + headID) + " = " & getparam("XDRO"))
    Code("#" + CStr(HeadGCodeBaseVarY + headID) + " = " & getparam("YDRO"))
End Sub

Sub GoHead(origin, headID)
    Dim command
    command = origin + " G0 X[#" + CStr(HeadGCodeBaseVarX + headID) + "] Y[#" + CStr(HeadGCodeBaseVarY + headID) + "]"
    DlgText "debug1", command
    DlgText "debug2", ""
    DlgText "debug3", ""
    Code(command)
End Sub

' Small Bump pit functions
Sub GoSmallBumpLEFT(headID)
    strTemp = "G58 G0 X[#" + CStr(HeadGCodeBaseVarSmallBumpLeftX + headID) + "] Y" + CStr(getSmallBumpMidY(headID))
    Code(strTemp)
    DlgText "Message", strtemp
End Sub

Sub GoSmallBumpRight(headID)
    strTemp = "G58 G0 X[#" + CStr(HeadGCodeBaseVarSmallBumpRightX + headID) + "] Y" + CStr(getSmallBumpMidY(headID))
    Code(strTemp)
    DlgText "Message", strtemp
End Sub

Sub GoSmallBumpTop(headID As Integer)
    Code("G58 G0 X" + CStr(getSmallBumpMidX(headID)) & "  Y[#" + CStr(HeadGCodeBaseVarSmallBumpTopY + headID) + "]")
    Code(strTemp)
    DlgText "Message", strtemp
End Sub

Sub GoSmallBumpBottom(headID As Integer)
    Code("G58 G0 X" + CStr(getSmallBumpMidX(headID)) & "  Y[#" + CStr(HeadGCodeBaseVarSmallBumpBottomY + headID) + "]")
    Code(strTemp)
    DlgText "Message", strtemp
End Sub

Sub SetSmallBumpLeft(headID As Integer)
    strTemp = "#" + CStr(HeadGCodeBaseVarSmallBumpLeftX + headID) + " = " & getparam("XDRO")
    Code("G58")
    Code(strTemp)
    DlgText "Message", strtemp
End Sub

Sub SetSmallBumpRight(headID As Integer)
    Code("G58")
    strTemp = "#" + CStr(HeadGCodeBaseVarSmallBumpRightX + headID) + " = " & getparam("XDRO")
    Code(strTemp)
    DlgText "Message", strtemp
End Sub

Sub SetSmallBumpTop(headID As Integer)
    Code("G58")
    strTemp = "#" + CStr(HeadGCodeBaseVarSmallBumpTopY + headID) + " = " & getparam("YDRO")
    Code(strTemp)
    DlgText "Message", strtemp
End Sub

Sub SetSmallBumpBottom(headID As Integer)
    strTemp = "#" + CStr(HeadGCodeBaseVarSmallBumpBottomY + headID) + " = " & getparam("YDRO")
    Code("G58")
    Code(strTemp)
    DlgText "Message", strtemp
End Sub
 
' Large Bump pit functions
Sub GoLargeBumpLEFT(headID)
    strTemp = "G58 G0 X[#" + CStr(HeadGCodeBaseVarLargeBumpLeftX + headID) + "] Y" + CStr(getLargeBumpMidY(headID))
    Code(strTemp)
    DlgText "Message", strtemp
End Sub

Sub GoLargeBumpRight(headID)
    strTemp = "G58 G0 X[#" + CStr(HeadGCodeBaseVarLargeBumpRightX + headID) + "] Y" + CStr(getLargeBumpMidY(headID))
    Code(strTemp)
    DlgText "Message", strtemp
End Sub

Sub GoLargeBumpTop(headID As Integer)
    strTemp = "G58 G0 X" + CStr(getLargeBumpMidX(headID)) & "  Y[#" + CStr(HeadGCodeBaseVarLargeBumpTopY + headID) + "]"
    Code(strTemp)
    DlgText "Message", strtemp
End Sub

Sub GoLargeBumpBottom(headID As Integer)
    strTemp = "G58 G0 X" + CStr(getLargeBumpMidX(headID)) & "  Y[#" + CStr(HeadGCodeBaseVarLargeBumpBottomY + headID) + "]"
    Code(strTemp)
    DlgText "Message", strtemp
End Sub

Sub SetLargeBumpLeft(headID As Integer)
    strTemp = "#" + CStr(HeadGCodeBaseVarLargeBumpLeftX + headID) + " = " & getparam("XDRO")
    Code("G58")
    Code(strTemp)
    DlgText "Message", strtemp
End Sub

Sub SetLargeBumpRight(headID As Integer)
    strTemp = "#" + CStr(HeadGCodeBaseVarLargeBumpRightX + headID) + " = " & getparam("XDRO")
    Code("G58")
    Code(strTemp)
    DlgText "Message", strtemp
End Sub

Sub SetLargeBumpTop(headID As Integer)
    strTemp = "#" + CStr(HeadGCodeBaseVarLargeBumpTopY + headID) + " = " & getparam("YDRO")
    Code("G58")
    Code(strTemp)
    DlgText "Message", strtemp
End Sub

Sub SetLargeBumpBottom(headID As Integer)
    strTemp = "#" + CStr(HeadGCodeBaseVarLargeBumpBottomY + headID) + " = " & getparam("YDRO")
    Code("G58")
    Code(strTemp)
    DlgText "Message", strtemp
End Sub


Function getSmallBumpMidY(headID)
    Dim topY, bottomY
    topY = GetVar(HeadGCodeBaseVarSmallBumpTopY + headID)
    bottomY = GetVar(HeadGCodeBaseVarSmallBumpBottomY + headID)
    getSmallBumpMidY = bottomY + ((topY - bottomY ) / 2 )
End Function

Function getSmallBumpMidX(headID)
    Dim leftX, rightX
    leftX = GetVar(HeadGCodeBaseVarSmallBumpLeftX + headID)
    rightX = GetVar(HeadGCodeBaseVarSmallBumpRightX + headID)
    getSmallBumpMidX = leftX + ((rightX - leftX ) / 2 )
End Function

Function getLargeBumpMidY(headID)
    Dim topY, bottomY
    topY = GetVar(HeadGCodeBaseVarLargeBumpTopY + headID)
    bottomY = GetVar(HeadGCodeBaseVarLargeBumpBottomY + headID)
    getLargeBumpMidY = bottomY + ((topY - bottomY ) / 2 )
End Function

Function getLargeBumpMidX(headID)
    Dim leftX, rightX
    leftX = GetVar(HeadGCodeBaseVarLargeBumpLeftX + headID)
    rightX = GetVar(HeadGCodeBaseVarLargeBumpRightX + headID)
    getLargeBumpMidX = leftX + ((rightX - leftX ) / 2 )
End Function