Private Sub CheckBox1_Click()
 'latitude default
 Dim ws
 With UserForm1
  Set ws = Worksheets(1)
  .TextBox1.value = Int(central - latrng) 'nlle(1, 3) 'Trim(ws.Cells(3, 2))    'min
  .TextBox2.value = Int(central + latrng) 'nlle(1, 1) 'Trim(ws.Cells(2, 2))    'max
 End With
End Sub

Private Sub CheckBox2_Click()
 'longtitude default
 Dim ws
 With UserForm1
  Set ws = Worksheets(1)
  .TextBox3.value = Int(central - latrng) 'nlle(2, 3) 'Trim(ws.Cells(3, 3))    'min
  .TextBox4.value = Int(central + latrng) 'nlle(2, 1) 'Trim(ws.Cells(2, 3))    'max
 End With
End Sub

Private Sub CheckBox3_Click()
 'elevation default
 Dim ws
 With UserForm1
  Set ws = Worksheets(1)
  .TextBox5.value = 0 'nlle(3, 3) 'Trim(ws.Cells(3, 4))    'min
  .TextBox6.value = binsmax 'nlle(3, 1) 'Trim(ws.Cells(2, 4))    'max
 End With
End Sub

Private Sub CheckBox4_Click()
 'lat = lon
 With UserForm1
 .TextBox1.value = .TextBox3.value  'min
 .TextBox2.value = .TextBox4.value  'max
 End With
End Sub

Private Sub CheckBox5_Click()
 'default settings
 With UserForm1
  If .CheckBox5.value = True Then
   .TextBox7.value = 0.36   'flh
   .TextBox8.value = 0.65   'ew
   .TextBox9.value = 1.75   'fd
   .TextBox10.value = 1     'x1
   .TextBox11.value = 1.5   'Aroad_scaler
  Else
   .CheckBox5.value = False
  End If
 End With
End Sub

Private Sub CommandButton1_Click()
'load
 Dim Filelist As Variant
 'Dim ftype As String
 Dim Mydata As String
 Dim ws As Variant
 
 Filelist = Application.GetOpenFilename(ftype, 0, "Import", , True)
 If IsArray(Filelist) = False Then
  End
 End If
 
 With UserForm1
  .Label7.Caption = Mid$(Filelist(1), InStrRev(Filelist(1), "\") + 1)
  
  Open Filelist(1) For Binary As #1
   Mydata = Space$(LOF(1))
   Get #1, , Mydata
  Close #1
 
  If Len(Mydata) > 1000 Then
   geofile = Filelist(1)
   loaded = True
   .CommandButton2.Enabled = True
   .TextBox1.Enabled = True
   .TextBox2.Enabled = True
   .TextBox3.Enabled = True
   .TextBox4.Enabled = True
   .TextBox5.Enabled = True
   .TextBox6.Enabled = True
   Call speedup_on
   Call gpx(Mydata)
   Call speedup_off
   If def_loaded = False Then
    Set ws = Worksheets(1)
    .TextBox1.value = Int(central - latrng) 'nlle(1, 3) 'Trim(ws.Cells(3, 2))  'min lat
    .TextBox2.value = Int(central + latrng) 'nlle(1, 1) 'Trim(ws.Cells(2, 2))  'max
    .TextBox3.value = Int(central - lonrng) 'nlle(2, 3) 'Trim(ws.Cells(3, 3))  'min lon
    .TextBox4.value = Int(central + lonrng) 'nlle(2, 1) 'Trim(ws.Cells(2, 3))  'max
    .TextBox5.value = 0 'nlle(3, 2) 'Trim(ws.Cells(3, 4))  'min ele
    .TextBox6.value = binsmax 'nlle(3, 1) 'Trim(ws.Cells(2, 4))  'max
   Else
    .TextBox1.value = prn_def(6)  'min lat
    .TextBox2.value = prn_def(7)  'max
    .TextBox3.value = prn_def(8)  'min lon
    .TextBox4.value = prn_def(9)  'max
    .TextBox5.value = prn_def(10) 'min ele
    .TextBox6.value = prn_def(11) 'max
   End If
  Else
   loaded = False
   .CommandButton2.Enabled = False
  End If
 
 End With
 
End Sub

Private Sub CommandButton2_Click()
'run conversion
 
 Dim t1 As Single
 Dim topend As Long
 
 Call speedup_on
 
 t1 = Timer
 
 With UserForm1
  flh = .TextBox7.value
  ew = .TextBox8.value
  fd = .TextBox9.value
  x1 = .TextBox10.value
  Aroad_scaler = .TextBox11.value
  'latitude
  nlle(1, 1) = .TextBox2.value  'max
  nlle(1, 2) = .TextBox1.value  'min
  nlle(1, 3) = nlle(1, 1) - nlle(1, 2)    'range
  If Val(nlle(1, 2)) >= Val(nlle(1, 1)) Then
   response = MsgBox("Min >= Max", vbOKOnly, "Latitude")
   Exit Sub
  End If
  'longtitude
  nlle(2, 1) = .TextBox4.value  'max
  nlle(2, 2) = .TextBox3.value  'min
  nlle(2, 3) = nlle(2, 1) - nlle(2, 2)    'range
  If Val(nlle(2, 2)) >= Val(nlle(2, 1)) Then
   response = MsgBox("Min >= Max", vbOKOnly, "Longtitude")
   Exit Sub
  End If
  'elevation
  nlle(3, 1) = .TextBox6.value  'max
  nlle(3, 2) = .TextBox5.value  'min
  nlle(3, 3) = nlle(3, 1) - nlle(3, 2)    'range
  If Val(nlle(3, 2)) >= Val(nlle(3, 1)) Then
   response = MsgBox("Min >= Max", vbOKOnly, "Elevation")
   Exit Sub
  End If

 End With
 
 response = MsgBox("Check Rescale Values", vbOKCancel)
 Select Case response
  Case vbOK
  Case vbCancel
   Exit Sub
 End Select
  
 topend = layers()
 Call gcode(topend)
 
 Debug.Print Timer - t1
 
 Call speedup_off
 
 UserForm1.Label8.Caption = zlayers & " :Layers"
End Sub

Private Sub CommandButton3_Click()
 UserForm2.Show
End Sub

Private Sub UserForm_Initialize()
 latrng = (nlle(1, 1) - nlle(1, 2)) \ 2
 lonrng = (nlle(2, 1) - nlle(2, 2)) \ 2
 
 With UserForm1
  .Caption = prog$
  .TextBox1.value = "none"
  .TextBox1.Enabled = False
  .TextBox2.value = "none"
  .TextBox2.Enabled = False
  .TextBox3.value = "none"
  .TextBox3.Enabled = False
  .TextBox4.value = "none"
  .TextBox4.Enabled = False
  .TextBox5.value = "none"
  .TextBox5.Enabled = False
  .TextBox6.value = "none"
  .TextBox6.Enabled = False
  .CommandButton2.Enabled = False
  .TextBox7.value = flh
  .TextBox8.value = ew
  .TextBox9.value = fd
  .TextBox10.value = x1
  .TextBox11.value = Aroad_scaler
 End With
End Sub
