| | |
A lot of subs into only one
Please support our VB.NET advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jul 2009
Posts: 3
Reputation:
Solved Threads: 0
Hello,
I'm a beginner in Visual Basic and I was wondering if it is possible to shorten twenty subs into only 1 sub.
example:
Thank you
I'm a beginner in Visual Basic and I was wondering if it is possible to shorten twenty subs into only 1 sub.
example:
VB.NET Syntax (Toggle Plain Text)
Private Sub box1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles kist1.Click Dim box1Click As Boolean = True End Sub Private Sub box2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles kist1.Click Dim box2Click As Boolean = True End Sub ... Private Sub box20_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles kist1.Click Dim box20Click As Boolean = True End Sub
Thank you
•
•
Join Date: Jun 2009
Posts: 271
Reputation:
Solved Threads: 56
1
#3 Nov 2nd, 2009
actually it is possible. not very sexy but possible...
vb Syntax (Toggle Plain Text)
Private Sub box1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles box1.Click, box2.Click, box3.Click Select Case sender.Name Case "box1" 'code for box1 Case "box2" 'code for box2 Case "box3" 'code for box3 Case Else End Select End Sub
•
•
Join Date: Sep 2009
Posts: 42
Reputation:
Solved Threads: 5
0
#4 Nov 2nd, 2009
•
•
•
•
Hello,
I'm a beginner in Visual Basic and I was wondering if it is possible to shorten twenty subs into only 1 sub.
example:
VB.NET Syntax (Toggle Plain Text)
Private Sub box1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles kist1.Click Dim box1Click As Boolean = True End Sub Private Sub box2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles kist1.Click Dim box2Click As Boolean = True End Sub ... Private Sub box20_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles kist1.Click Dim box20Click As Boolean = True End Sub
Thank you
2. Your examples creates a variable, sets its value, and then discards it without doing anything with it. That doesn't make sense, but you can do multiple things that don't make sense in one routine just as well as 20.
3. Since it passes "ByVal sender As System.Object", this routine is designed to handle multiple events, and is fairly easy to do in C#, but since I am a beginner, I too don't know how to direct multiple objects' one event type to one subroutine. I've got 9 routines that call one routine passing a Byte that tells me which object was called and it does the work. It would have been helpful to know how to do this in VB.NET as well.
PS You can put common logic in one routine and call it 20 times:
VB.NET Syntax (Toggle Plain Text)
Private Sub General_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 'Do something more complex like Dim btn As System.Windows.Forms.Button btn = sender If btn.Name = "Calculate_btn" Then 'do something End If End Sub Private Sub Calculate1_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Calculate_btn1.Click General_btn_Click(sender, e) End Sub
Last edited by kplcjl; Nov 2nd, 2009 at 11:00 pm. Reason: Trying to make what I said clearer
![]() |
Similar Threads
- Reserved Words in VB6 (Visual Basic 4 / 5 / 6)
- Passing arrays between subs (VB.NET)
- Something wrong with this (Visual Basic 4 / 5 / 6)
- Completed Code but A LOT of GOTO...Replacement? (C++)
- 1000 MB Space 100 Gigs file transfer Unlimited Subs-Email 3.50 mo.With Cpanel (Web Hosting Deals)
- php phpmyadmin problem ?? (PHP)
- passing arrays in visual basic (Visual Basic 4 / 5 / 6)
Other Threads in the VB.NET Forum
- Previous Thread: How to delete a record from a DB?
- Next Thread: help with windows form applications
Views: 200 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for VB.NET
"crystal .net .net2005 30minutes 2008 access application arithmetic array assignment basic binary bing box button buttons c# center code combobox component connectionstring convert data database databasesearch datagrid datagridview design designer dissertation dissertations dissertationthesis dll dosconsolevb.net error excel file-dialog firewall folder google hardcopy highlighting image images isnumericfuntioncall listview login math memory mobile ms navigate net networking opacity output peertopeervideostreaming picturebox picturebox1 plugin port print printing problem problemwithinstallation project reports" save savedialog serial server sorting sql string studio syntax temp text textbox timer toolbox updown upload useraccounts usercontrol vb vb.net vb.netcode vb.nettoolboxvisualbasic2008sidebar vb2008 vbnet view visual visualbasic visualbasic.net visualstudio visualstudio2008 web wpf





