Return a string

  • Thread starter Thread starter Stanley
  • Start date Start date
S

Stanley

Hi, all! How can a show up a form then get a return string from it when
it close? I mean like inputbox! Thanks in advance

Regards,
Stanley
 
Hi Stanley,

Form 1. Add a textBox & a button
Form 2 Add a TextBox & a Button

Add this code to form 1 behind a button

Dim frm As New Form2
frm.ShowDialog()
Me.TextBox1.Text = frm.TextBox1.Text
frm.Dispose()

Behind the button on form2:

Me.Close()

------------------------------

Whatever you type in the textbox of form 2 will appear in the textbox of
form1

I hope this helps

Crouchie1998
BA (HONS) MCP MCSE
 
Hi,
Hi, all! How can a show up a form then get a return string from it when
it close? I mean like inputbox! Thanks in advance

create a simple class that wraps up your query-form. I.e.:

public class frm_UserQuery
'your form-stuff goes here and should include a textbox (txtUserInput),
'a label (lblInstructions) and two buttons (OK with DialogResult.OK,
'Cancel with i.e. DialogResult.Cancel). Both buttons will close the form
end class

public class CUserQuery

public shared sub getUserInput(byval strQueryText as string) as string
dim frmQ as new new frm_UserQuery
dim strUserInput as string

frmQ.lblInstructions.text=strQueryText

frmQ.ShowDialog()

if frmQ.DialogResult = DialogResult.OK then
'User clicked the OK-button
strUserInput=txtUserInput.text
else
'User clicked the Cancel-button
strUserInput=string.empty
end if

frmQ.dispose

return strUserInput
end sub

end class

From your main form, call the above with i.e.
dim strUserInput as string = _
CUserQuery.getUserInput("Please enter something smart:")

Cheers,
Olaf
 
Thanks all for precious information! I really appreciate them! Thanks
again!
 
All:

A question rather than an answer.

It has been recommended to me that I use a specific style for getting
information from pop-up dialogs/forms and would like some opinions on
it.


Problem:
We have a pop-up form that is to be used for inputting a handful (say
5) of values.


Recommended Solution:

Create a class to hold the values to be populated

e.g.

class PersonInfo
Public Forename as string
Public Surname as string
Public Age as integer
Public Email as EmailAddress // Custom class, declared
elsewhere
Public PhoneNbr as PhoneNumber // ditto
end class

Pass and instance of this class into the form as part of the ctor, and
when the user presses OK on the form, it (the form code) will update
the instance with the values from the screen.

e.g.

dim perInfo as New PersonInfo
dim frm as new PersonInfo(perInfo)

if (frm.ShowDialog(me) = DialogResult.OK) then

< do various things with the values in perInfo

end if



Is this overkill?
Does it gain anything (at all) over jut declaring properties on the
form?
It is more useful if we are passing values into the pop-up?


Thanks in advance,

Alan.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top