Results 1 to 9 of 9

Thread: [2005] simultaneous button click

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2008
    Posts
    14

    [2005] simultaneous button click

    Hello everybody,
    i'm making a program in vb 2005 and i have a problem...i m trying to make two buttons work(be clicked and selected) programmatically...by clicking a third button...the only problem is that i want the two buttons to work simultaneously...so here is my code

    Button2.PerformClick()
    Button2.Select()
    Button3.PerformClick()
    Button3.Select()

    this code is inside Button4 for example...
    now, this code performs only the methods for Button3 because it's the last one...
    how can i make the two buttons work simultaneously???
    i know that this approach is kind of wrong...but i would really appreciate your help...

    note:the two buttons contain .wav sounds that i have recorded(just to know)...

    thank you for your time
    sorry for my english...
    theodora
    Last edited by theopres; Oct 21st, 2008 at 09:26 AM.

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,109

    Re: [2005] simultaneous button click

    You're going to have the problem that two buttons can never be clicked simultaneously in a single threaded app (and not really in a multithreaded app). Each button click posts a message to the process message queue, and one will always be ahead of the other.

    I see that you are playing sounds, which I have never dealt with, so they may work differently, but if each button click event just had a sub like this:
    Code:
    Button2Click()
     PlaySound(2)
    End sub
    
    Button3Click()
     PlaySound(3)
    End Sub
    Then you would simulate clicking the two buttons by calling:

    PlaySound(2)
    PlaySound(3)

    Obviously, this would NOT act like two simultaneous button clicks, since one would happen just before the other one. However, that's how the actual button clicks happen anyways, so this example is the functional equivalent to having each button click event be called specifically.

    What I don't know, having never worked with sound, is whether you can play one sound and start a second sound before the first one has finished playing.
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2008
    Posts
    14
    Thank you for your help Shaggy...
    i knew that was going to be the answer ...i just needed the help of someone more experienced than me...
    i m actually making o guitar program and i want to make two strings sound like one but also show that on the fretboard...that's why i needed the buttons to be selected...(each button plays one string)...well....i m going to use flashing lights on the fret to show that...(i'll try)..

    as far as i know in vb 2005 you can't make two sounds play simultaneously(that's why i said that my approach is wrong)...specially if you're using System.Media.SoundPlayer...i just wanted to see if i can do that throught the buttons...

    Hope i didn't mess things up for you
    my english ain't that good
    thank you for your time...
    theodora

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,109

    Re: [2005] simultaneous button click

    Your english is actually quite good. Doubtless it is better than my inability at whatever is your native tongue.

    Actually, what you are trying to do must be possible, because I have played games where there were multiple sound clips overlapping. How it is done I don't know, but I would guess that it may require playing each sound on a different thread, or something like that. In your case, that is probably worth considering, since a guitar string would be a single note fading in volume over time, and without the ability to play two notes at the same time, computer sound would have to be really simplistic. Thus I believe it can be done, but exactly how I don't know. Somebody with more knowledge about playing sounds would be better equipt to answer.
    My usual boring signature: Nothing

  5. #5
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Re: [2005] simultaneous button click

    Hi,

    Perhaps it isn't that what you need, but this is an example how to click simultaneous:

    vb.net Code:
    1. Dim the_clics As Integer
    2.     Dim my_clics As Integer
    3.  
    4.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    5.         If the_clics Mod 2 = 0 Then
    6.             Button1.Text = "Hello"
    7.         Else
    8.             Button1.Text = "Goodbye"
    9.         End If
    10.  
    11.         the_clics += 1
    12.     End Sub
    13.  
    14.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    15.         If my_clics Mod 2 = 0 Then
    16.             Me.BackColor = Color.Green
    17.         Else
    18.             Me.BackColor = Color.Blue
    19.         End If
    20.  
    21.         my_clics += 1
    22.  
    23.     End Sub
    24.  
    25.     Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    26.         Button1.PerformClick()
    27.         Button2.PerformClick()
    28.     End Sub

    Hope it's a start,

    sparrow1
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  6. #6
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Boston, MA
    Posts
    391

    Re: [2005] simultaneous button click

    Generally speaking if you want two things to happen at the "same time" (though not really, just close) you're going to have to use Threads. In that way you can have a thread start doing some work and launch another thread to do something else without having to wait for the first thread to finish it's job.

    Now, if all you want to do is play sounds, while I don't know for sure I would wager that the player can play sounds asynchronously. Have you looked at directx?.... Okay a quick search turned up this http://www.vbforums.com/showthread.php?p=2586544.... I think that will help.

  7. #7

    Thread Starter
    New Member
    Join Date
    Oct 2008
    Posts
    14

    Re: [2005] simultaneous button click

    Thank you all for your help...yes, the way to play simultaneous sounds in vb 2005 is through directX SDK...!
    Also, thank you sparrow1 for the code...it has been very helpful although i started using a different approach now...
    Anyway...
    Thank you all for your time...
    theodora

  8. #8
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Sector 001
    Posts
    1,577

    Re: [2005] simultaneous button click

    You can also use MCI. It can sound pretty simultaneously to humans.
    VB 2005, Win Xp Pro sp2

  9. #9

    Thread Starter
    New Member
    Join Date
    Oct 2008
    Posts
    14

    Re: [2005] simultaneous button click

    oups it seems i have a different kind of problem now...

    i managed to play simultaneous sounds by using DirectX like this

    Dim Play1 As New DirectX.AudioVideoPlayback.Audio("c:\cuckoo.wav")
    Dim Play2 As New DirectX.AudioVideoPlayback.Audio("c:\cuckoo2.wav")

    Play1.Play()
    Play2.Play()

    it seems that DirectX.AudioVideoPlayback.Audio accepts only filenames/URLs to load audio files. i added my sounds to the application's resources but i can't find a way to call them since i'm using directX.
    Does anyone know if i can call stored audio files by using directX???
    i really want the program to run on other computers,too.

    Thank you,
    theodora
    Last edited by theopres; Oct 22nd, 2008 at 10:40 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width