passing parameters between forms

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jan Warning

    #1

    passing parameters between forms

    How do I pass an argument from one form to another?
    I do the following:
    FormA:
    dim strFilename as string ="Filename"
    dim frmLayout1 as New frmLayout(strFi lename)
    frmLayout1.Show ()

    frmLayout:
    Private strFilename as string
    ..
    ..
    Sub New(Filename as string)
    ..
    ..strFilename = Filename
    ..
    ..
    Private Sub frmLayout_Load( ...)
    dim strLayout as new Filestream(strF ilename, FileMode.Open)

    At this point I get an error because strFilename is empty (Nothing)

    When I step thru the code, I can see that the parm is correctly passed to
    and stored by the Sub New
    What am I doing wrong?



  • dotnetnewbie

    #2
    RE: passing parameters between forms

    You could either use a property (in a Module) and access the value there
    (from any form) or

    In Form A:

    Private sub OpenNewForm()
    Dim strValue as string
    Dim frm as FormB
    frm.GetDetails( strValue)
    frm = nothing
    End Sub


    In Form B

    Private mstrValue as string

    Public Sub GetDetails(byva l vstrValue as string)
    mstrValue = vstrValue
    me.show
    end sub

    Gerry

    "Jan Warning" wrote:
    [color=blue]
    > How do I pass an argument from one form to another?
    > I do the following:
    > FormA:
    > dim strFilename as string ="Filename"
    > dim frmLayout1 as New frmLayout(strFi lename)
    > frmLayout1.Show ()
    >
    > frmLayout:
    > Private strFilename as string
    > ..
    > ..
    > Sub New(Filename as string)
    > ..
    > ..strFilename = Filename
    > ..
    > ..
    > Private Sub frmLayout_Load( ...)
    > dim strLayout as new Filestream(strF ilename, FileMode.Open)
    >
    > At this point I get an error because strFilename is empty (Nothing)
    >
    > When I step thru the code, I can see that the parm is correctly passed to
    > and stored by the Sub New
    > What am I doing wrong?
    >
    >
    >
    >[/color]

    Comment

    • dotnetnewbie

      #3
      RE: passing parameters between forms

      Correction to my last post

      Dim frm as FormB

      should have read

      Dim frm as New FormB

      Gerry


      "Jan Warning" wrote:
      [color=blue]
      > How do I pass an argument from one form to another?
      > I do the following:
      > FormA:
      > dim strFilename as string ="Filename"
      > dim frmLayout1 as New frmLayout(strFi lename)
      > frmLayout1.Show ()
      >
      > frmLayout:
      > Private strFilename as string
      > ..
      > ..
      > Sub New(Filename as string)
      > ..
      > ..strFilename = Filename
      > ..
      > ..
      > Private Sub frmLayout_Load( ...)
      > dim strLayout as new Filestream(strF ilename, FileMode.Open)
      >
      > At this point I get an error because strFilename is empty (Nothing)
      >
      > When I step thru the code, I can see that the parm is correctly passed to
      > and stored by the Sub New
      > What am I doing wrong?
      >
      >
      >
      >[/color]

      Comment

      • Jan Warning

        #4
        Re: passing parameters between forms

        I tried it (I noticed your mistake) and it worked. Thanks a lot.
        But I am still wondering why my original code did not work.

        Regards, Jan Warning
        "dotnetnewb ie" <dotnetnewbie@d iscussions.micr osoft.com> wrote in message
        news:5B37507D-3D82-4515-8893-E509D2A82D07@mi crosoft.com...[color=blue]
        > Correction to my last post
        >
        > Dim frm as FormB
        >
        > should have read
        >
        > Dim frm as New FormB
        >
        > Gerry
        >
        >
        > "Jan Warning" wrote:
        >[color=green]
        >> How do I pass an argument from one form to another?
        >> I do the following:
        >> FormA:
        >> dim strFilename as string ="Filename"
        >> dim frmLayout1 as New frmLayout(strFi lename)
        >> frmLayout1.Show ()
        >>
        >> frmLayout:
        >> Private strFilename as string
        >> ..
        >> ..
        >> Sub New(Filename as string)
        >> ..
        >> ..strFilename = Filename
        >> ..
        >> ..
        >> Private Sub frmLayout_Load( ...)
        >> dim strLayout as new Filestream(strF ilename, FileMode.Open)
        >>
        >> At this point I get an error because strFilename is empty (Nothing)
        >>
        >> When I step thru the code, I can see that the parm is correctly passed to
        >> and stored by the Sub New
        >> What am I doing wrong?
        >>
        >>
        >>
        >>[/color][/color]


        Comment

        • Zoury

          #5
          Re: passing parameters between forms

          Yeah.. Your original would have been better... Was it the real code
          (copy/paste) ? If so can you reproduce this behavior in a new project ?

          --
          Best Regards
          Yanick
          "Jan Warning" <jan.warning@wa nadoo.nl> a écrit dans le message de
          news:OnAuJ0GaFH A.720@TK2MSFTNG P15.phx.gbl...[color=blue]
          > I tried it (I noticed your mistake) and it worked. Thanks a lot.
          > But I am still wondering why my original code did not work.
          >
          > Regards, Jan Warning
          > "dotnetnewb ie" <dotnetnewbie@d iscussions.micr osoft.com> wrote in message
          > news:5B37507D-3D82-4515-8893-E509D2A82D07@mi crosoft.com...[color=green]
          > > Correction to my last post
          > >
          > > Dim frm as FormB
          > >
          > > should have read
          > >
          > > Dim frm as New FormB
          > >
          > > Gerry
          > >
          > >
          > > "Jan Warning" wrote:
          > >[color=darkred]
          > >> How do I pass an argument from one form to another?
          > >> I do the following:
          > >> FormA:
          > >> dim strFilename as string ="Filename"
          > >> dim frmLayout1 as New frmLayout(strFi lename)
          > >> frmLayout1.Show ()
          > >>
          > >> frmLayout:
          > >> Private strFilename as string
          > >> ..
          > >> ..
          > >> Sub New(Filename as string)
          > >> ..
          > >> ..strFilename = Filename
          > >> ..
          > >> ..
          > >> Private Sub frmLayout_Load( ...)
          > >> dim strLayout as new Filestream(strF ilename, FileMode.Open)
          > >>
          > >> At this point I get an error because strFilename is empty (Nothing)
          > >>
          > >> When I step thru the code, I can see that the parm is correctly passed[/color][/color][/color]
          to[color=blue][color=green][color=darkred]
          > >> and stored by the Sub New
          > >> What am I doing wrong?
          > >>
          > >>
          > >>
          > >>[/color][/color]
          >
          >[/color]


          Comment

          • Jan Warning

            #6
            Re: passing parameters between forms

            It had to replace a defective harddisk, so I could not reply any sooner.

            I could reproduce this behavior in a small new project.
            I also discobvered wahat I did wrong, although I still don't quite
            understand it.

            I passed the parameter from FormA to FormB as follows:
            Private Parm as string
            dim myFormb as New FormB(Parm)
            FormB.Show

            In FormB:
            Private Filename as string
            ..

            Public Sub New(byval Filename as string)
            Filename = Filename
            etc.

            Public Sub Form2_Load .....
            xxxx = Filename

            Now filename appears to be empty (Nothing)

            when I change the code to"
            Private myFilename as string
            ..

            Public Sub New(byval Filename as string)
            myFilename = Filename
            etc.

            Public Sub Form2_Load .....
            xxxx = myFilename

            then everything is fine.

            as I said, I don't quite understand, but it works.

            Best regards, Jan Warning

            "Zoury" <yanick_lefebvr e at hotmail dot com> wrote in message
            news:ugc%23h%23 GaFHA.2128@TK2M SFTNGP14.phx.gb l...[color=blue]
            > Yeah.. Your original would have been better... Was it the real code
            > (copy/paste) ? If so can you reproduce this behavior in a new project ?
            >
            > --
            > Best Regards
            > Yanick
            > "Jan Warning" <jan.warning@wa nadoo.nl> a écrit dans le message de
            > news:OnAuJ0GaFH A.720@TK2MSFTNG P15.phx.gbl...[color=green]
            >> I tried it (I noticed your mistake) and it worked. Thanks a lot.
            >> But I am still wondering why my original code did not work.
            >>
            >> Regards, Jan Warning
            >> "dotnetnewb ie" <dotnetnewbie@d iscussions.micr osoft.com> wrote in message
            >> news:5B37507D-3D82-4515-8893-E509D2A82D07@mi crosoft.com...[color=darkred]
            >> > Correction to my last post
            >> >
            >> > Dim frm as FormB
            >> >
            >> > should have read
            >> >
            >> > Dim frm as New FormB
            >> >
            >> > Gerry
            >> >
            >> >
            >> > "Jan Warning" wrote:
            >> >
            >> >> How do I pass an argument from one form to another?
            >> >> I do the following:
            >> >> FormA:
            >> >> dim strFilename as string ="Filename"
            >> >> dim frmLayout1 as New frmLayout(strFi lename)
            >> >> frmLayout1.Show ()
            >> >>
            >> >> frmLayout:
            >> >> Private strFilename as string
            >> >> ..
            >> >> ..
            >> >> Sub New(Filename as string)
            >> >> ..
            >> >> ..strFilename = Filename
            >> >> ..
            >> >> ..
            >> >> Private Sub frmLayout_Load( ...)
            >> >> dim strLayout as new Filestream(strF ilename, FileMode.Open)
            >> >>
            >> >> At this point I get an error because strFilename is empty (Nothing)
            >> >>
            >> >> When I step thru the code, I can see that the parm is correctly passed[/color][/color]
            > to[color=green][color=darkred]
            >> >> and stored by the Sub New
            >> >> What am I doing wrong?
            >> >>
            >> >>
            >> >>
            >> >>[/color]
            >>
            >>[/color]
            >
            >[/color]


            Comment

            • Armin Zingler

              #7
              Re: passing parameters between forms


              "Jan Warning" <jan.warning@wa nadoo.nl> schrieb im Newsbeitrag
              news:elNIqp6aFH A.720@TK2MSFTNG P15.phx.gbl...[color=blue]
              > It had to replace a defective harddisk, so I could not reply any sooner.
              >
              > I could reproduce this behavior in a small new project.
              > I also discobvered wahat I did wrong, although I still don't quite
              > understand it.
              >
              > I passed the parameter from FormA to FormB as follows:
              > Private Parm as string
              > dim myFormb as New FormB(Parm)
              > FormB.Show
              >
              > In FormB:
              > Private Filename as string
              > .
              >
              > Public Sub New(byval Filename as string)
              > Filename = Filename
              > etc.[/color]


              Names are resolved inside out. "Filename = Filename" assigns the argument to
              the argument, i.e. it changes nothing. To change the field of the Form,
              write

              me.filename = filename

              [color=blue]
              > Public Sub Form2_Load .....
              > xxxx = Filename
              >
              > Now filename appears to be empty (Nothing)
              >
              > when I change the code to"
              > Private myFilename as string
              > .
              >
              > Public Sub New(byval Filename as string)
              > myFilename = Filename
              > etc.
              >
              > Public Sub Form2_Load .....
              > xxxx = myFilename
              >
              > then everything is fine.
              >
              > as I said, I don't quite understand, but it works.[/color]


              "myfilename = " accesses the field of the Form because there is no local
              variable with the name "myfilename "

              Armin

              Comment

              Working...