-
June 9th, 2012, 04:09 PM
#1
Problem!
Please, I think it isn't a big deal, but still I am having problems because I am a beginner.
Can someone write me a code that will do next: I want my text from textbox wich I enter in a dialogbox to enter itself into textbox in my form when I click OK. I hope my post isn't too much unclear!
-
June 9th, 2012, 07:36 PM
#2
Re: Problem!
Your post is perfectly clear: You want someone to do your work (or, more likely, your homework) for you.
Have you tried doing this yourself yet? If so, can you share your code and what you think the problem is as to why it doesn't work? If you haven't tried to do this yourself yet, why not? How do you expect to learn if you don't at least try?
-
June 9th, 2012, 07:58 PM
#3
Re: Problem!
I've tried to do it. This is code I've enterd.
Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
Me.DialogResult = System.Windows.Forms.DialogResult.OK
Me.Close()
Form1.Enabled = True
Form1.TextBox1.Text = TextBox1.Text
Form1.TextBox2.Text = TextBox2.Text
Form1.Focus()
End Sub
And still it doesn't wrok!
-
June 9th, 2012, 09:40 PM
#4
Re: Problem!
1: It is VB.Net code but you are posting under VB6
2: You are closing the form on the second line before you get to most of your code
Always use [code][/code] tags when posting code.
-
June 11th, 2012, 07:14 AM
#5
Re: Problem!
And look:
Form1.TextBox1.Text = TextBox1.Text
You are assigning the text of the textbox to itself. This won't change anything.
First you have to get the input from the dialog to a string variable like strText
(Possibly that's your line Me.DialogResult = System.Windows.Forms.DialogResult.OK
Then you assign the string to the textbox like Form1.TextBox1.Text = Me.DialogResult
Then you may do Me.Close. When you close the form, the contents of its variables get lost.
However I'm not quite sure how the VB.NET Dialog works.
-
June 11th, 2012, 10:31 AM
#6
Re: Problem!
This :
Code:
Me.DialogResult = System.Windows.Forms.DialogResult.OK
Me.Close()
Form1.Enabled = True
Form1.TextBox1.Text = TextBox1.Text
Form1.TextBox2.Text = TextBox2.Text
Form1.Focus()
will achieve absolutely nothing. zilch. nada.
You say you want the text entered from a dialog box to be entered on a textbox.
WHERE IS YOUR IF CONDITION????
You can't say this :
Code:
Me.DialogResult = System.Windows.Forms.DialogResult.OK
Me.Close()
What SHOULD happen?
You need to test IF OK was pressed, then commence with adding the text in the textboxes.
ALso, you cannot Close the dialog box. By closing it, you dispose of it - that means you wipe the memory clear, so, in fact, there is NO text to bring over to the form.
Form.Enabled - is very bad practise. You should show the form.
This :
Code:
Form1.TextBox1.Text = TextBox1.Text
Form1.TextBox2.Text = TextBox2.Text
Is so CONFUSING. This is the problem when people do not learn how to properly name objects! I would suggest you give each form and each object on the form(s) proper names! It confuses everyone. I think that you have two improperly named forms, then on each form, you have textboxes named TextBox1 and TextBox2. Change that.
-
June 11th, 2012, 02:13 PM
#7
Re: Problem!
Originally Posted by WoF
And look:
Form1.TextBox1.Text = TextBox1.Text
You are assigning the text of the textbox to itself. This won't change anything.
I thought the same thing at first glance but after reading again I saw that these are textboxes on 2 different forms. Apparently the intention was that the code shown is intended to be the dialog form and is to return values to the calling form which of course should be handled much differently.
Calling form
Code:
Dim frmTemp As New frmDialog
frmTemp.ShowDialog()
If frmTemp.DialogResult = Windows.Forms.DialogResult.OK Then
textbox1.text = frmTemp.textbox1.text
textbox2.text = frmTemp.textbox2.text
End If
frmTemp.Close()
Code in ok button on frmdialog
Code:
Me.DialogResult = System.Windows.Forms.DialogResult.OK
Me.Hide
When the form is hidden control goes back to the calling form which will then grab the values from the dialog form and close it.
And of course using this method there is no reference back to the callign form so it could be called from any form and work just fine.
Always use [code][/code] tags when posting code.
-
June 12th, 2012, 07:24 AM
#8
Re: Problem!
Ah, yes. Ok. I didn't spot that.
But then, the Me.Close, wouldn't it have destroyed the values anyway, right before they were assigned?
-
June 12th, 2012, 08:36 AM
#9
Re: Problem!
Originally Posted by WoF
Ah, yes. Ok. I didn't spot that.
But then, the Me.Close, wouldn't it have destroyed the values anyway, right before they were assigned?
Yes, that would be my take on it though I can't say i have ever tried it
Always use [code][/code] tags when posting code.
-
June 14th, 2012, 11:19 AM
#10
Re: Problem!
Ok. I have not tried either because it is VB.Net. In VB6 we do not have Me.Close, but we have Unload Me and I'm sure that this will loose the contents of any variable local to that form.
-
June 15th, 2012, 12:59 AM
#11
Re: Problem!
Originally Posted by WoF
Ok. I have not tried either because it is VB.Net. In VB6 we do not have Me.Close, but we have Unload Me and I'm sure that this will loose the contents of any variable local to that form.
I think this was missed somewhow
Originally Posted by HanneSThEGreaT
ALso, you cannot Close the dialog box. By closing it, you dispose of it - that means you wipe the memory clear, so, in fact, there is NO text to bring over to the form.
Tags for this Thread
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
|