Results 1 to 5 of 5

Thread: String Object References [Resolved]

Threaded View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 1999
    Posts
    77

    Resolved String Object References [Resolved]

    I'm trying to create an object reference for the String Class.

    Normally to create an object reference you declare the variable as the object type, without the New keyword, as shown by my first example, using the Form Class.

    Next I use the String class, but there's a problem. Strings automatically assume the New keyword, so how do I create an object reference for a String?

    Note: Class Class1 is shown below the Button1_Click( ... ) method.

    I tried setting the String Object to Nothing, with no change in outcome.

    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.     Dim MyFrm As New Form
    3.     Dim MyFrm2 As Form
    4.    
    5.     MyFrm.Text = "Hello World"
    6.     MyFrm2 = MyFrm
    7.    
    8.     MyFrm.Text = "Hello Again"
    9.    
    10.     MsgBox(MyFrm2.Text)
    11.    
    12.     ' *** Above Example Outputs "Hello Again" ***
    13.    
    14.     Dim Temp As New Class1
    15.     Dim Temp2 As String
    16.    
    17.     Temp2 = "Hello"
    18.    
    19.     Temp.MyString = Temp2
    20.    
    21.     Temp2 = "Hi2u"
    22.    
    23.     MsgBox(Temp.MyString)
    24.    
    25.     ' *** Above Example Outputs "Hello" ***
    26. End Sub
    27.  
    28. Public Class Class1
    29.     'Public Shared MyString As String
    30.     Public MyString As String
    31.    
    32.     Public Sub New()
    33.         MyString = Nothing
    34.     End Sub
    35. End Class

    I tried searching for an answer, but none of them didn't seem to work or I didn't completely understand what was suggested at: http://www.codeguru.com/forum/showthread.php?t=257933

    The reason I need a String object reference is since I'm going to be creating a thread. The thread is wrapped inside a class, that will contain data used for the method that is threaded, since no actual arguments can be passed to a thread. Since I want this thread to be able to access a string outside of the thread, which may be modified by another thread/method, I want a String Object Reference.

    I hope I'm using the correct terminology and thanks for your help in advanced. I'm still not that great of a programmer, so if I'm making a huge mistake in the way I'm designing this application, please don't be shy to tell me so.
    Last edited by jgomes; Mar 1st, 2005 at 10:31 AM. Reason: *Changes Code tags to VBCode*, *2nd Edit: Adds [Resolved]*

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width