Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Passing a control as a reference
Message
 
To
30/12/2004 20:25:23
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
00973454
Message ID:
00973470
Views:
14
I think your problem is the default value you need to give to the optional parameter.

Why don't you create an overloaded method?
    Private overloads Sub AddToLog(ByVal tcString As String)
        Log.Text += "Started: " + Date.Now + Chr(13) + Chr(10)
        Log.Text += tcString + Chr(13) + Chr(10)
        CursorLog()
    End Sub
    Private overloads Sub AddToLog(ByVal tcString As String, ByVal toObject As Object )
        toObject.Text += "Started: " + Date.Now + Chr(13) + Chr(10)
        toObject.Text += tcString + Chr(13) + Chr(10)
        CursorLog()
    End Sub
>I have a log function which is like this:
>
>
>    Private Sub AddToLog(ByVal tcString As String)
>        Log.Text = Log.Text + "Started: " + Date.Now + Chr(13) + Chr(10)
>        Log.Text = Log.Text + tcString + Chr(13) + Chr(10)
>        CursorLog()
>    End Sub
>
>
>As I have two logs on the form, I would like to pass an additional parameter for the TextControl to be used. So, I have updated the function like this:
>
>
>    Private Sub AddToLog(ByVal tcString As String, Optional ByVal toObject As Object = "Log")
>        toObject.Text = toObject.Text + "Started: " + Date.Now + Chr(13) + Chr(10)
>        toObject.Text = toObject.Text + tcString + Chr(13) + Chr(10)
>        CursorLog()
>    End Sub
>
>
>However, this generates development time error. This is normal as toObject is not a control on the form. How can I achieve that?
Éric Moreau, MCPD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
Moer inc.
http://www.emoreau.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform