Object REferences from within a class.


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Object REferences from within a class.

  1. #1
    Tyler W Guest

    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


  2. #2
    Dave Guest

    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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center