|
-
May 20th, 2002, 02:19 PM
#1
Thread Starter
Lively Member
Problems referencing form object from module..
Hi,
In my project I have form1 and module1
On form1 I have a textbox1
In my module I am trying to open a text file and send it to the textbox on form1. This is my code..
Code:
Imports system.IO
Dim serverconfig As TextReader
Public Sub openfile()
Dim frm1 As New Form1()
Dim a As String
a = "C:\a.txt"
serverconfig = New StreamReader(a)
frm1.TextBox1.Text = serverconfig.ReadToEnd
End Sub
On form1 Load I simply put -- "openfile"
When I do it this way, no text appears in my textbox. But If I put the code from my module directly into my form1_load (replacing frm1.Textbox1.Text with Textbox1.Text) It prints out the Text File fine. I seem to be having problems with the line "frm1.TextBox1.Text = serverconfig.ReadToEnd"...
However in my module if I just type frm1...Then it comes up with all the objects on my Form1 (TextBox1) So I don't know what the problem is...
Any help would be great. Thx
-
May 20th, 2002, 02:26 PM
#2
having troubles? Does that mean it does nothing? Gives an error? If error, what error?
-
May 20th, 2002, 04:00 PM
#3
Thread Starter
Lively Member
There is no error.. It simply just doesnt print the contents of the textfile (a.txt) into my TextBox1.Text on Form1............
However If I use the move the code from my module to the Form1_Load It then works....(prints the textfile into the textbox)
-
May 20th, 2002, 04:09 PM
#4
Thread Starter
Lively Member
I found out what I was doing wrong. Another guy helped me out...I should have had my code like this:
Code:
Public serverconfig As TextReader
Public Sub Listen(ByVal frm1 As Form1)
Dim a As String
a = "C:\a.txt"
serverconfig = New StreamReader(a)
frm1.TextBox1.Text = serverconfig.ReadToEnd
End Sub
Form1_Load
Listen(Me)
End Sub
Apparently..This is something VB6 programmers have been used to..Unfortunately I had made the transition from VB5 to .NET...So there's a few things I'm not used to yet..Anyways thanks for the help.
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
|