Problem calling a Sub in another form

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

    Problem calling a Sub in another form

    Hello.

    I have 2 forms (Form1 and Form2). When i call the Sub placed in form1 from
    form2, i get the error "object reference not set to an instance of an object"
    !
    What can i do to solve the problem?

    Thanks
  • rowe_newsgroups

    #2
    Re: Problem calling a Sub in another form

    Please post the code that calls the sub.

    Thanks,

    Seth Rowe

    vitorjol wrote:
    Hello.
    >
    I have 2 forms (Form1 and Form2). When i call the Sub placed in form1 from
    form2, i get the error "object reference not set to an instance of an object"
    !
    What can i do to solve the problem?
    >
    Thanks

    Comment

    • vitorjol

      #3
      Re: Problem calling a Sub in another form

      Here is the code:

      ' the code in form2
      Private Sub DataGridView1_R owHeaderMouseCl ick(ByVal sender As Object, ByVal
      e As System.Windows. Forms.DataGridV iewCellMouseEve ntArgs) Handles
      DataGridView1.R owHeaderMouseCl ick
      dim exitvar as Integer
      exitvar = DataGridView1.R ows(e.RowIndex) .Cells(0).Value
      Dim ff As New Form1
      ff.BringToFront ()
      ff.soumavez(exi tvar) ' this is the call to the sub in Form1
      End Sub

      "rowe_newsgroup s" wrote:
      Please post the code that calls the sub.
      >
      Thanks,
      >
      Seth Rowe
      >
      vitorjol wrote:
      Hello.

      I have 2 forms (Form1 and Form2). When i call the Sub placed in form1 from
      form2, i get the error "object reference not set to an instance of an object"
      !
      What can i do to solve the problem?

      Thanks
      >
      >

      Comment

      • rowe_newsgroups

        #4
        Re: Problem calling a Sub in another form

        Looks like it should work, when you step through the code where does
        the exception occur? If the error occurs in somewhere other than this
        sub please post that code too. Also what does "soumavez" mean?

        Thanks,

        Seth Rowe


        vitorjol wrote:
        Here is the code:
        >
        ' the code in form2
        Private Sub DataGridView1_R owHeaderMouseCl ick(ByVal sender As Object, ByVal
        e As System.Windows. Forms.DataGridV iewCellMouseEve ntArgs) Handles
        DataGridView1.R owHeaderMouseCl ick
        dim exitvar as Integer
        exitvar = DataGridView1.R ows(e.RowIndex) .Cells(0).Value
        Dim ff As New Form1
        ff.BringToFront ()
        ff.soumavez(exi tvar) ' this is the call to the sub in Form1
        End Sub
        >
        "rowe_newsgroup s" wrote:
        >
        Please post the code that calls the sub.

        Thanks,

        Seth Rowe

        vitorjol wrote:
        Hello.
        >
        I have 2 forms (Form1 and Form2). When i call the Sub placed in form1 from
        form2, i get the error "object reference not set to an instance of an object"
        !
        What can i do to solve the problem?
        >
        Thanks

        Comment

        • vitorjol

          #5
          Re: Problem calling a Sub in another form

          ok....the name "soumavez" its a name that i called to the Sub...End Sub.

          i put here the code of Sub(its about the Mapguide ActiveX to show a map in
          VB). I'll send there to Sub in the other form the id of a polygon on the map,
          and then the Sub localize the polygon and zoom the place!!!

          Code of the Sub "soumavez" in the Form1:

          Public Sub soumavez(ByVal varin As Integer)
          ' --->"varin" its the var that i send from Form2!!!
          ' --->"mgmap" its the name of the control (mapguide activex)
          Try
          Dim pubmapsel As MGMapControl.MG Selection
          Dim pubvar2 As MGMapControl.MG MapLayer
          Dim pubmapobjectos As MGMapControl.MG Collection
          Dim pubmapobj As MGMapControl.MG MapObject
          pubmapsel = mgmap.getSelect ion()
          pubvar2 = mgmap.getMapLay er("SIG")
          pubmapobjectos = mgmap.createObj ect("MGCollecti on")
          pubmapobj = pubvar2.getMapO bject(varin)
          pubmapobjectos. add(pubmapobj)
          pubmapsel.addOb jectsEx(pubmapo bjectos, False)
          mgmap.zoomSelec ted()
          mgmap.zoomScale (mgmap.getLat() , mgmap.getLon(), 1500)
          mgmap.refresh()
          Catch ex As Exception
          MessageBox.Show (ex.Message, "Erro", MessageBoxButto ns.OK,
          MessageBoxIcon. Error)
          End Try
          End Sub


          "rowe_newsgroup s" wrote:
          Looks like it should work, when you step through the code where does
          the exception occur? If the error occurs in somewhere other than this
          sub please post that code too. Also what does "soumavez" mean?
          >
          Thanks,
          >
          Seth Rowe
          >
          >
          vitorjol wrote:
          Here is the code:

          ' the code in form2
          Private Sub DataGridView1_R owHeaderMouseCl ick(ByVal sender As Object, ByVal
          e As System.Windows. Forms.DataGridV iewCellMouseEve ntArgs) Handles
          DataGridView1.R owHeaderMouseCl ick
          dim exitvar as Integer
          exitvar = DataGridView1.R ows(e.RowIndex) .Cells(0).Value
          Dim ff As New Form1
          ff.BringToFront ()
          ff.soumavez(exi tvar) ' this is the call to the sub in Form1
          End Sub

          "rowe_newsgroup s" wrote:
          Please post the code that calls the sub.
          >
          Thanks,
          >
          Seth Rowe
          >
          vitorjol wrote:
          Hello.

          I have 2 forms (Form1 and Form2). When i call the Sub placed in form1 from
          form2, i get the error "object reference not set to an instance of an object"
          !
          What can i do to solve the problem?

          Thanks
          >
          >
          >
          >

          Comment

          • rowe_newsgroups

            #6
            Re: Problem calling a Sub in another form

            ok....the name "soumavez" its a name that i called to the Sub...End Sub.

            It looked like a foreign langauge to me (is it?), so I was just making
            sure it was a protected keyword in a foreign language edition of visual
            studio.

            Anyways, I have to apologize - my "visual" debugging skills must be
            lacking today, as I still don't see anything obviously wrong. Which
            line of the code raises the exception?

            Thanks,

            Seth Rowe


            vitorjol wrote:
            >
            i put here the code of Sub(its about the Mapguide ActiveX to show a map in
            VB). I'll send there to Sub in the other form the id of a polygon on the map,
            and then the Sub localize the polygon and zoom the place!!!
            >
            Code of the Sub "soumavez" in the Form1:
            >
            Public Sub soumavez(ByVal varin As Integer)
            ' --->"varin" its the var that i send from Form2!!!
            ' --->"mgmap" its the name of the control (mapguide activex)
            Try
            Dim pubmapsel As MGMapControl.MG Selection
            Dim pubvar2 As MGMapControl.MG MapLayer
            Dim pubmapobjectos As MGMapControl.MG Collection
            Dim pubmapobj As MGMapControl.MG MapObject
            pubmapsel = mgmap.getSelect ion()
            pubvar2 = mgmap.getMapLay er("SIG")
            pubmapobjectos = mgmap.createObj ect("MGCollecti on")
            pubmapobj = pubvar2.getMapO bject(varin)
            pubmapobjectos. add(pubmapobj)
            pubmapsel.addOb jectsEx(pubmapo bjectos, False)
            mgmap.zoomSelec ted()
            mgmap.zoomScale (mgmap.getLat() , mgmap.getLon(), 1500)
            mgmap.refresh()
            Catch ex As Exception
            MessageBox.Show (ex.Message, "Erro", MessageBoxButto ns.OK,
            MessageBoxIcon. Error)
            End Try
            End Sub
            >
            >
            "rowe_newsgroup s" wrote:
            >
            Looks like it should work, when you step through the code where does
            the exception occur? If the error occurs in somewhere other than this
            sub please post that code too. Also what does "soumavez" mean?

            Thanks,

            Seth Rowe


            vitorjol wrote:
            Here is the code:
            >
            ' the code in form2
            Private Sub DataGridView1_R owHeaderMouseCl ick(ByVal sender As Object, ByVal
            e As System.Windows. Forms.DataGridV iewCellMouseEve ntArgs) Handles
            DataGridView1.R owHeaderMouseCl ick
            dim exitvar as Integer
            exitvar = DataGridView1.R ows(e.RowIndex) .Cells(0).Value
            Dim ff As New Form1
            ff.BringToFront ()
            ff.soumavez(exi tvar) ' this is the call to the sub in Form1
            End Sub
            >
            "rowe_newsgroup s" wrote:
            >
            Please post the code that calls the sub.

            Thanks,

            Seth Rowe

            vitorjol wrote:
            Hello.
            >
            I have 2 forms (Form1 and Form2). When i call the Sub placed in form1 from
            form2, i get the error "object reference not set to an instance of an object"
            !
            What can i do to solve the problem?
            >
            Thanks

            Comment

            • vitorjol

              #7
              Re: Problem calling a Sub in another form

              Yes....im portuguese....b ut I love America!!!!!

              i forgot to tell U the line with the problem!!!Sorry

              So, the problem "object reference not set to an instance of an object"
              occurs in the line >>pubmapobj = pubvar2.getMapO bject(varin)

              Thanks


              "rowe_newsgroup s" wrote:
              ok....the name "soumavez" its a name that i called to the Sub...End Sub.
              >
              It looked like a foreign langauge to me (is it?), so I was just making
              sure it was a protected keyword in a foreign language edition of visual
              studio.
              >
              Anyways, I have to apologize - my "visual" debugging skills must be
              lacking today, as I still don't see anything obviously wrong. Which
              line of the code raises the exception?
              >
              Thanks,
              >
              Seth Rowe
              >
              >
              vitorjol wrote:
              >

              i put here the code of Sub(its about the Mapguide ActiveX to show a map in
              VB). I'll send there to Sub in the other form the id of a polygon on the map,
              and then the Sub localize the polygon and zoom the place!!!

              Code of the Sub "soumavez" in the Form1:

              Public Sub soumavez(ByVal varin As Integer)
              ' --->"varin" its the var that i send from Form2!!!
              ' --->"mgmap" its the name of the control (mapguide activex)
              Try
              Dim pubmapsel As MGMapControl.MG Selection
              Dim pubvar2 As MGMapControl.MG MapLayer
              Dim pubmapobjectos As MGMapControl.MG Collection
              Dim pubmapobj As MGMapControl.MG MapObject
              pubmapsel = mgmap.getSelect ion()
              pubvar2 = mgmap.getMapLay er("SIG")
              pubmapobjectos = mgmap.createObj ect("MGCollecti on")
              pubmapobj = pubvar2.getMapO bject(varin)
              pubmapobjectos. add(pubmapobj)
              pubmapsel.addOb jectsEx(pubmapo bjectos, False)
              mgmap.zoomSelec ted()
              mgmap.zoomScale (mgmap.getLat() , mgmap.getLon(), 1500)
              mgmap.refresh()
              Catch ex As Exception
              MessageBox.Show (ex.Message, "Erro", MessageBoxButto ns.OK,
              MessageBoxIcon. Error)
              End Try
              End Sub


              "rowe_newsgroup s" wrote:
              Looks like it should work, when you step through the code where does
              the exception occur? If the error occurs in somewhere other than this
              sub please post that code too. Also what does "soumavez" mean?
              >
              Thanks,
              >
              Seth Rowe
              >
              >
              vitorjol wrote:
              Here is the code:

              ' the code in form2
              Private Sub DataGridView1_R owHeaderMouseCl ick(ByVal sender As Object, ByVal
              e As System.Windows. Forms.DataGridV iewCellMouseEve ntArgs) Handles
              DataGridView1.R owHeaderMouseCl ick
              dim exitvar as Integer
              exitvar = DataGridView1.R ows(e.RowIndex) .Cells(0).Value
              Dim ff As New Form1
              ff.BringToFront ()
              ff.soumavez(exi tvar) ' this is the call to the sub in Form1
              End Sub

              "rowe_newsgroup s" wrote:

              Please post the code that calls the sub.
              >
              Thanks,
              >
              Seth Rowe
              >
              vitorjol wrote:
              Hello.

              I have 2 forms (Form1 and Form2). When i call the Sub placed in form1 from
              form2, i get the error "object reference not set to an instance of an object"
              !
              What can i do to solve the problem?

              Thanks
              >
              >
              >
              >
              >
              >

              Comment

              • rowe_newsgroups

                #8
                Re: Problem calling a Sub in another form

                Hmm. The "object reference not set to an instance of an object"
                exception is raised when you try to use an object that doesn't exist
                yet, like if you left out the New keyword. However, everything looks
                alright to me. The only thing I would try (outside of praying that
                someone else happens on this thread and sees what we're missing!) is to
                change this line:
                >pubmapobj = pubvar2.getMapO bject(varin)
                To this:

                pubmapobj = MGMapControl.MG MapLayer.getMap Object(varin)

                That will take the pubvar2 variable out of the equation. Note, you may
                also try throwing the "New" keyword into that line, I'm not sure if
                you do or don't need it.

                Hope that helps,

                Seth Rowe

                vitorjol wrote:
                Yes....im portuguese....b ut I love America!!!!!
                >
                i forgot to tell U the line with the problem!!!Sorry
                >
                So, the problem "object reference not set to an instance of an object"
                occurs in the line >>pubmapobj = pubvar2.getMapO bject(varin)
                >
                Thanks
                >
                >
                "rowe_newsgroup s" wrote:
                >
                ok....the name "soumavez" its a name that i called to the Sub...End Sub.
                It looked like a foreign langauge to me (is it?), so I was just making
                sure it was a protected keyword in a foreign language edition of visual
                studio.

                Anyways, I have to apologize - my "visual" debugging skills must be
                lacking today, as I still don't see anything obviously wrong. Which
                line of the code raises the exception?

                Thanks,

                Seth Rowe


                vitorjol wrote:
                >
                i put here the code of Sub(its about the Mapguide ActiveX to show a map in
                VB). I'll send there to Sub in the other form the id of a polygon on the map,
                and then the Sub localize the polygon and zoom the place!!!
                >
                Code of the Sub "soumavez" in the Form1:
                >
                Public Sub soumavez(ByVal varin As Integer)
                ' --->"varin" its the var that i send from Form2!!!
                ' --->"mgmap" its the name of the control (mapguide activex)
                Try
                Dim pubmapsel As MGMapControl.MG Selection
                Dim pubvar2 As MGMapControl.MG MapLayer
                Dim pubmapobjectos As MGMapControl.MG Collection
                Dim pubmapobj As MGMapControl.MG MapObject
                pubmapsel = mgmap.getSelect ion()
                pubvar2 = mgmap.getMapLay er("SIG")
                pubmapobjectos = mgmap.createObj ect("MGCollecti on")
                pubmapobj = pubvar2.getMapO bject(varin)
                pubmapobjectos. add(pubmapobj)
                pubmapsel.addOb jectsEx(pubmapo bjectos, False)
                mgmap.zoomSelec ted()
                mgmap.zoomScale (mgmap.getLat() , mgmap.getLon(), 1500)
                mgmap.refresh()
                Catch ex As Exception
                MessageBox.Show (ex.Message, "Erro", MessageBoxButto ns.OK,
                MessageBoxIcon. Error)
                End Try
                End Sub
                >
                >
                "rowe_newsgroup s" wrote:
                >
                Looks like it should work, when you step through the code where does
                the exception occur? If the error occurs in somewhere other than this
                sub please post that code too. Also what does "soumavez" mean?

                Thanks,

                Seth Rowe


                vitorjol wrote:
                Here is the code:
                >
                ' the code in form2
                Private Sub DataGridView1_R owHeaderMouseCl ick(ByVal sender As Object, ByVal
                e As System.Windows. Forms.DataGridV iewCellMouseEve ntArgs) Handles
                DataGridView1.R owHeaderMouseCl ick
                dim exitvar as Integer
                exitvar = DataGridView1.R ows(e.RowIndex) .Cells(0).Value
                Dim ff As New Form1
                ff.BringToFront ()
                ff.soumavez(exi tvar) ' this is the call to the sub in Form1
                End Sub
                >
                "rowe_newsgroup s" wrote:
                >
                Please post the code that calls the sub.

                Thanks,

                Seth Rowe

                vitorjol wrote:
                Hello.
                >
                I have 2 forms (Form1 and Form2). When i call the Sub placed in form1 from
                form2, i get the error "object reference not set to an instance of an object"
                !
                What can i do to solve the problem?
                >
                Thanks


                Comment

                • GhostInAK

                  #9
                  Re: Problem calling a Sub in another form

                  Hello rowe_newsgroups ,

                  Your solutuion would not work. MGMapControl is the namespace.. MGMapLayer
                  is the type. getMapObject is not static (shared).
                  pubvar2 (GEEZ! Use some better freakin names next time wouldja, OP!) is
                  supposed to grab a reference to a specific map layer.

                  You are correct in that the OP is trying to use an object that is null.

                  OP: Check your MWF, make sure you have a layer actually called "SIG". Also,
                  ZoomSelected is a terrible way to get to an object. First, the selection
                  will only succeed if the object is visible at your current zoom scale. Second,
                  MapGuide is notorious for busystate collisions.

                  -Boo
                  Hmm. The "object reference not set to an instance of an object"
                  exception is raised when you try to use an object that doesn't exist
                  yet, like if you left out the New keyword. However, everything looks
                  alright to me. The only thing I would try (outside of praying that
                  someone else happens on this thread and sees what we're missing!) is
                  to change this line:
                  >
                  >pubmapobj = pubvar2.getMapO bject(varin)
                  >>
                  To this:
                  >
                  pubmapobj = MGMapControl.MG MapLayer.getMap Object(varin)
                  >
                  That will take the pubvar2 variable out of the equation. Note, you may
                  also try throwing the "New" keyword into that line, I'm not sure if
                  you do or don't need it.
                  >
                  Hope that helps,
                  >
                  Seth Rowe
                  >
                  vitorjol wrote:
                  >
                  >Yes....im portuguese....b ut I love America!!!!!
                  >>
                  >i forgot to tell U the line with the problem!!!Sorry
                  >>
                  >So, the problem "object reference not set to an instance of an
                  >object" occurs in the line >>pubmapobj = pubvar2.getMapO bject(varin)
                  >>
                  >Thanks
                  >>
                  >"rowe_newsgrou ps" wrote:
                  >>
                  >>>ok....the name "soumavez" its a name that i called to the Sub...End
                  >>>Sub.
                  >>>>
                  >>It looked like a foreign langauge to me (is it?), so I was just
                  >>making sure it was a protected keyword in a foreign language edition
                  >>of visual studio.
                  >>>
                  >>Anyways, I have to apologize - my "visual" debugging skills must be
                  >>lacking today, as I still don't see anything obviously wrong. Which
                  >>line of the code raises the exception?
                  >>>
                  >>Thanks,
                  >>>
                  >>Seth Rowe
                  >>>
                  >>vitorjol wrote:
                  >>>
                  >>>i put here the code of Sub(its about the Mapguide ActiveX to show a
                  >>>map in VB). I'll send there to Sub in the other form the id of a
                  >>>polygon on the map, and then the Sub localize the polygon and zoom
                  >>>the place!!!
                  >>>>
                  >>>Code of the Sub "soumavez" in the Form1:
                  >>>>
                  >>>Public Sub soumavez(ByVal varin As Integer)
                  >>>' --->"varin" its the var that i send from Form2!!!
                  >>>' --->"mgmap" its the name of the control (mapguide activex)
                  >>>Try
                  >>>Dim pubmapsel As MGMapControl.MG Selection
                  >>>Dim pubvar2 As MGMapControl.MG MapLayer
                  >>>Dim pubmapobjectos As MGMapControl.MG Collection
                  >>>Dim pubmapobj As MGMapControl.MG MapObject
                  >>>pubmapsel = mgmap.getSelect ion()
                  >>>pubvar2 = mgmap.getMapLay er("SIG")
                  >>>pubmapobject os = mgmap.createObj ect("MGCollecti on")
                  >>>pubmapobj = pubvar2.getMapO bject(varin)
                  >>>pubmapobject os.add(pubmapob j)
                  >>>pubmapsel.ad dObjectsEx(pubm apobjectos, False)
                  >>>mgmap.zoomSe lected()
                  >>>mgmap.zoomSc ale(mgmap.getLa t(), mgmap.getLon(), 1500)
                  >>>mgmap.refres h()
                  >>>Catch ex As Exception
                  >>>MessageBox.S how(ex.Message, "Erro", MessageBoxButto ns.OK,
                  >>>MessageBoxIc on.Error)
                  >>>End Try
                  >>>End Sub
                  >>>"rowe_newsgr oups" wrote:
                  >>>>
                  >>>>Looks like it should work, when you step through the code where
                  >>>>does the exception occur? If the error occurs in somewhere other
                  >>>>than this sub please post that code too. Also what does "soumavez"
                  >>>>mean?
                  >>>>>
                  >>>>Thanks,
                  >>>>>
                  >>>>Seth Rowe
                  >>>>>
                  >>>>vitorjol wrote:
                  >>>>>
                  >>>>>Here is the code:
                  >>>>>>
                  >>>>>' the code in form2
                  >>>>>Private Sub DataGridView1_R owHeaderMouseCl ick(ByVal sender As
                  >>>>>Object, ByVal
                  >>>>>e As System.Windows. Forms.DataGridV iewCellMouseEve ntArgs) Handles
                  >>>>>DataGridVi ew1.RowHeaderMo useClick
                  >>>>>dim exitvar as Integer
                  >>>>>exitvar = DataGridView1.R ows(e.RowIndex) .Cells(0).Value
                  >>>>>Dim ff As New Form1
                  >>>>>ff.BringTo Front()
                  >>>>>ff.soumave z(exitvar) ' this is the call to the sub in Form1
                  >>>>>End Sub
                  >>>>>"rowe_news groups" wrote:
                  >>>>>>
                  >>>>>>Please post the code that calls the sub.
                  >>>>>>>
                  >>>>>>Thanks,
                  >>>>>>>
                  >>>>>>Seth Rowe
                  >>>>>>>
                  >>>>>>vitorjo l wrote:
                  >>>>>>>
                  >>>>>>>Hello.
                  >>>>>>>>
                  >>>>>>>I have 2 forms (Form1 and Form2). When i call the Sub placed in
                  >>>>>>>form1 from
                  >>>>>>>form2, i get the error "object reference not set to an instance
                  >>>>>>>of an object"
                  >>>>>>>!
                  >>>>>>>What can i do to solve the problem?
                  >>>>>>>Thanks
                  >>>>>>>>

                  Comment

                  • Daniel Bloch

                    #10
                    Re: Problem calling a Sub in another form

                    What I see is that you do not show the form BringToFront does not make
                    a control a top-level control, and it does not raise the Paint event.

                    So with the knowledge of the last post, try following

                    - Check, if you can run the sub from form2 alone. Implement a button to
                    show what you want and make a test like this.
                    - If this does not work, first correct the sub until you are able to
                    let it run.
                    - After that, first show the new form and then let sub run from
                    form1...

                    Daniel

                    Comment

                    • Daniel Bloch

                      #11
                      Re: Problem calling a Sub in another form


                      Daniel Bloch schrieb:
                      What I see is that you do not show the form BringToFront does not make
                      a control a top-level control, and it does not raise the Paint event.
                      >
                      So with the knowledge of the last post, try following
                      >
                      - Check, if you can run the sub from form2 alone. Implement a button to
                      show what you want and make a test like this.
                      - If this does not work, first correct the sub until you are able to
                      let it run.
                      - After that, first show the new form and then let sub run from
                      form1...
                      >
                      Daniel
                      Sorry, I did a mistake and mixed form1 and form2 :)

                      Comment

                      • vitorjol

                        #12
                        Re: Problem calling a Sub in another form

                        The SUB in form2:

                        Public Sub soumavez(ByVal varin As Integer)
                        Try
                        MessageBox.Show (varin)
                        Dim pubmapsel As MGMapControl.MG Selection
                        Dim pubvar2 As MGMapControl.MG MapLayer
                        Dim pubmapobjectos As MGMapControl.MG Collection
                        Dim pubmapobj As MGMapControl.MG MapObject
                        pubmapsel = mgmap.getSelect ion()
                        pubvar2 = mgmap.getMapLay er("SIG")
                        pubmapobjectos = mgmap.createObj ect("MGCollecti on")
                        pubmapobj = mgmap.getMapLay er("SIG").getMa pObject(varin)
                        pubmapobjectos. add(pubmapobj)
                        mgmap.getSelect ion().addObject sEx(pubmapobjec tos, False)
                        mgmap.zoomSelec ted()
                        mgmap.zoomScale (mgmap.getLat() , mgmap.getLon(), 1500)
                        mgmap.refresh()
                        Catch ex As Exception
                        MessageBox.Show (ex.Message, "Erro", MessageBoxButto ns.OK,
                        MessageBoxIcon. Error)
                        End Try

                        End Sub


                        this sub is called form Form2 with the following code:

                        exitvar = DataGridView1.R ows(e.RowIndex) .Cells(0).Value
                        Dim ff As New Form1
                        ff.BringToFront ()
                        ff.soumavez(exi tvar)

                        PROBLEM:

                        if i dont put the codeline "MessageBox.Sho w(varin)", occurs the error at
                        line "pubmapobj = mgmap.getMapLay er("SIG").getMa pObject(varin)" .
                        If i put the message "MessageBox.Sho w(varin)", occurs the error at line
                        "mgmap.getSelec tion().addObjec tsEx(pubmapobje ctos, False)".

                        the test that u say to do (call the sub from a buttonclick within Form1)
                        occurs with NO Error!!!!

                        Thanks

                        "Daniel Bloch" wrote:
                        >
                        Daniel Bloch schrieb:
                        >
                        What I see is that you do not show the form BringToFront does not make
                        a control a top-level control, and it does not raise the Paint event.

                        So with the knowledge of the last post, try following

                        - Check, if you can run the sub from form2 alone. Implement a button to
                        show what you want and make a test like this.
                        - If this does not work, first correct the sub until you are able to
                        let it run.
                        - After that, first show the new form and then let sub run from
                        form1...

                        Daniel
                        >
                        Sorry, I did a mistake and mixed form1 and form2 :)
                        >
                        >

                        Comment

                        • vitorjol

                          #13
                          Re: Problem calling a Sub in another form

                          Resume my problem:


                          if i call the Sub located in Form1 from Form1 i get no error. If i call the
                          Sub from Form2 i get error. Why?

                          Thanks

                          "vitorjol" wrote:
                          The SUB in form2:
                          >
                          Public Sub soumavez(ByVal varin As Integer)
                          Try
                          MessageBox.Show (varin)
                          Dim pubmapsel As MGMapControl.MG Selection
                          Dim pubvar2 As MGMapControl.MG MapLayer
                          Dim pubmapobjectos As MGMapControl.MG Collection
                          Dim pubmapobj As MGMapControl.MG MapObject
                          pubmapsel = mgmap.getSelect ion()
                          pubvar2 = mgmap.getMapLay er("SIG")
                          pubmapobjectos = mgmap.createObj ect("MGCollecti on")
                          pubmapobj = mgmap.getMapLay er("SIG").getMa pObject(varin)
                          pubmapobjectos. add(pubmapobj)
                          mgmap.getSelect ion().addObject sEx(pubmapobjec tos, False)
                          mgmap.zoomSelec ted()
                          mgmap.zoomScale (mgmap.getLat() , mgmap.getLon(), 1500)
                          mgmap.refresh()
                          Catch ex As Exception
                          MessageBox.Show (ex.Message, "Erro", MessageBoxButto ns.OK,
                          MessageBoxIcon. Error)
                          End Try
                          >
                          End Sub
                          >
                          >
                          this sub is called form Form2 with the following code:
                          >
                          exitvar = DataGridView1.R ows(e.RowIndex) .Cells(0).Value
                          Dim ff As New Form1
                          ff.BringToFront ()
                          ff.soumavez(exi tvar)
                          >
                          PROBLEM:
                          >
                          if i dont put the codeline "MessageBox.Sho w(varin)", occurs the error at
                          line "pubmapobj = mgmap.getMapLay er("SIG").getMa pObject(varin)" .
                          If i put the message "MessageBox.Sho w(varin)", occurs the error at line
                          "mgmap.getSelec tion().addObjec tsEx(pubmapobje ctos, False)".
                          >
                          the test that u say to do (call the sub from a buttonclick within Form1)
                          occurs with NO Error!!!!
                          >
                          Thanks
                          >
                          "Daniel Bloch" wrote:
                          >

                          Daniel Bloch schrieb:
                          What I see is that you do not show the form BringToFront does not make
                          a control a top-level control, and it does not raise the Paint event.
                          >
                          So with the knowledge of the last post, try following
                          >
                          - Check, if you can run the sub from form2 alone. Implement a button to
                          show what you want and make a test like this.
                          - If this does not work, first correct the sub until you are able to
                          let it run.
                          - After that, first show the new form and then let sub run from
                          form1...
                          >
                          Daniel
                          Sorry, I did a mistake and mixed form1 and form2 :)

                          Comment

                          • rowe_newsgroups

                            #14
                            Re: Problem calling a Sub in another form

                            Thanks for coming to my rescue here Ghost, with no experience using
                            Mapguide (and not having it's SDK) I was getting in over my head!

                            Thanks,

                            Seth Rowe

                            GhostInAK wrote:
                            Hello rowe_newsgroups ,
                            >
                            Your solutuion would not work. MGMapControl is the namespace.. MGMapLayer
                            is the type. getMapObject is not static (shared).
                            pubvar2 (GEEZ! Use some better freakin names next time wouldja, OP!) is
                            supposed to grab a reference to a specific map layer.
                            >
                            You are correct in that the OP is trying to use an object that is null.
                            >
                            OP: Check your MWF, make sure you have a layer actually called "SIG". Also,
                            ZoomSelected is a terrible way to get to an object. First, the selection
                            will only succeed if the object is visible at your current zoom scale. Second,
                            MapGuide is notorious for busystate collisions.
                            >
                            -Boo
                            >
                            Hmm. The "object reference not set to an instance of an object"
                            exception is raised when you try to use an object that doesn't exist
                            yet, like if you left out the New keyword. However, everything looks
                            alright to me. The only thing I would try (outside of praying that
                            someone else happens on this thread and sees what we're missing!) is
                            to change this line:
                            pubmapobj = pubvar2.getMapO bject(varin)
                            >
                            To this:

                            pubmapobj = MGMapControl.MG MapLayer.getMap Object(varin)

                            That will take the pubvar2 variable out of the equation. Note, you may
                            also try throwing the "New" keyword into that line, I'm not sure if
                            you do or don't need it.

                            Hope that helps,

                            Seth Rowe

                            vitorjol wrote:
                            Yes....im portuguese....b ut I love America!!!!!
                            >
                            i forgot to tell U the line with the problem!!!Sorry
                            >
                            So, the problem "object reference not set to an instance of an
                            object" occurs in the line >>pubmapobj = pubvar2.getMapO bject(varin)
                            >
                            Thanks
                            >
                            "rowe_newsgroup s" wrote:
                            >
                            >>ok....the name "soumavez" its a name that i called to the Sub...End
                            >>Sub.
                            >>>
                            >It looked like a foreign langauge to me (is it?), so I was just
                            >making sure it was a protected keyword in a foreign language edition
                            >of visual studio.
                            >>
                            >Anyways, I have to apologize - my "visual" debugging skills must be
                            >lacking today, as I still don't see anything obviously wrong. Which
                            >line of the code raises the exception?
                            >>
                            >Thanks,
                            >>
                            >Seth Rowe
                            >>
                            >vitorjol wrote:
                            >>
                            >>i put here the code of Sub(its about the Mapguide ActiveX to show a
                            >>map in VB). I'll send there to Sub in the other form the id of a
                            >>polygon on the map, and then the Sub localize the polygon and zoom
                            >>the place!!!
                            >>>
                            >>Code of the Sub "soumavez" in the Form1:
                            >>>
                            >>Public Sub soumavez(ByVal varin As Integer)
                            >>' --->"varin" its the var that i send from Form2!!!
                            >>' --->"mgmap" its the name of the control (mapguide activex)
                            >>Try
                            >>Dim pubmapsel As MGMapControl.MG Selection
                            >>Dim pubvar2 As MGMapControl.MG MapLayer
                            >>Dim pubmapobjectos As MGMapControl.MG Collection
                            >>Dim pubmapobj As MGMapControl.MG MapObject
                            >>pubmapsel = mgmap.getSelect ion()
                            >>pubvar2 = mgmap.getMapLay er("SIG")
                            >>pubmapobjecto s = mgmap.createObj ect("MGCollecti on")
                            >>pubmapobj = pubvar2.getMapO bject(varin)
                            >>pubmapobjecto s.add(pubmapobj )
                            >>pubmapsel.add ObjectsEx(pubma pobjectos, False)
                            >>mgmap.zoomSel ected()
                            >>mgmap.zoomSca le(mgmap.getLat (), mgmap.getLon(), 1500)
                            >>mgmap.refresh ()
                            >>Catch ex As Exception
                            >>MessageBox.Sh ow(ex.Message, "Erro", MessageBoxButto ns.OK,
                            >>MessageBoxIco n.Error)
                            >>End Try
                            >>End Sub
                            >>"rowe_newsgro ups" wrote:
                            >>>
                            >>>Looks like it should work, when you step through the code where
                            >>>does the exception occur? If the error occurs in somewhere other
                            >>>than this sub please post that code too. Also what does "soumavez"
                            >>>mean?
                            >>>>
                            >>>Thanks,
                            >>>>
                            >>>Seth Rowe
                            >>>>
                            >>>vitorjol wrote:
                            >>>>
                            >>>>Here is the code:
                            >>>>>
                            >>>>' the code in form2
                            >>>>Private Sub DataGridView1_R owHeaderMouseCl ick(ByVal sender As
                            >>>>Object, ByVal
                            >>>>e As System.Windows. Forms.DataGridV iewCellMouseEve ntArgs) Handles
                            >>>>DataGridVie w1.RowHeaderMou seClick
                            >>>>dim exitvar as Integer
                            >>>>exitvar = DataGridView1.R ows(e.RowIndex) .Cells(0).Value
                            >>>>Dim ff As New Form1
                            >>>>ff.BringToF ront()
                            >>>>ff.soumavez (exitvar) ' this is the call to the sub in Form1
                            >>>>End Sub
                            >>>>"rowe_newsg roups" wrote:
                            >>>>>
                            >>>>>Please post the code that calls the sub.
                            >>>>>>
                            >>>>>Thanks,
                            >>>>>>
                            >>>>>Seth Rowe
                            >>>>>>
                            >>>>>vitorjol wrote:
                            >>>>>>
                            >>>>>>Hello.
                            >>>>>>>
                            >>>>>>I have 2 forms (Form1 and Form2). When i call the Sub placed in
                            >>>>>>form1 from
                            >>>>>>form2, i get the error "object reference not set to an instance
                            >>>>>>of an object"
                            >>>>>>!
                            >>>>>>What can i do to solve the problem?
                            >>>>>>Thanks
                            >>>>>>>

                            Comment

                            • GhostInAK

                              #15
                              Re: Problem calling a Sub in another form

                              Hello rowe_newsgroups ,

                              I envy you, Seth. I have to use the abismal peice of crap every day.

                              -Boo
                              Thanks for coming to my rescue here Ghost, with no experience using
                              Mapguide (and not having it's SDK) I was getting in over my head!
                              >
                              Thanks,
                              >
                              Seth Rowe
                              >
                              GhostInAK wrote:
                              >
                              >Hello rowe_newsgroups ,
                              >>
                              >Your solutuion would not work. MGMapControl is the namespace..
                              >MGMapLayer
                              >is the type. getMapObject is not static (shared).
                              >pubvar2 (GEEZ! Use some better freakin names next time wouldja, OP!)
                              >is
                              >supposed to grab a reference to a specific map layer.
                              >You are correct in that the OP is trying to use an object that is
                              >null.
                              >>
                              >OP: Check your MWF, make sure you have a layer actually called
                              >"SIG". Also,
                              >ZoomSelected is a terrible way to get to an object. First, the
                              >selection
                              >will only succeed if the object is visible at your current zoom
                              >scale. Second,
                              >MapGuide is notorious for busystate collisions.
                              >-Boo
                              >>
                              >>Hmm. The "object reference not set to an instance of an object"
                              >>exception is raised when you try to use an object that doesn't exist
                              >>yet, like if you left out the New keyword. However, everything looks
                              >>alright to me. The only thing I would try (outside of praying that
                              >>someone else happens on this thread and sees what we're missing!) is
                              >>to change this line:
                              >>>
                              >>>pubmapobj = pubvar2.getMapO bject(varin)
                              >>>>
                              >>To this:
                              >>>
                              >>pubmapobj = MGMapControl.MG MapLayer.getMap Object(varin)
                              >>>
                              >>That will take the pubvar2 variable out of the equation. Note, you
                              >>may also try throwing the "New" keyword into that line, I'm not
                              >>sure if you do or don't need it.
                              >>>
                              >>Hope that helps,
                              >>>
                              >>Seth Rowe
                              >>>
                              >>vitorjol wrote:
                              >>>
                              >>>Yes....im portuguese....b ut I love America!!!!!
                              >>>>
                              >>>i forgot to tell U the line with the problem!!!Sorry
                              >>>>
                              >>>So, the problem "object reference not set to an instance of an
                              >>>object" occurs in the line >>pubmapobj =
                              >>>pubvar2.getM apObject(varin)
                              >>>>
                              >>>Thanks
                              >>>>
                              >>>"rowe_newsgr oups" wrote:
                              >>>>
                              >>>>>ok....th e name "soumavez" its a name that i called to the
                              >>>>>Sub...En d Sub.
                              >>>>>>
                              >>>>It looked like a foreign langauge to me (is it?), so I was just
                              >>>>making sure it was a protected keyword in a foreign language
                              >>>>edition of visual studio.
                              >>>>>
                              >>>>Anyways, I have to apologize - my "visual" debugging skills must
                              >>>>be lacking today, as I still don't see anything obviously wrong.
                              >>>>Which line of the code raises the exception?
                              >>>>>
                              >>>>Thanks,
                              >>>>>
                              >>>>Seth Rowe
                              >>>>>
                              >>>>vitorjol wrote:
                              >>>>>
                              >>>>>i put here the code of Sub(its about the Mapguide ActiveX to show
                              >>>>>a map in VB). I'll send there to Sub in the other form the id of
                              >>>>>a polygon on the map, and then the Sub localize the polygon and
                              >>>>>zoom the place!!!
                              >>>>>>
                              >>>>>Code of the Sub "soumavez" in the Form1:
                              >>>>>>
                              >>>>>Public Sub soumavez(ByVal varin As Integer)
                              >>>>>' --->"varin" its the var that i send from Form2!!!
                              >>>>>' --->"mgmap" its the name of the control (mapguide activex)
                              >>>>>Try
                              >>>>>Dim pubmapsel As MGMapControl.MG Selection
                              >>>>>Dim pubvar2 As MGMapControl.MG MapLayer
                              >>>>>Dim pubmapobjectos As MGMapControl.MG Collection
                              >>>>>Dim pubmapobj As MGMapControl.MG MapObject
                              >>>>>pubmapse l = mgmap.getSelect ion()
                              >>>>>pubvar2 = mgmap.getMapLay er("SIG")
                              >>>>>pubmapobje ctos = mgmap.createObj ect("MGCollecti on")
                              >>>>>pubmapob j = pubvar2.getMapO bject(varin)
                              >>>>>pubmapobje ctos.add(pubmap obj)
                              >>>>>pubmapsel. addObjectsEx(pu bmapobjectos, False)
                              >>>>>mgmap.zoom Selected()
                              >>>>>mgmap.zoom Scale(mgmap.get Lat(), mgmap.getLon(), 1500)
                              >>>>>mgmap.refr esh()
                              >>>>>Catch ex As Exception
                              >>>>>MessageBox .Show(ex.Messag e, "Erro", MessageBoxButto ns.OK,
                              >>>>>MessageBox Icon.Error)
                              >>>>>End Try
                              >>>>>End Sub
                              >>>>>"rowe_news groups" wrote:
                              >>>>>>Looks like it should work, when you step through the code where
                              >>>>>>does the exception occur? If the error occurs in somewhere
                              >>>>>>other than this sub please post that code too. Also what does
                              >>>>>>"soumavez " mean?
                              >>>>>>>
                              >>>>>>Thanks,
                              >>>>>>>
                              >>>>>>Seth Rowe
                              >>>>>>>
                              >>>>>>vitorjo l wrote:
                              >>>>>>>
                              >>>>>>>Here is the code:
                              >>>>>>>>
                              >>>>>>>' the code in form2
                              >>>>>>>Privat e Sub DataGridView1_R owHeaderMouseCl ick(ByVal sender As
                              >>>>>>>Object , ByVal
                              >>>>>>>e As System.Windows. Forms.DataGridV iewCellMouseEve ntArgs)
                              >>>>>>>Handle s
                              >>>>>>>DataGrid View1.RowHeader MouseClick
                              >>>>>>>dim exitvar as Integer
                              >>>>>>>exitva r = DataGridView1.R ows(e.RowIndex) .Cells(0).Value
                              >>>>>>>Dim ff As New Form1
                              >>>>>>>ff.Bring ToFront()
                              >>>>>>>ff.souma vez(exitvar) ' this is the call to the sub in Form1
                              >>>>>>>End Sub
                              >>>>>>>"rowe_ne wsgroups" wrote:
                              >>>>>>>>Pleas e post the code that calls the sub.
                              >>>>>>>>>
                              >>>>>>>>Thank s,
                              >>>>>>>>>
                              >>>>>>>>Seth Rowe
                              >>>>>>>>>
                              >>>>>>>>vitorjo l wrote:
                              >>>>>>>>>
                              >>>>>>>>>Hell o.
                              >>>>>>>>>>
                              >>>>>>>>>I have 2 forms (Form1 and Form2). When i call the Sub placed
                              >>>>>>>>>in
                              >>>>>>>>>form 1 from
                              >>>>>>>>>form 2, i get the error "object reference not set to an
                              >>>>>>>>>instan ce
                              >>>>>>>>>of an object"
                              >>>>>>>>>!
                              >>>>>>>>>What can i do to solve the problem?
                              >>>>>>>>>Than ks

                              Comment

                              Working...