PDA

Click to See Complete Forum and Search --> : Joystick control


khuber
Aug 28th, 2000, 10:35 AM
I'm desperately trying to make sense out of a VB joystick tutorial at the following web address:

http://msdn.microsoft.com/library/psdk/directx/vbditut_9jky.htm

I've modified it slightly because I don't need to use a list box for my joystick, because I'm in a controled environment. So my code looks as follows:
_____________________________________________________

Dim dx As New DirectX7
Dim EventHandle As Long
Dim di As DirectInput
Dim diDev As DirectInputDevice
Dim diDevEnum As DirectInputEnumDevices
Dim joyCaps As DIDEVCAPS

Sub InitDirectInput()
'On Error GoTo Error_Out

Set di = dx.DirectInputCreate()
Set diDevEnum = di.GetDIEnumDevices( _
DIDEVTYPE_JOYSTICK, DIEDFL_ATTACHEDONLY)
If diDevEnum.GetCount = 0 Then
MsgBox "No joystick attached."
Unload Me
End If

Set diDev = di.CreateDevice(diDevEnum.GetItem(1).GetGuidInstance)
diDev.SetCommonDataFormat DIFORMAT_JOYSTICK
diDev.SetCooperativeLevel Me.hWnd, _
DISCL_EXCLUSIVE Or DISCL_BACKGROUND
diDev.GetDeviceInfo.GetGuidInstance


'Get an event handle to associate with the device
EventHandle = dx.CreateEvent(Me)
Exit Sub

Error_Out:
MsgBox "Error initializing DirectInput."
Unload Me

End Sub
_____________________________________________________

I have not gotten past the 1st step yet, because of the "EventHandle = dx.CreateEvent(Me)" line. I get a run-time error '13': Type mismatch.

I'm using MS win 2k with a Microsoft Precision Pro(USB) joystick. It's driving me a little nuts. The tutorial is missing some kind of decleration of an object I think but not really sure how to fix it.

Leave it to microsoft to leave a tutorial up that preassumes knowledge to make the script work? whats the point of putting a tutorial up if they don't tell you everything that is needed to make it work?

Thanks for any help on this matter, KWH