Click here to Skip to main content
15,913,773 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: Bubble sort an array of Structure Pin
TwoFaced3-May-07 13:35
TwoFaced3-May-07 13:35 
QuestionChecking for overlapping timespans Pin
fp2billiards3-May-07 11:05
fp2billiards3-May-07 11:05 
AnswerRe: Checking for overlapping timespans Pin
Arun.Immanuel3-May-07 15:53
Arun.Immanuel3-May-07 15:53 
QuestionUsing a filter on BindingSource with BindingList Pin
Mightor3-May-07 9:44
Mightor3-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
Mightor4-May-07 9:17 
QuestionConvert 2003 to 2005 Errors Pin
Central_IT3-May-07 9:34
Central_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
Central_IT3-May-07 9:49 
GeneralRe: Convert 2003 to 2005 Errors Pin
Central_IT3-May-07 10:02
Central_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
Central_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
RichFeldman3-May-07 8:23 
AnswerRe: Creating a Help System for a VB.NET Project Pin
MatrixCoder3-May-07 11:19
MatrixCoder3-May-07 11:19 
Question[02/03] Please help graphing datasource Pin
Srigopal0073-May-07 8:19
Srigopal0073-May-07 8:19 
QuestionError While Creating Publish Pin
vurugonda3-May-07 7:53
vurugonda3-May-07 7:53 
QuestionInstalling a Windows Service and the GAC Pin
Terry Porter3-May-07 6:04
Terry Porter3-May-07 6:04 
AnswerRe: Installing a Windows Service and the GAC Pin
kubben3-May-07 6:24
kubben3-May-07 6:24 
GeneralRe: Installing a Windows Service and the GAC Pin
Terry Porter3-May-07 6:33
Terry Porter3-May-07 6:33 
Questionsearch for files Pin
jds12073-May-07 5:35
jds12073-May-07 5:35 
AnswerRe: search for files Pin
kubben3-May-07 6:31
kubben3-May-07 6:31 
GeneralRe: search for files Pin
jds12073-May-07 7:53
jds12073-May-07 7:53 
AnswerRe: search for files Pin
jds12073-May-07 10:03
jds12073-May-07 10:03 
Questionvb-dll problem Pin
aamn13-May-07 5:18
aamn13-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.