|
Here is something that may help.
http://www.codeproject.com/cs/media/DirectSound9p2.asp[^]
The Win32 multimedia APIs look very complicated, you best bet is DirectX. I would also check out the XNA Framework from Microsoft. Download XNA Studio Express and check it out.
█▒▒▒▒▒██▒█▒██
█▒█████▒▒▒▒▒█
█▒██████▒█▒██
█▒█████▒▒▒▒▒█
█▒▒▒▒▒██▒█▒██
|
|
|
|
|
I need to make 1 of my textboxes (which displays available system RAM) update itself every few seconds, now I very easily understand this example:
http://abstractvb.com/code.asp?F=26&P=1&A=1032[^]
BUT...
It up an exception saying something about threading.. has VB 2005 gone mad and is trying to eternally pee on me! or am i doing something wrong because i followed that exactly and i get that exception...?
|
|
|
|
|
Can you please post the exact error?
|
|
|
|
|
|
Use a timer control instead. It runs in the same thread.
---
b { font-weight: normal; }
|
|
|
|
|
I havent used timer controls, how would i type one out?
|
|
|
|
|
Just type:
Dim TimerControl As New Timer
|
|
|
|
|
oh ok thanks
|
|
|
|
|
Just drag the Timer control from the toolbox to your form.
---
b { font-weight: normal; }
|
|
|
|
|
ah cool
|
|
|
|
|
I am trying to format cost once the file is written to the database. Here is what I have:
Dim FormatCost As String
FormatCost = Format(row("coreprice").ToString(), "c")
It is displaying c instead of the actual number, but when I do this for example:
MessageBox.Show(Format(553378.6789, "c"))
This code works fine.
Any advice will be greatly appreciated!
jds1207
|
|
|
|
|
your using your ToString too early. you can only format a number/date. if the argument is a string, it doesn't understand that.
FormatCost = format(CSng(row('coreprice")),"c").tostring
|
|
|
|
|
|
FormatCost = String.Format(CSng(row("coreprice")), "c")
You do NOT need to call ToString on the return value of Format, since it's already a String.
Sorry, just one of my pet peeves.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
My apologies...I find extra operations annoying as well...
|
|
|
|
|
please tell me how to do numlock and caplock on or off show in statusbar panel.
Thanks.
Rehan.
|
|
|
|
|
Easy. Create 2 Status strip labels (CapsText and NumText). Then, create a timer and set it's value for about 100 milliseconds. Then in the timer control, type:
<br />
If My.Computer.Keyboard.CapsLock = True Then<br />
CapsText.Text = "Caps On"<br />
End If<br />
If My.Computer.Keyboard.CapsLock = False Then<br />
CapsText.Text = "Caps Off"<br />
End If<br />
<br />
If My.Computer.Keyboard.NumLock = True Then<br />
Numtext.Text = "Num On"<br />
End If<br />
If My.Computer.Keyboard.NumLock = False Then<br />
NumText.Text = "Num Off"<br />
End If<br />
I hope this helps. Be sure to have the timer go off frequently, otherwise there will be a delay between the user hitting the key and the text changing.
|
|
|
|
|
Bad solution. You do not need a Timer to do this. See my post to the OP for a better solution.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Handle your Form's KeyDown or KeyUp event (the KeyPreview property of the form needs to be turned on!) and look for the keycodes NumLock and Capital, then update whatever control you're using as a status indicator appropriately.
Private Sub Form_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.NumLock Then
' Keyboard.Numlock will return True or False depending on the status
' of the indicator light on the keyboard.
UpdateNumLockIndicator(My.Computer.Keyboard.NumLock)
End If
If e.KeyCode = Keys.Capital Then
UpdateCapsLockIndicator(My.Computer.Keyboard.CapsLock)
End If
End Sub
...and you do NOT need a Timer to do this!
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Forgive but wouldn't this only handle the event when your form has focus? If you minimized your form and hit numlock, then maximized your form, it wouldn't know that the numlock was changed. I believe that's the purpose of the timer. So to solve this on a form_resize event, call the code on a windowstate change from minimized.
Private Sub Form2_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
if me.WindowState<>FormWindowState.Minimized then
UpdateNumLockIndicator(My.Computer.Keyboard.NumLock)
UpdateCapsLockIndicator(My.Computer.Keyboard.CapsLock)
end if
End Sub
Actually you would need to put it on the Form_Activate event as well...
|
|
|
|
|
There are a few other events you would have to handle to always know the state of the keyboard.
I'm not saying a timer is perfect, but definitely less coding.
Maybe a keyboard hook?
|
|
|
|
|
A keyboard hook would be the ultimate solution for the problem.
I personally, favor more coding over the use of more resources. Using a Timer and redrawing the status control every 100ms imports its own problems, especially in an environment that makes heavy use of custom drawn controls that take some time to draw.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
That's why I used a timer!
|
|
|
|
|
Yep, but the whole point is that a Timer is totally unnecessary and overkill since Ultra's example would needlessly redraw the status control every 100ms.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
thank for the answer but i am using visual basic.net 2003 in this vision i find error: (variable not declear) in "UpdateNumLockIndicator" & "My.Computer.Keyboard.NumLock"
please help me in this case.
thanks.
Rehan.
|
|
|
|