Click to See Complete Forum and Search --> : passing parameters from one form to another


ruphus
May 21st, 1999, 08:56 AM
In a form called selectfile.frm I have selected and stored a dbase IV file name and path to a variable.
cFile$ = file1.path + filename
I can display the variable in a text box to confirm that it does contain the file name and path.
I have another form (Browser.frm) that uses flexgrid and datacontrol. I can view a dbase file
in this form by setting the datacontrol properties to: (example)
connect = dbaseiv
DatabaseName = E:\sfmp\data
RecordSource = fire1970.dbf

How do I pass the information in selectfile.cFile$ to the appropriate properties in my Browser.frm so that
I can view the selected file in the "browser.frm"? The dbase file will need read/write access in the
Browser.frm.

I would be very grateful for any assistance.
ruphus

Gordito Supreme
May 22nd, 1999, 07:10 PM
The easiest way to do it is to make the parameters Global variables that can be used by both forms. You do this by creating a Bas Module and declaring you variables globally, for example,

Option Explicit
Public DataFileName as String

Or if you want to pass parameters, make a function in frmBrowser to load the parameters. For example call it LoadPar(filename as String). In this function just set whatever variable you have declared for your filename ... such as strFileName and set it equal to filename (strFileName = filename). Then when the user inputs the filename in frmSelectfile ... call the function in frmBrowser to give it the filename also, here is the code to do that,

Call frmBrowser.LoadPar(cFile)

Of course you need to Load frmBrowser before you can do this ... I would suggest doing that in the load event of your frmFilename, or whatever your startup form is.

Gordito

Ravi Kiran
May 23rd, 1999, 09:47 PM
Hi,

DONT USE GLOBAL VARS. It is BAD STYLE. i would say out-of-fashion!.

Use (Form/class) Properties instead.
From VB 4.0 onwards, you can have properties to your forms and forms are internally implemented as classes ( i am told:-) ). So store the file name in a private member variable and have a public property to your file selection form, say "SelectedFile", , something like this:

' In Declarations Section
private m_szSelFile as string
'
public property SelectedFile() as string
SelectedFile = m_szSelFile
end property




and at appropriate place (i.e after the file name is selected and available) set it to m_szSelFile

IN your browser form, say on some btn click,

private sub Commmand1_click()
frmSelectFile.Show vbmodal
' by the time the form is unloaded, you know
' the file name should be ready
Text1.Text = frmSelectFile.SelectedFile()
' will display the selected file name in a text box 'Text1'
end sub




Ravi Kiran