471,338 Members | 1,019 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,338 software developers and data experts.

VB - Return Val from Frm as Function

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
4 1791
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
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
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
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.

Similar topics

17 posts views Thread by strout | last post: by
10 posts views Thread by LaEisem | last post: by
23 posts views Thread by Nascimento | last post: by
3 posts views Thread by Thomas Scheiderich | last post: by
12 posts views Thread by Michael Maes | last post: by
7 posts views Thread by nafri | last post: by
2 posts views Thread by mosesdinakaran | last post: by
7 posts views Thread by Terry Olsen | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.