How can is see what button is pressed in a button array

Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Sep 2009
Posts: 13
Reputation: Ulukay is an unknown quantity at this point 
Solved Threads: 0
Ulukay Ulukay is offline Offline
Newbie Poster

How can is see what button is pressed in a button array

 
0
  #1
Sep 9th, 2009
I got a button array of 40 buttons
And i handle all the button events in 1 sub .
But i need to know what button is pressed.
Can someone help me ?

  1. Private bttonArray(41) As Button
  2. Public Sub Hoofdscherm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  3.  
  4. REM place the Buttons in a array
  5. bttonArray(1) = Button1
  6. bttonArray(2) = Button2
  7. bttonArray(3) = Button3
  8. bttonArray(4) = Button4
  9. bttonArray(5) = Button5
  10. bttonArray(6) = Button6
  11. bttonArray(7) = Button7
  12. bttonArray(8) = Button8
  13. bttonArray(9) = Button9
  14. bttonArray(10) = Button10
  15. bttonArray(11) = Button11
  16. bttonArray(12) = Button12
  17. bttonArray(13) = Button13
  18. bttonArray(14) = Button14
  19. bttonArray(15) = Button15
  20. bttonArray(16) = Button16
  21. bttonArray(17) = Button17
  22. bttonArray(18) = Button18
  23. bttonArray(19) = Button19
  24. bttonArray(20) = Button20
  25. bttonArray(21) = Button21
  26. bttonArray(22) = Button22
  27. bttonArray(23) = Button23
  28. bttonArray(24) = Button24
  29. bttonArray(25) = Button25
  30. bttonArray(26) = Button26
  31. bttonArray(27) = Button27
  32. bttonArray(28) = Button28
  33. bttonArray(29) = Button29
  34. bttonArray(30) = Button30
  35. bttonArray(31) = Button31
  36. bttonArray(32) = Button32
  37. bttonArray(33) = Button33
  38. bttonArray(34) = Button34
  39. bttonArray(35) = Button35
  40. bttonArray(36) = Button36
  41. bttonArray(37) = Button37
  42. bttonArray(38) = Button38
  43. bttonArray(39) = Button39
  44. bttonArray(40) = Button40
  45. For x = 1 To 40
  46. AddHandler bttonArray(x).Click, AddressOf Button_Click
  47. bttonArray(x).Show()
  48. bttonArray(x).Size = New Size(80, 23)
  49. Next x
  50. End Sub
  51.  
  52. Rem button click sub
  53. Private Sub Button_Click(ByVal sender As Object, ByVal e As System.EventArgs)
  54.  
  55. Rem now i need to know then button number
  56. bttonArray(This number i need).Text = "click"
  57. End Sub
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,636
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 472
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: How can is see what button is pressed in a button array

 
1
  #2
Sep 9th, 2009
By sender reference,
  1. CType(sender,Button).Text="Click"
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 13
Reputation: Ulukay is an unknown quantity at this point 
Solved Threads: 0
Ulukay Ulukay is offline Offline
Newbie Poster

Re: How can is see what button is pressed in a button array

 
0
  #3
Sep 9th, 2009
Thank You for you quick reply.

It works , i see the clicked button change .
But i still not know how to get the number of the button.
I tryed several things but i keep freezing my program.
Can you maybe explain , how i can place the button number in a integer ?
Last edited by Ulukay; Sep 9th, 2009 at 7:12 am.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,636
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 472
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: How can is see what button is pressed in a button array

 
1
  #4
Sep 9th, 2009
By comparing references,
  1. Dim btn As Button = CType(sender, Button)
  2. Dim i As Integer
  3. For i = 0 To bttonArray.Length - 1
  4. If btn.Equals(bttonArray(i)) Then
  5. 'statements
  6. End If
  7. Next

EDIT:
variable name changed.
Last edited by adatapost; Sep 9th, 2009 at 7:33 am. Reason: variable name changed.
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 13
Reputation: Ulukay is an unknown quantity at this point 
Solved Threads: 0
Ulukay Ulukay is offline Offline
Newbie Poster

Re: How can is see what button is pressed in a button array

 
0
  #5
Sep 9th, 2009
No i get "name c is not declared"
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 13
Reputation: Ulukay is an unknown quantity at this point 
Solved Threads: 0
Ulukay Ulukay is offline Offline
Newbie Poster

Re: How can is see what button is pressed in a button array

 
0
  #6
Sep 9th, 2009
Im only programming in VB for a week
Im used to program on the AMIGA in GFAbasic
And i find VB very confusing
So this was a great help
Thank you very mutch

Sincerely yours

Jack
Last edited by Ulukay; Sep 9th, 2009 at 8:32 am.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,636
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 472
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: How can is see what button is pressed in a button array

 
0
  #7
Sep 9th, 2009
Thanks Jack. Purchase some good books of .net framework, and vb.net.
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Reply

Tags
array, buttons, click

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC