CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 1999
    Posts
    1

    passing parameters from one form to another

    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




  2. #2
    Join Date
    Apr 1999
    Posts
    45

    Re: passing parameters from one form to another

    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


  3. #3
    Join Date
    May 1999
    Location
    Omika, Japan
    Posts
    729

    Re: passing parameters from one form to another

    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


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured