Click here to Skip to main content
14,825,984 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: Bubble sort an array of Structure Pin
TwoFaced3-May-07 13:35
MemberTwoFaced3-May-07 13:35 
QuestionChecking for overlapping timespans Pin
fp2billiards3-May-07 11:05
Memberfp2billiards3-May-07 11:05 
AnswerRe: Checking for overlapping timespans Pin
Arun.Immanuel3-May-07 15:53
MemberArun.Immanuel3-May-07 15:53 
QuestionUsing a filter on BindingSource with BindingList Pin
Mightor3-May-07 9:44
MemberMightor3-May-07 9:44 
AnswerRe: Using a filter on BindingSource with BindingList Pin
Dave Kreskowiak4-May-07 3:50
mveDave Kreskowiak4-May-07 3:50 
GeneralRe: Using a filter on BindingSource with BindingList Pin
Mightor4-May-07 9:17
MemberMightor4-May-07 9:17 
QuestionConvert 2003 to 2005 Errors Pin
Central_IT3-May-07 9:34
MemberCentral_IT3-May-07 9:34 
AnswerRe: Convert 2003 to 2005 Errors Pin
Dave Kreskowiak3-May-07 9:42
mveDave Kreskowiak3-May-07 9:42 
Easy. sender is passed as Object, which can be anything, including an object that doesn't have a Name property.

Test, then Cast sender to the object type you expect it to be, like Button in your code:
Private Sub SomeSub(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click
    If TypeOf sender Is Button Then
        Dim s As Button = DirectCast(sender, Button)
        Select Case s.Name
            Case "Button1"
                ' Do something
            Case "Button2"
                ' Do something
            Case Else
                ' This should never happen, but then again...
        End Select
    End If
End Sub

Doing this isn't a good idea. Simply renaming a button can cause your code to fail and be pretty difficult to track the problem down. Break your button handlers in their own methods and you'll increase your codes maintainability.


Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic
     2006, 2007


GeneralRe: Convert 2003 to 2005 Errors Pin
Central_IT3-May-07 9:49
MemberCentral_IT3-May-07 9:49 
GeneralRe: Convert 2003 to 2005 Errors Pin
Central_IT3-May-07 10:02
MemberCentral_IT3-May-07 10:02 
GeneralRe: Convert 2003 to 2005 Errors Pin
Dave Kreskowiak3-May-07 13:34
mveDave Kreskowiak3-May-07 13:34 
GeneralRe: Convert 2003 to 2005 Errors Pin
Central_IT4-May-07 1:36
MemberCentral_IT4-May-07 1:36 
GeneralRe: Convert 2003 to 2005 Errors Pin
Dave Kreskowiak4-May-07 2:31
mveDave Kreskowiak4-May-07 2:31 
QuestionCreating a Help System for a VB.NET Project Pin
RichFeldman3-May-07 8:23
MemberRichFeldman3-May-07 8:23 
AnswerRe: Creating a Help System for a VB.NET Project Pin
MatrixCoder3-May-07 11:19
MemberMatrixCoder3-May-07 11:19 
Question[02/03] Please help graphing datasource Pin
Srigopal0073-May-07 8:19
MemberSrigopal0073-May-07 8:19 
QuestionError While Creating Publish Pin
vurugonda3-May-07 7:53
Membervurugonda3-May-07 7:53 
QuestionInstalling a Windows Service and the GAC Pin
Terry Porter3-May-07 6:04
MemberTerry Porter3-May-07 6:04 
AnswerRe: Installing a Windows Service and the GAC Pin
kubben3-May-07 6:24
Memberkubben3-May-07 6:24 
GeneralRe: Installing a Windows Service and the GAC Pin
Terry Porter3-May-07 6:33
MemberTerry Porter3-May-07 6:33 
Questionsearch for files Pin
jds12073-May-07 5:35
Memberjds12073-May-07 5:35 
AnswerRe: search for files Pin
kubben3-May-07 6:31
Memberkubben3-May-07 6:31 
GeneralRe: search for files Pin
jds12073-May-07 7:53
Memberjds12073-May-07 7:53 
AnswerRe: search for files Pin
jds12073-May-07 10:03
Memberjds12073-May-07 10:03 
Questionvb-dll problem Pin
aamn13-May-07 5:18
Memberaamn13-May-07 5:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.