|
-
May 10th, 2004, 04:12 PM
#1
Thread Starter
Junior Member
more confused than before.. such a simple probme
Ive tried searching, and Ive tried everything ive found, and I cant get anything to work
I need to do this-
A click event on form 2 will change a textbox's text on form1.
On form 2:
public frm1 as form1
Private Sub BtnGo_click (blah balh blah) handles btnGo.click
frm1.textbox1.text = "hello"
End Sub
From what Ive read, shouldnt this work?
-
May 10th, 2004, 04:16 PM
#2
Frenzied Member
that should work. post the exact code you're using please.
-
May 10th, 2004, 04:16 PM
#3
Thread Starter
Junior Member
in form 2, i also tried:
public frm1 as form1
private sub btnGo_click (blah.....) handles btnGo.click
txtBoxonForm2.text = "hello"
frm1.textbox1.text = txtBoxOnForm2.text
end sub
help
-
May 10th, 2004, 04:23 PM
#4
Thread Starter
Junior Member
Originally posted by Andy
that should work. post the exact code you're using please.
On form1:
VB Code:
Public frm5 As Form5
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim form5 As New Form5
form5.Show()
End Sub
Form 5 loads, with a textbox, I want to change the text in the box using a button on form1.
VB Code:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
frm5.TextBox1.Text = "hello"
End Sub
I get this error message:
Object reference not set to an instance of an object.
-
May 10th, 2004, 04:31 PM
#5
Frenzied Member
Why is it that you are using Frm5 instead of Form5 here:
VB Code:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
frm5.TextBox1.Text = "hello"
End Sub
??? ???
Squirrelly1
Now happily married and still crankin' away at the keyboard.  Life is grand for a coder, no?
-
May 10th, 2004, 04:37 PM
#6
Thread Starter
Junior Member
Originally posted by squirrelly1
Why is it that you are using Frm5 instead of Form5 here:
VB Code:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
frm5.TextBox1.Text = "hello"
End Sub
??? ???
Squirrelly1
I was using it because I set that as the name in public, so I thought I had to?
-
May 10th, 2004, 04:48 PM
#7
Frenzied Member
Button 2 is on your Form1, right?
Declare the Form5 object as Friend or something like that at the top of your Form1.. initialize it then too...
Then... open it whenever you want to...
At the Button2 click event, make sure you use the same name for the Form5 object as you declared earlier...
If you're actually using frm5 in the button2 click event and Form5 when you set it to be an object, then you will get the error that you reported... 
then just use the same command that you were using to set the textbox...
form5.textbox1.text = "whatever"
that should do it...
~Squirrelly1
btw... 9/10 times it's something simple that we just wouldn't expect to be there that keeps our software from running correctly... you'll scratch your head thinking about the huge algorithms and such and not even notice that you left a piece of code commented or you forgot a closing brace...
Now happily married and still crankin' away at the keyboard.  Life is grand for a coder, no?
-
May 10th, 2004, 04:56 PM
#8
Thread Starter
Junior Member
VB Code:
Friend form5
Public frm5 As Form5
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim form5 As New Form5
form5.Show()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim form5 As Form5
form5.TextBox1.Text()
End Sub
Still doesnt work...
What am I doing wrong?
-
May 10th, 2004, 05:07 PM
#9
Why do you keep dimming Form5?
It should be dimmed once, loaded once, and be done with it.
VB Code:
Public frm5 As Form5
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
frm5 = New Form5
frm5 .Show()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
frm5 .TextBox1.Text()
End Sub
TG
-
May 10th, 2004, 05:09 PM
#10
Frenzied Member
In your last example, you've got several instances of form5, although only one is instantiated.
You could declare and instantiate the form in a module. Alternatively, in your form:
VB Code:
'Form level declaration
Dim frm5 as New Form5
Private Sub Button1_Click(ByVal......)
frm5.Show
frm5.Textbox1.Text = "Hey! Look at me!"
End Sub
This assumes you actually have a form in your project named Form5.
If you're just referencing frm5 from this form, you don't need to declare it Public. If you declare it in a module, then declare it Public so you can reference it from other forms.
-
May 10th, 2004, 05:23 PM
#11
Thread Starter
Junior Member
Do I need the frm5 = new form 5 in the button2 click event?
or can I do this:
VB Code:
Friend form5
Dim frm5 As New form5
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
frm5.Show()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
frm5.TextBox1.Text = "TTHH"
End Sub
Cause that works too
Thanks guys.
-Nick
Originally posted by techgnome
Why do you keep dimming Form5?
It should be dimmed once, loaded once, and be done with it.
VB Code:
Public frm5 As Form5
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
frm5 = New Form5
frm5 .Show()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
frm5 .TextBox1.Text()
End Sub
TG
-
May 10th, 2004, 07:19 PM
#12
Frenzied Member
You don't need the Friend line.
If you dim frm5 as New Form5 again in button2, you'll get a second instance of Form5, a new, separate Form5. That's probably not what you want.
There's plenty of threads on this subject. You could do a search if we're not explaining it well for you.
-
May 11th, 2004, 05:10 AM
#13
PowerPoster
Hi,
Have a look at the post by blue_rabbit in thread
http://www.vbforums.com/showthread.p...hreadid=288940
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
May 11th, 2004, 09:52 AM
#14
Frenzied Member
Dude, it's pretty simple...
You only have to declare and initialize a Global (object OR variable) one time... and then use it from anywhere... Think about that, look at ur code, and you'll get it.
Squirrelly1
Now happily married and still crankin' away at the keyboard.  Life is grand for a coder, no?
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
|