By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,569 Members | 1,358 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,569 IT Pros & Developers. It's quick & easy.

problems trying to write back to a form

P: n/a
Have created a form to pop up with 2 option I then wish to write the text that
is in the option button chose back to the original form using the code below but
it gives me an exception error so could any please help me.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim frm As Form1

Dim text As String

If RadioButton1.Checked = True Then

text = RadioButton1.Text

frm.lblName4.Text = text

frm.lblSkill4.Text = "50%"

ElseIf RadioButton2.Checked = True Then

text = RadioButton2.Text

frm.lblName4.Text = text

frm.lblSkill4.Text = "40%"

End If

Close()

End Sub

thanks in advance.
--
And you thought it was safe to come out.

Nov 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
The line:

Dim frm as Form1

doesn't give you access to the main form. What you want to do is have the
code in your main form that pops up that dialog handle filling in the
values. Your dialog box class should implement public properties to expose
the data that the main form needs access to. Here is a short example. Lets
say your popup dialog has a textbox named TextBox1 and a submit button
named Button1. When the user hits Button1, you want the form to close and
the main form to show the data from that textbox in its own textbox called
MainTextBox.

Class PopupDialog
Private data as String
' Winforms code here
Private Sub Button1_Click(ByVal sender as Object, ByVal e as
ClickEventArgs) Handles Button1.Click
' We'll save the data the user has entered into a string
data = TextBox1.Text
Me.DialogResult = DialogResult.Ok
End Sub
Public ReadOnly Property DialogText as String
Get
Return data
End Get
End Property
End Class

Class MainForm
' Winforms stuff here
Private Sub ShowPopupDialog()
Dim popup as New PopupDialog
If popup.ShowDialog = DialogResult.Ok Then
MainTextBox.Text = popup.DialogText
End If
End Sub
End Class

This is just a little sample but you get the idea (I hope :)). Setting the
dialog result in the popup will cause it to close and return to the main
form since we used ShowDialog to display the dialog.

If you need more help, don't be afraid to ask.

--
Mike Sampson VB .Net Developer in Deployment
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Note: For the benefit of the community-at-large, all responses to this
message are best directed to the newsgroup/thread from which they
originated.
--------------------
From: "The One" <th*****@home.com>
Newsgroups: microsoft.public.dotnet.languages.vb
Subject: problems trying to write back to a form
Lines: 38
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <3S******************@newsfep1-win.server.ntli.net>
Date: Tue, 11 Nov 2003 12:46:13 -0000
NNTP-Posting-Host: 81.103.242.136
X-Complaints-To: ab***@ntlworld.com
X-Trace: newsfep1-win.server.ntli.net 1068554751 81.103.242.136 (Tue, 11 Nov 2003 12:45:51 GMT)NNTP-Posting-Date: Tue, 11 Nov 2003 12:45:51 GMT
Organization: ntl Cablemodem News Service
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed 00.sul.t-online.de!newsfee
d01.sul.t-online.de!t-online.de!newspeer1-gui.server.ntli.net!ntli.net!newsf
ep1-win.server.ntli.net.POSTED!53ab2750!not-for-mailXref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:155865
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

Have created a form to pop up with 2 option I then wish to write the text thatis in the option button chose back to the original form using the code below butit gives me an exception error so could any please help me.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim frm As Form1

Dim text As String

If RadioButton1.Checked = True Then

text = RadioButton1.Text

frm.lblName4.Text = text

frm.lblSkill4.Text = "50%"

ElseIf RadioButton2.Checked = True Then

text = RadioButton2.Text

frm.lblName4.Text = text

frm.lblSkill4.Text = "40%"

End If

Close()

End Sub

thanks in advance.
--
And you thought it was safe to come out.


Nov 20 '05 #2

P: n/a
Cool thanks for that I'll give it a try.
I think I'm going to have to go back and learn some more on dot not.
Thanks again for that if get back if I have any problems with it.

"Michal Sampson [MSFT]" <mi******@online.microsoft.com> wrote in message
news:0s**************@cpmsftngxa06.phx.gbl...
The line:

Dim frm as Form1

doesn't give you access to the main form. What you want to do is have the
code in your main form that pops up that dialog handle filling in the
values. Your dialog box class should implement public properties to expose
the data that the main form needs access to. Here is a short example. Lets
say your popup dialog has a textbox named TextBox1 and a submit button
named Button1. When the user hits Button1, you want the form to close and
the main form to show the data from that textbox in its own textbox called
MainTextBox.

Class PopupDialog
Private data as String
' Winforms code here
Private Sub Button1_Click(ByVal sender as Object, ByVal e as
ClickEventArgs) Handles Button1.Click
' We'll save the data the user has entered into a string
data = TextBox1.Text
Me.DialogResult = DialogResult.Ok
End Sub
Public ReadOnly Property DialogText as String
Get
Return data
End Get
End Property
End Class

Class MainForm
' Winforms stuff here
Private Sub ShowPopupDialog()
Dim popup as New PopupDialog
If popup.ShowDialog = DialogResult.Ok Then
MainTextBox.Text = popup.DialogText
End If
End Sub
End Class

