Dec 11, 2009 at 9:45 PM
Edited Dec 11, 2009 at 9:48 PM
Below is some code that I am having a problem with ... If anyone has ANY idea what is going on here, I would greatly appreciate the input ... I will explain what I do with the wiiMote while the prog is running, and the debug output ...
Ok, I start the prog and click Button7 ... After a second or two, the battery level is printed in the debug window ... All is good.
Next, I press (and hold) A on the wiiMote ... 'True:False' is printed ... All is good.
Next, I let go of A on the wiiMote ... 'False:False' is printed ... THIS IS WRONG - PrevState.ButtonStatus.A (the second item printed) SHOULD BE TRUE
Next, I press (and hold) A on the wiiMote ... 'True:True' is printed ... THIS IS WRONG - PrevState.ButtonStatus.A (the second item printed) SHOULD BE FALSE
If I change 'PrevStat = CurrStat' to 'PrevStat.ButtonState = CurrStat.ButtonState' it works correctly. This indicates to me that the statement 'PrevStat = CurrStat' is setting the reference not the value (not sure if this even makes sense, let alone
how to fix it).
Dim CurrStat As WiimoteLib.WiimoteState
Dim PrevStat As WiimoteLib.WiimoteState
Sub Button7Click(sender As Object, e As EventArgs)
Dim wiiMote As New WiimoteLib.Wiimote
Dim wiiMoteCol As New WiimoteLib.WiimoteCollection
wiiMote = wiiMoteCol.Item(0)
PrevStat = wiiMote.WiimoteState
AddHandler wiiMote.WiimoteChanged, AddressOf EventHandler
Sub EventHandler(sender as Object, wiiMoteChangedEventArgs as WiimoteLib.WiimoteChangedEventArgs)
CurrStat = wiiMoteChangedEventArgs.WiimoteState
debug.Print(CurrStat.ButtonState.A & ":" & PrevStat.ButtonState.A)
PrevStat = CurrStat