home *** CD-ROM | disk | FTP | other *** search
- DefInt A-Z
-
- Sub calibrate (thisform As Form)
- '***********************************
- ' calibrate the joystick to a form
- '***********************************
- Static busy As Integer
-
- On Error GoTo errorhandler
- If busy = True Then Exit Sub
- busy = True
- FORM2.Show
- restart:
- ' lower right
- FORM2.Label1.Caption = "Move the joystick to the lower right position and press a button"
- FORM2.Picture1(1).Visible = False
- FORM2.Picture1(3).Visible = True
- 'wait for button
- Do
- dummy = DoEvents()
- Loop While button_mark = False
- button_mark = False
- ymax = 20000
- xmax = 20000
-
- '*******************************************
- ' If the x and y values do not convert to *
- ' values that exactly match the current *
- ' corner, adjust xmax and ymax so that *
- ' x and y values convert to correct value *
- '*******************************************
-
-
- Do
-
- convert calx, ymax, thisform
- If winpoint.x > winxmax Then
- If winpoint.x - winxmax > 100 Then
- xmax = xmax + 100
- Else
- xmax = xmax + 1
- End If
- ElseIf winpoint.x < winxmax Then
- If winxmax - winpoint.x > 100 Then
- xmax = xmax - 100
- Else
- xmax = xmax - 1
- End If
- End If
- Loop While winpoint.x <> winxmax
-
- Do
- convert xmax, caly, thisform
- 'Debug.Print caly, ymax, winpoint.y, winymax
- If winpoint.y > winymax Then
- If winpoint.y - winymax > 100 Then
- ymax = ymax + 100
- Else
- ymax = ymax + 1
- End If
- ElseIf winpoint.y < winymax Then
- If winymax - winpoint.y > 100 Then
- ymax = ymax - 100
- Else
- ymax = ymax - 1
- End If
- End If
- Loop While winpoint.y <> winymax
-
- ' lower left
- FORM2.Label1.Caption = "Move the joystick to the lower left position and press a button"
- FORM2.Picture1(3).Visible = False
- FORM2.Picture1(2).Visible = True
- Do
- dummy = DoEvents()
- Loop While button_mark = False
- button_mark = False
- xmin = 0
- Do
- convert calx, ymax, thisform
- If winpoint.x < winxmin Then
- If winxmax - winpoint.x > 100 Then
- xmax = xmax - 100
- Else
- xmax = xmax - 1
- End If
-
- ElseIf winpoint.x > winxmin Then
- If winpoint.x - winxmin > 100 Then
- xmax = xmax + 100
- Else
- xmax = xmax + 1
- End If
- End If
- Loop While winpoint.x <> winxmin
-
- If caly < ymax Then
- Do
- convert xmin, caly, thisform
- If winpoint.y > winymax Then
- If winpoint.y - winymax > 100 Then
- ymax = ymax + 100
- Else
- ymax = ymax + 1
- End If
- ElseIf winpoint.y < winymax Then
- If winymax - winpoint.y > 100 Then
- ymax = ymax - 100
- Else
- ymax = ymax - 1
- End If
-
- End If
- Loop While winpoint.y <> winymax
- End If
-
- button_mark = False
-
-
- ' upper left
- FORM2.Label1.Caption = "Move the joystick to the upper left position and press a button"
- FORM2.Picture1(2).Visible = False
- FORM2.Picture1(0).Visible = True
- Do
- dummy = DoEvents()
- Loop While button_mark = False
- button_mark = False
- ymin = 0
- Do
- convert calx, ymin, thisform
- If winpoint.x < winxmin Then
- If winxmin - winpoint.x > 100 Then
- xmax = xmax - 100
- Else
- xmax = xmax - 1
- End If
- ElseIf winpoint.x > winxmin Then
- If winpoint.x - winxmin > 100 Then
- xmax = xmax + 100
- Else
- xmax = xmax + 1
- End If
- End If
- Loop While winpoint.x <> winxmin
- If caly < ymin Then
- Do
- convert xmin, caly, thisform
- Debug.Print caly, ymin, winpoint.y, winymin
- If winpoint.y > winymin Then
- If winpoint.y - winymin > 100 Then
- ymin = ymin - 100
- Else
- ymin = ymin - 1
- End If
- ElseIf winpoint.y < winymin Then
- If winymin - winpoint.y > 100 Then
- ymin = ymin + 100
- Else
- ymin = ymin + 1
- End If
- End If
- Loop While winpoint.y <> winymin
- End If
-
- ' upper right
- FORM2.Label1.Caption = "Move the joystick to the upper right position and press a button"
- FORM2.Picture1(0).Visible = False
- FORM2.Picture1(1).Visible = True
-
- Do
- dummy = DoEvents()
- Loop While button_mark = False
- button_mark = False
- If calx < xmax Then
- Do
- convert calx, ymin, thisform
- If winpoint.x > winxmax Then
- If winpoint.x - winxmax > 100 Then
- xmax = xmax + 100
- Else
- xmax = xmax + 1
- End If
- ElseIf winpoint.x < winxmax Then
- If winxmax - winpoint.x > 100 Then
- xmax = xmax - 100
- Else
- xmax = xmax - 1
- End If
- End If
- Loop While winpoint.x <> winxmax
- End If
-
- If caly < ymin Then
- Do
- convert xmax, caly, thisform
- If winpoint.y > winymin Then
- If winpoint.y - winymin > 100 Then
- ymin = ymin - 100
- Else
- ymin = ymin - 1
- End If
- ElseIf winpoint.y < winymin Then
- If winymin - winpoint.y > 100 Then
- ymin = ymin + 100
- Else
- ymin = ymin + 1
- End If
- End If
- Loop While winpoint.y <> winymin
- End If
- FORM2.Picture1(3).Visible = False
-
-
-
- busy = False
- need_calibrate = False
- On Error GoTo 0' disable error handler
- Unload FORM2
- Exit Sub
-
- errorhandler:
- If Err = 6 Then 'Overflow-button pressed in wrong place
- msg$ = "An error has occurred during Calibration." + Chr$(13) + Chr$(10)
- msg$ = msg$ + "Calibration will now restart"
- MsgBox msg$, 49, "Calibrating Joystick"
- Resume restart
- Else
- msg$ = "An unexpected error has occurred:" + Chr$(13) + Chr$(10)
- msg$ = msg$ + Error$ + Chr$(13) + Chr$(10)
- msg$ = msg$ + "The program will now terminate"
- MsgBox msg$, 16, "Calibrating Joystick"
- End
- End If
- End Sub
-
-