-
Object REferences from within a class.
I'm new to vb.net so forgive me this is most likly a stupid question but I
can't find the answer to it... I've been trying to port my addtext class
for a richtextbox from 6.0 to .net
on my frmmain I have a richtextbox called logtext.
I then made a class..
Public Class addtext
Dim frmmain As frmmain
Public Sub addtime(ByVal chatbox As String)
With frmmain.logtext
.SelectionStart = Len(.Text)
.SelectionLength = 0
.Text = "[" & TimeOfDay & "]"
End With
End Sub
Public Sub Addtext(ByVal color As System.Drawing.Color, ByVal mytext
As String, ByVal chatbox As String, ByVal usetimestamp As Boolean)
If chatbox = 1 Then
If usetimestamp = True Then
addtime(1)
Else
End If
With frmmain.logtext
.SelectionStart = Len(.Text)
.SelectionLength = 0
.SelectionColor = color
.Text = mytext
.SelectionStart = Len(.Text) + 1
End With
End If
End Sub
End Class
my problem is that .text im not sure is the same as .seltext because it wasn't
in vb 6.0 SO what function do I use...
and my second problem is that it complains that i need an object reference
to frmmain.logtext but i tried dim frmmain as frmmain
and that works until you compile and it complains that it has to reference
an instance. So how do I reference an instance thats already running. in
6.0 i could just do frmmain.logtext
I much appreciate the help. Thanks in advance
Tyler
-
Re: Object REferences from within a class.
"Tyler W" <novas1313@novaslp.net> wrote:
>
>I'm new to vb.net so forgive me this is most likly a stupid question but
I
>can't find the answer to it... I've been trying to port my addtext class
>for a richtextbox from 6.0 to .net
>
>on my frmmain I have a richtextbox called logtext.
>
>I then made a class..
>
>Public Class addtext
> Dim frmmain As frmmain
> Public Sub addtime(ByVal chatbox As String)
> With frmmain.logtext
> .SelectionStart = Len(.Text)
> .SelectionLength = 0
> .Text = "[" & TimeOfDay & "]"
> End With
> End Sub
> Public Sub Addtext(ByVal color As System.Drawing.Color, ByVal mytext
>As String, ByVal chatbox As String, ByVal usetimestamp As Boolean)
> If chatbox = 1 Then
> If usetimestamp = True Then
> addtime(1)
> Else
> End If
> With frmmain.logtext
> .SelectionStart = Len(.Text)
> .SelectionLength = 0
> .SelectionColor = color
> .Text = mytext
> .SelectionStart = Len(.Text) + 1
> End With
> End If
> End Sub
>
>End Class
>
>
>
>my problem is that .text im not sure is the same as .seltext because it
wasn't
>in vb 6.0 SO what function do I use...
>
>and my second problem is that it complains that i need an object reference
>to frmmain.logtext but i tried dim frmmain as frmmain
>
>and that works until you compile and it complains that it has to reference
>an instance. So how do I reference an instance thats already running. in
>6.0 i could just do frmmain.logtext
>
>
>I much appreciate the help. Thanks in advance
>
>
> Tyler
>
The upgrade wizard probably made a "DefInstance" property available on your
frmMain. Just use that (even that should be removed and done right - but
one thing at a time):
i.e.,
With frmmain.DefInstance.logtext
This should get you started.
Eventually you'll want to get away from the poor programming practice of
using default form instances (the upgrade wizard didn't really do us any
favors with allowing us to perpetuate this bad practice with "DefInstance")
and replace the 'New' method of frmMain (the default constructor) with:
Public Sub New()
MyBase.New()
gfrmMain = Me
'This call is required by the Windows Form Designer.
InitializeComponent()
End Sub
where gfrmMain is declared somewhere as:
Public gfrmMain As frmMain
Then, your example would be:
With gfrmMain.logtext
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks