passing parameters

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi

How can I pass a string from a form to a dialog which I am trying to open
from the same form?

Thanks

Regards
 
Hi John,
Thousand possibilties,
I just make a public string in my dialogform let say
(pseudo code)
\\\
public a as string
///
and then in the main form
\\\
dim frm as new formdialog
frm.a = "John"
frm.showdialog
dim answer as string = frm.a
frm.dispose
///
Maybe not nice, but for a dialogform I found it nice enough

I hope this helps a little 1/8 byte?
Cor
 
@reader20.wxs.nl:

Hi Cor,

I think he wanted to pass the string TO the dialog.

One way would be to overload the ShowDialog method to take a string and
pass in the string when the dialog form is shown:

'In the dialog form

Private m_SomeString As String

Public Overloads Function ShowDialog(sParm As String) As DialogResult
m_SomeString = sParm
Return MyBase.ShowDialog()
End Function


'Then in the form that opens the dialog,
' pass in the string to the constructor:

Dim fDialog As New DialogForm()

fDialog.ShowDialog("String to pass to the Dialog")


HTH

Chris
 
Chris,
I think he wanted to pass the string TO the dialog.

I did in my exampe, TO and FROM.
\\\
frm.a = "John"
frm.showdialog
dim answer as string = frm.a
///

I know it is not nice but that dialogbox lives just some seconds.

And mostly it is a very simple form,

When it would be a special dialogclass for all dialogs, I would sure do it
in the way you describe.

Cor
 
John,
As Cor stated you can use a Property, which is consistent with the Framework
(OpenFileDialog for example).

In addition to the property I will also sometimes add an overloaded
constructor to the dialog that accepts the value I want to pass in. However
I normally only use this when I am passing readonly data, such as the
caption of the dialog or a reference to an object that the dialog operates
on. Because the object is a reference the dialog can modify the object
itself.

Hope this helps
Jay
 
Back
Top