|
-
Mar 1st, 2005, 08:39 AM
#1
Thread Starter
Lively Member
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:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim MyFrm As New Form
Dim MyFrm2 As Form
MyFrm.Text = "Hello World"
MyFrm2 = MyFrm
MyFrm.Text = "Hello Again"
MsgBox(MyFrm2.Text)
' *** Above Example Outputs "Hello Again" ***
Dim Temp As New Class1
Dim Temp2 As String
Temp2 = "Hello"
Temp.MyString = Temp2
Temp2 = "Hi2u"
MsgBox(Temp.MyString)
' *** Above Example Outputs "Hello" ***
End Sub
Public Class Class1
'Public Shared MyString As String
Public MyString As String
Public Sub New()
MyString = Nothing
End Sub
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|