This is just a little sample but you get the idea (I hope :)). Setting the
dialog result in the popup will cause it to close and return to the main
form since we used ShowDialog to display the dialog.

If you need more help, don't be afraid to ask.

--
Mike Sampson VB .Net Developer in Deployment
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Note: For the benefit of the community-at-large, all responses to this
message are best directed to the newsgroup/thread from which they
originated.
--------------------
From: "The One" <th*****@home.com>
Newsgroups: microsoft.public.dotnet.languages.vb
Subject: problems trying to write back to a form
Lines: 38
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <3S******************@newsfep1-win.server.ntli.net>
Date: Tue, 11 Nov 2003 12:46:13 -0000
NNTP-Posting-Host: 81.103.242.136
X-Complaints-To: ab***@ntlworld.com
X-Trace: newsfep1-win.server.ntli.net 1068554751 81.103.242.136 (Tue, 11

Nov 2003 12:45:51 GMT)
NNTP-Posting-Date: Tue, 11 Nov 2003 12:45:51 GMT
Organization: ntl Cablemodem News Service
Path:

cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed 00.sul.t-online.de!newsfee
d01.sul.t-online.de!t-online.de!newspeer1-gui.server.ntli.net!ntli.net!newsf
ep1-win.server.ntli.net.POSTED!53ab2750!not-for-mail
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:155865
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

Have created a form to pop up with 2 option I then wish to write the text

that
is in the option button chose back to the original form using the code

below but
it gives me an exception error so could any please help me.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim frm As Form1

Dim text As String

If RadioButton1.Checked = True Then

text = RadioButton1.Text

frm.lblName4.Text = text

frm.lblSkill4.Text = "50%"

ElseIf RadioButton2.Checked = True Then

text = RadioButton2.Text

frm.lblName4.Text = text

frm.lblSkill4.Text = "40%"

End If

Close()

End Sub

thanks in advance.
--
And you thought it was safe to come out.


Nov 20 '05 #3

P: n/a
Thanks for that will give that I try.

"Michal Sampson [MSFT]" <mi******@online.microsoft.com> wrote in message
news:0s**************@cpmsftngxa06.phx.gbl...
The line:

Dim frm as Form1

doesn't give you access to the main form. What you want to do is have the
code in your main form that pops up that dialog handle filling in the
values. Your dialog box class should implement public properties to expose
the data that the main form needs access to. Here is a short example. Lets
say your popup dialog has a textbox named TextBox1 and a submit button
named Button1. When the user hits Button1, you want the form to close and
the main form to show the data from that textbox in its own textbox called
MainTextBox.

Class PopupDialog
Private data as String
' Winforms code here
Private Sub Button1_Click(ByVal sender as Object, ByVal e as
ClickEventArgs) Handles Button1.Click
' We'll save the data the user has entered into a string
data = TextBox1.Text
Me.DialogResult = DialogResult.Ok
End Sub
Public ReadOnly Property DialogText as String
Get
Return data
End Get
End Property
End Class

Class MainForm
' Winforms stuff here
Private Sub ShowPopupDialog()
Dim popup as New PopupDialog
If popup.ShowDialog = DialogResult.Ok Then
MainTextBox.Text = popup.DialogText
End If
End Sub
End Class

This is just a little sample but you get the idea (I hope :)). Setting the
dialog result in the popup will cause it to close and return to the main
form since we used ShowDialog to display the dialog.

If you need more help, don't be afraid to ask.

--
Mike Sampson VB .Net Developer in Deployment
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Note: For the benefit of the community-at-large, all responses to this
message are best directed to the newsgroup/thread from which they
originated.
--------------------
From: "The One" <th*****@home.com>
Newsgroups: microsoft.public.dotnet.languages.vb
Subject: problems trying to write back to a form
Lines: 38
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <3S******************@newsfep1-win.server.ntli.net>
Date: Tue, 11 Nov 2003 12:46:13 -0000
NNTP-Posting-Host: 81.103.242.136
X-Complaints-To: ab***@ntlworld.com
X-Trace: newsfep1-win.server.ntli.net 1068554751 81.103.242.136 (Tue, 11

Nov 2003 12:45:51 GMT)
NNTP-Posting-Date: Tue, 11 Nov 2003 12:45:51 GMT
Organization: ntl Cablemodem News Service
Path:

cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed 00.sul.t-online.de!newsfee
d01.sul.t-online.de!t-online.de!newspeer1-gui.server.ntli.net!ntli.net!newsf
ep1-win.server.ntli.net.POSTED!53ab2750!not-for-mail
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:155865
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

Have created a form to pop up with 2 option I then wish to write the text

that
is in the option button chose back to the original form using the code

below but
it gives me an exception error so could any please help me.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim frm As Form1

Dim text As String

If RadioButton1.Checked = True Then

text = RadioButton1.Text

frm.lblName4.Text = text

frm.lblSkill4.Text = "50%"

ElseIf RadioButton2.Checked = True Then

text = RadioButton2.Text

frm.lblName4.Text = text

frm.lblSkill4.Text = "40%"

End If

Close()

End Sub

thanks in advance.
--
And you thought it was safe to come out.


Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.