943,816 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 2761
  • VB.NET RSS
Sep 9th, 2009
0

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

Expand Post »
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 ?

VB.NET Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Ulukay is offline Offline
18 posts
since Sep 2009
Sep 9th, 2009
1

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

By sender reference,
VB.NET Syntax (Toggle Plain Text)
  1. CType(sender,Button).Text="Click"
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008
Sep 9th, 2009
0

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

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Ulukay is offline Offline
18 posts
since Sep 2009
Sep 9th, 2009
1

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

By comparing references,
VB.NET Syntax (Toggle Plain Text)
  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.
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008
Sep 9th, 2009
0

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

No i get "name c is not declared"
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Ulukay is offline Offline
18 posts
since Sep 2009
Sep 9th, 2009
0

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

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Ulukay is offline Offline
18 posts
since Sep 2009
Sep 9th, 2009
0

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

Thanks Jack. Purchase some good books of .net framework, and vb.net.
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008
Dec 9th, 2009
0
Re: How can is see what button is pressed in a button array
' ********************************************
' ** Button clicked so carry out the event **
' ********************************************
VB.NET Syntax (Toggle Plain Text)
  1. Private Sub btnEvents_Click(ByVal sender As System.Object, ByVal e As EventArgs) Handles MyBase.Click
  2. Dim cString As String = sender.Text()
  3. 'Dim myObject As Object = sender
  4.  
  5.  
  6. Select Case cString
  7. Case "Add"
  8. ....
Last edited by adatapost; Dec 9th, 2009 at 7:31 am. Reason: Added [code] tags. Encase your code in: [code] and [/code]
Reputation Points: 10
Solved Threads: 0
Newbie Poster
morke is offline Offline
3 posts
since Jan 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Button Array
Next Thread in VB.NET Forum Timeline: SOmeone PLSSS help me on thiss vb question..





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC