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

VB - Return Val from Frm as Function

P: n/a
How can you return the value of a (sub)form to another form as a function?
My sub form is a similar to a "file list" form.
On my main form, it runs the subs and if can't find a file it calls the sub
form for user input.
My code will be something like:

Sub MainForm
'do stuff
If FileExist(sFile) = false Then
sFile= ??'result of sub form
End If
'do more stuff with sFile
End Sub
Aug 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
You can add a public value into that form.
then:

obj.ShowDialog
sFile=obj.valuename
"carl" <ca**@discussions.microsoft.com> wrote in message
news:20**********************************@microsof t.com...
How can you return the value of a (sub)form to another form as a function?
My sub form is a similar to a "file list" form.
On my main form, it runs the subs and if can't find a file it calls the
sub
form for user input.
My code will be something like:

Sub MainForm
'do stuff
If FileExist(sFile) = false Then
sFile= ??'result of sub form
End If
'do more stuff with sFile
End Sub

Aug 17 '05 #2

P: n/a
Allen
I get an error, Object doesn't support the method or property. I'm using VB.

"Allen St.Clair" wrote:
You can add a public value into that form.
then:

obj.ShowDialog
sFile=obj.valuename
"carl" <ca**@discussions.microsoft.com> wrote in message
news:20**********************************@microsof t.com...
How can you return the value of a (sub)form to another form as a function?
My sub form is a similar to a "file list" form.
On my main form, it runs the subs and if can't find a file it calls the
sub
form for user input.
My code will be something like:

Sub MainForm
'do stuff
If FileExist(sFile) = false Then
sFile= ??'result of sub form
End If
'do more stuff with sFile
End Sub


Aug 17 '05 #3

P: n/a
How are you calling it? If you add a function or sub or property to
the form class, you can access it from an instance of the class.

Dim frm As New MyFormClass

sFile = frm.SomeFunctionInMyFormClass

....

Aug 17 '05 #4

P: n/a
If the "sub form" is a modal dialog, just pass a ref parameter via the
constructor.
e.g.,
Public Sub New(ByRef sFile As String)
InitializeComponent()
Me.ShowDialog()
sFile = m_sFile 'set from elsewhere on form before closing
End Sub
--
David Anton
www.tangiblesoftwaresolutions.com
Home of:
Clear VB: Cleans up outdated VB.NET code
Instant C#: Converts from VB.NET to C#
Instant VB: Converts from C# to VB.NET
Instant J#: Converts from VB.NET to J#
"carl" wrote:
How can you return the value of a (sub)form to another form as a function?
My sub form is a similar to a "file list" form.
On my main form, it runs the subs and if can't find a file it calls the sub
form for user input.
My code will be something like:

Sub MainForm
'do stuff
If FileExist(sFile) = false Then
sFile= ??'result of sub form
End If
'do more stuff with sFile
End Sub

Aug 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.