How to create a function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Miguel Dias Moura

    #1

    How to create a function

    Hello,

    I am working on an Asp.Net 2.0.
    I created a master page named "MyMasterPage.m aster".
    I created the function "SUM" in my master page VB code.

    I then created the page "MyPage.asp x" from my master page.
    When I try to use the function "SUM" in "MyPage" VB code it says:
    - Name "SUM" is not declared.

    I created the SUM function in different ways:
    - "SUB SUM()..."
    - "Private SUB SUM()..."
    - "Public SUB SUM()..." > I thought this would solve the problem.

    Basically I need to create functions which will be accessible from many
    Aspx pages.

    Thank You Very Much,
    Miguel

  • Milosz Skalecki

    #2
    RE: How to create a function

    Lo,

    In VB.NET

    1. Create new module called i.e. MyUtilityFuncti ons and add code
    public function Sum(byval a as integer, byval b as integer) as Integer
    return a + b
    end function
    You can use it in your code as follows
    dim result as integer = MyUtilityFuncti ons.Sum(1, 2)

    or.
    2. Create new class called i.e. MyUtilityFuncti ons and add code
    public shared function Sum(byval a as integer, byval b as integer) as
    Integer
    return a + b
    end function

    and you can use it in your code:
    dim result as integer = MyUtilityFuncti ons.Sum(1, 2)

    I advise to read a VB.NET tutorial/book to gain basic knowledge about vb.net.
    --
    Milosz Skalecki
    MCP, MCAD


    "Miguel Dias Moura" wrote:
    [color=blue]
    > Hello,
    >
    > I am working on an Asp.Net 2.0.
    > I created a master page named "MyMasterPage.m aster".
    > I created the function "SUM" in my master page VB code.
    >
    > I then created the page "MyPage.asp x" from my master page.
    > When I try to use the function "SUM" in "MyPage" VB code it says:
    > - Name "SUM" is not declared.
    >
    > I created the SUM function in different ways:
    > - "SUB SUM()..."
    > - "Private SUB SUM()..."
    > - "Public SUB SUM()..." > I thought this would solve the problem.
    >
    > Basically I need to create functions which will be accessible from many
    > Aspx pages.
    >
    > Thank You Very Much,
    > Miguel
    >
    >[/color]

    Comment

    • Karl Seguin [MVP]

      #3
      Re: How to create a function

      In your page, specifying the @masterType directive..

      <%@ Page .... %>
      <%@ MasterType VirtualPath="~/master/Main.master" %>


      then from your codebehind you should be able to do:
      Master.Sum(...)

      declare sum as

      public sub Sum
      end sub

      --
      Programming blog exploring Zig, Elixir, Go, Testing, Design and Performance




      "Miguel Dias Moura" <md*REMOVE*mour a@gmail*NOSPAM* .com> wrote in message
      news:uaF1PvbHGH A.3116@TK2MSFTN GP15.phx.gbl...[color=blue]
      > Hello,
      >
      > I am working on an Asp.Net 2.0.
      > I created a master page named "MyMasterPage.m aster".
      > I created the function "SUM" in my master page VB code.
      >
      > I then created the page "MyPage.asp x" from my master page.
      > When I try to use the function "SUM" in "MyPage" VB code it says:
      > - Name "SUM" is not declared.
      >
      > I created the SUM function in different ways:
      > - "SUB SUM()..."
      > - "Private SUB SUM()..."
      > - "Public SUB SUM()..." > I thought this would solve the problem.
      >
      > Basically I need to create functions which will be accessible from many
      > Aspx pages.
      >
      > Thank You Very Much,
      > Miguel
      >[/color]


      Comment

      • Karl Seguin [MVP]

        #4
        Re: How to create a function

        I agree that a separate utility class is the way to go assuming it doesn't
        actually interact with the master page.

        Say you wanted Sum to do:

        Sub Sum (byval x as string)
        myHeaderText.Te xt = x
        end sub

        where myHeaderText is a label on the master page, then you'd want to keep
        Sum on the master page.

        Karl

        --
        Programming blog exploring Zig, Elixir, Go, Testing, Design and Performance




        "Milosz Skalecki" <mily242@REMOVE ITwp.pl> wrote in message
        news:A83C5707-03BF-4C41-B41D-063219DCFD3B@mi crosoft.com...[color=blue]
        > Lo,
        >
        > In VB.NET
        >
        > 1. Create new module called i.e. MyUtilityFuncti ons and add code
        > public function Sum(byval a as integer, byval b as integer) as Integer
        > return a + b
        > end function
        > You can use it in your code as follows
        > dim result as integer = MyUtilityFuncti ons.Sum(1, 2)
        >
        > or.
        > 2. Create new class called i.e. MyUtilityFuncti ons and add code
        > public shared function Sum(byval a as integer, byval b as integer)
        > as
        > Integer
        > return a + b
        > end function
        >
        > and you can use it in your code:
        > dim result as integer = MyUtilityFuncti ons.Sum(1, 2)
        >
        > I advise to read a VB.NET tutorial/book to gain basic knowledge about
        > vb.net.
        > --
        > Milosz Skalecki
        > MCP, MCAD
        >
        >
        > "Miguel Dias Moura" wrote:
        >[color=green]
        >> Hello,
        >>
        >> I am working on an Asp.Net 2.0.
        >> I created a master page named "MyMasterPage.m aster".
        >> I created the function "SUM" in my master page VB code.
        >>
        >> I then created the page "MyPage.asp x" from my master page.
        >> When I try to use the function "SUM" in "MyPage" VB code it says:
        >> - Name "SUM" is not declared.
        >>
        >> I created the SUM function in different ways:
        >> - "SUB SUM()..."
        >> - "Private SUB SUM()..."
        >> - "Public SUB SUM()..." > I thought this would solve the problem.
        >>
        >> Basically I need to create functions which will be accessible from many
        >> Aspx pages.
        >>
        >> Thank You Very Much,
        >> Miguel
        >>
        >>[/color][/color]


        Comment

        • Milosz Skalecki

          #5
          Re: How to create a function

          Agree, i thought He wanted just a utility independent function that does't
          interact with master page.
          --
          Milosz Skalecki
          MCP, MCAD


          "Karl Seguin [MVP]" wrote:
          [color=blue]
          > I agree that a separate utility class is the way to go assuming it doesn't
          > actually interact with the master page.
          >
          > Say you wanted Sum to do:
          >
          > Sub Sum (byval x as string)
          > myHeaderText.Te xt = x
          > end sub
          >
          > where myHeaderText is a label on the master page, then you'd want to keep
          > Sum on the master page.
          >
          > Karl
          >
          > --
          > http://www.openmymind.net/
          >
          >
          >
          > "Milosz Skalecki" <mily242@REMOVE ITwp.pl> wrote in message
          > news:A83C5707-03BF-4C41-B41D-063219DCFD3B@mi crosoft.com...[color=green]
          > > Lo,
          > >
          > > In VB.NET
          > >
          > > 1. Create new module called i.e. MyUtilityFuncti ons and add code
          > > public function Sum(byval a as integer, byval b as integer) as Integer
          > > return a + b
          > > end function
          > > You can use it in your code as follows
          > > dim result as integer = MyUtilityFuncti ons.Sum(1, 2)
          > >
          > > or.
          > > 2. Create new class called i.e. MyUtilityFuncti ons and add code
          > > public shared function Sum(byval a as integer, byval b as integer)
          > > as
          > > Integer
          > > return a + b
          > > end function
          > >
          > > and you can use it in your code:
          > > dim result as integer = MyUtilityFuncti ons.Sum(1, 2)
          > >
          > > I advise to read a VB.NET tutorial/book to gain basic knowledge about
          > > vb.net.
          > > --
          > > Milosz Skalecki
          > > MCP, MCAD
          > >
          > >
          > > "Miguel Dias Moura" wrote:
          > >[color=darkred]
          > >> Hello,
          > >>
          > >> I am working on an Asp.Net 2.0.
          > >> I created a master page named "MyMasterPage.m aster".
          > >> I created the function "SUM" in my master page VB code.
          > >>
          > >> I then created the page "MyPage.asp x" from my master page.
          > >> When I try to use the function "SUM" in "MyPage" VB code it says:
          > >> - Name "SUM" is not declared.
          > >>
          > >> I created the SUM function in different ways:
          > >> - "SUB SUM()..."
          > >> - "Private SUB SUM()..."
          > >> - "Public SUB SUM()..." > I thought this would solve the problem.
          > >>
          > >> Basically I need to create functions which will be accessible from many
          > >> Aspx pages.
          > >>
          > >> Thank You Very Much,
          > >> Miguel
          > >>
          > >>[/color][/color]
          >
          >
          >[/color]

          Comment

          • Karl Seguin [MVP]

            #6
            Re: How to create a function

            ya, probably :) it wasn't clear

            --
            MY ASP.Net tutorials
            Programming blog exploring Zig, Elixir, Go, Testing, Design and Performance



            "Milosz Skalecki" <mily242@REMOVE ITwp.pl> wrote in message
            news:FC61F715-A7F7-47CE-A7F3-2CD915C2079D@mi crosoft.com...[color=blue]
            > Agree, i thought He wanted just a utility independent function that does't
            > interact with master page.
            > --
            > Milosz Skalecki
            > MCP, MCAD
            >
            >
            > "Karl Seguin [MVP]" wrote:
            >[color=green]
            >> I agree that a separate utility class is the way to go assuming it
            >> doesn't
            >> actually interact with the master page.
            >>
            >> Say you wanted Sum to do:
            >>
            >> Sub Sum (byval x as string)
            >> myHeaderText.Te xt = x
            >> end sub
            >>
            >> where myHeaderText is a label on the master page, then you'd want to keep
            >> Sum on the master page.
            >>
            >> Karl
            >>
            >> --
            >> http://www.openmymind.net/
            >>
            >>
            >>
            >> "Milosz Skalecki" <mily242@REMOVE ITwp.pl> wrote in message
            >> news:A83C5707-03BF-4C41-B41D-063219DCFD3B@mi crosoft.com...[color=darkred]
            >> > Lo,
            >> >
            >> > In VB.NET
            >> >
            >> > 1. Create new module called i.e. MyUtilityFuncti ons and add code
            >> > public function Sum(byval a as integer, byval b as integer) as
            >> > Integer
            >> > return a + b
            >> > end function
            >> > You can use it in your code as follows
            >> > dim result as integer = MyUtilityFuncti ons.Sum(1, 2)
            >> >
            >> > or.
            >> > 2. Create new class called i.e. MyUtilityFuncti ons and add code
            >> > public shared function Sum(byval a as integer, byval b as
            >> > integer)
            >> > as
            >> > Integer
            >> > return a + b
            >> > end function
            >> >
            >> > and you can use it in your code:
            >> > dim result as integer = MyUtilityFuncti ons.Sum(1, 2)
            >> >
            >> > I advise to read a VB.NET tutorial/book to gain basic knowledge about
            >> > vb.net.
            >> > --
            >> > Milosz Skalecki
            >> > MCP, MCAD
            >> >
            >> >
            >> > "Miguel Dias Moura" wrote:
            >> >
            >> >> Hello,
            >> >>
            >> >> I am working on an Asp.Net 2.0.
            >> >> I created a master page named "MyMasterPage.m aster".
            >> >> I created the function "SUM" in my master page VB code.
            >> >>
            >> >> I then created the page "MyPage.asp x" from my master page.
            >> >> When I try to use the function "SUM" in "MyPage" VB code it says:
            >> >> - Name "SUM" is not declared.
            >> >>
            >> >> I created the SUM function in different ways:
            >> >> - "SUB SUM()..."
            >> >> - "Private SUB SUM()..."
            >> >> - "Public SUB SUM()..." > I thought this would solve the problem.
            >> >>
            >> >> Basically I need to create functions which will be accessible from
            >> >> many
            >> >> Aspx pages.
            >> >>
            >> >> Thank You Very Much,
            >> >> Miguel
            >> >>
            >> >>[/color]
            >>
            >>
            >>[/color][/color]


            Comment

            Working...