C# to VB help required

Discussion in 'ASP .Net' started by Jon Paal, Dec 7, 2005.

  1. Jon Paal

    Jon Paal Guest

    Trying to convert this to VB and need some help. Standard converters not accepting the code.
    major problem is on the last line of code text
    thanks for any help -

    ------------ C# code ------------------
    public Global()
    {
    this.PreRequestHandlerExecute += new EventHandler(Application_PreRequestHandlerExecute);
    }

    private void Application_PreRequestHandlerExecute(Object sender, EventArgs e)
    void Application_PreRequestHandlerExecute(Object sender, EventArgs e)
    {
    HttpContext CurrentContext = HttpContext.Current;
    Page myPage = CurrentContext.Handler as Page;
    if (myPage != null)
    {
    myPage.Theme = (CurrentContext.Profile as ProfileCommon).SiteTheme;
    }
    }
     
    Jon Paal, Dec 7, 2005
    #1
    1. Advertising

  2. Jon Paal

    Karl Seguin Guest

    The last line isn't particularly well written, which is why I'd expect
    converts to throw up some errors.

    the corrent vb.net line would be:

    myPage.Theme = ctype(CurrentContext.Profile, ProfileCommon).SiteTheme


    I say it's badly programmed because "as" tries and casts a value to a type,
    and returns null if it fails. It's used as a safe-conversion. However,
    since you aren't checking for null and are simply accessing a property, you
    might as well use a direct cast.

    myPage.Theme = ((ProfileCommon)CurrentContext.Profile).SiteTheme

    or check for null:

    ProfileCommon profile = CurrentContext.Profile as ProfileCommon;
    if (profile != null)
    {
    myPage.Theme = profile.SiteTheme;
    }
    else
    {
    //default theme perhaps?? what to do?
    }


    karl
    --
    MY ASP.Net tutorials
    http://www.openmymind.net/


    "Jon Paal" <Jon nospam Paal @ everywhere dot com> wrote in message
    news:eTDt2$1%...
    > Trying to convert this to VB and need some help. Standard converters not
    > accepting the code.
    > major problem is on the last line of code text
    > thanks for any help -
    >
    > ------------ C# code ------------------
    > public Global()
    > {
    > this.PreRequestHandlerExecute += new
    > EventHandler(Application_PreRequestHandlerExecute);
    > }
    >
    > private void Application_PreRequestHandlerExecute(Object sender, EventArgs
    > e)
    > void Application_PreRequestHandlerExecute(Object sender, EventArgs e)
    > {
    > HttpContext CurrentContext = HttpContext.Current;
    > Page myPage = CurrentContext.Handler as Page;
    > if (myPage != null)
    > {
    > myPage.Theme = (CurrentContext.Profile as
    > ProfileCommon).SiteTheme;
    > }
    > }
    >
     
    Karl Seguin, Dec 7, 2005
    #2
    1. Advertising

  3. Jon Paal

    Guest

    You mean that myPage.Theme = (CurrentContext.Profile as
    ProfileCommon).SiteTheme; line?

    VB.Net version would be:
    myPage.Theme = CType(CurrentContext.Profile, ProfileCommon).SiteTheme;
     
    , Dec 7, 2005
    #3
  4. Jon Paal

    Jon Paal Guest

    this is my resultant VB code (located in my Global.asax file), but compiler is throwing this error:

    Compiler Error Message: BC30269: 'Public Sub New()' has multiple definitions with identical signatures.

    'Public Sub New()' only occurs once in the Global.asax but does get used in the App_Code files.

    Is there a way to have 'Public Sub New()' also in the Global .asax ?
    or is there another way to create an instance of the RequisiteHandler ?



    ------- VB code in Global.asax-------------
    Public Sub New()
    AddHandler Me.PreRequestHandlerExecute, AddressOf Application_PreRequestHandlerExecute
    End Sub

    Private Sub Application_PreRequestHandlerExecute(ByVal sender As Object, ByVal e As EventArgs)
    Dim CurrentContext As HttpContext = HttpContext.Current
    Dim myPage As Page = CurrentContext.Handler
    If Not myPage Is Nothing Then
    myPage.Theme = myPage.Theme = CType(CurrentContext.Profile, ProfileCommon).SiteTheme
    End If
    End Sub








    "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in message
    news:%23pYLHH2%...
    > The last line isn't particularly well written, which is why I'd expect converts to throw up some errors.
    >
    > the corrent vb.net line would be:
    >
    > myPage.Theme = ctype(CurrentContext.Profile, ProfileCommon).SiteTheme
    >
    >
    > I say it's badly programmed because "as" tries and casts a value to a type, and returns null if it fails. It's used as a
    > safe-conversion. However, since you aren't checking for null and are simply accessing a property, you might as well use a direct
    > cast.
    >
    > myPage.Theme = ((ProfileCommon)CurrentContext.Profile).SiteTheme
    >
    > or check for null:
    >
    > ProfileCommon profile = CurrentContext.Profile as ProfileCommon;
    > if (profile != null)
    > {
    > myPage.Theme = profile.SiteTheme;
    > }
    > else
    > {
    > //default theme perhaps?? what to do?
    > }
    >
    >
    > karl
    > --
    > MY ASP.Net tutorials
    > http://www.openmymind.net/
    >
    >
    > "Jon Paal" <Jon nospam Paal @ everywhere dot com> wrote in message news:eTDt2$1%...
    >> Trying to convert this to VB and need some help. Standard converters not accepting the code.
    >> major problem is on the last line of code text
    >> thanks for any help -
    >>
    >> ------------ C# code ------------------
    >> public Global()
    >> {
    >> this.PreRequestHandlerExecute += new EventHandler(Application_PreRequestHandlerExecute);
    >> }
    >>
    >> private void Application_PreRequestHandlerExecute(Object sender, EventArgs e)
    >> void Application_PreRequestHandlerExecute(Object sender, EventArgs e)
    >> {
    >> HttpContext CurrentContext = HttpContext.Current;
    >> Page myPage = CurrentContext.Handler as Page;
    >> if (myPage != null)
    >> {
    >> myPage.Theme = (CurrentContext.Profile as ProfileCommon).SiteTheme;
    >> }
    >> }
    >>

    >
    >
     
    Jon Paal, Dec 7, 2005
    #4
  5. Jon Paal

    Karl Seguin Guest

    Not sure why it would complain inVB.net and not in C#. But I can tell you
    that you shouldn't be hooking these events..they are already hooked up by
    the framework.

    Ty removing the constructor and changing the method from Private to
    Protected.

    Karl

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/


    "Jon Paal" <Jon nospam Paal @ everywhere dot com> wrote in message
    news:uRAOcT2%...
    > this is my resultant VB code (located in my Global.asax file), but
    > compiler is throwing this error:
    >
    > Compiler Error Message: BC30269: 'Public Sub New()' has multiple
    > definitions with identical signatures.
    >
    > 'Public Sub New()' only occurs once in the Global.asax but does get used
    > in the App_Code files.
    >
    > Is there a way to have 'Public Sub New()' also in the Global .asax ?
    > or is there another way to create an instance of the RequisiteHandler ?
    >
    >
    >
    > ------- VB code in Global.asax-------------
    > Public Sub New()
    > AddHandler Me.PreRequestHandlerExecute, AddressOf
    > Application_PreRequestHandlerExecute
    > End Sub
    >
    > Private Sub Application_PreRequestHandlerExecute(ByVal sender As Object,
    > ByVal e As EventArgs)
    > Dim CurrentContext As HttpContext = HttpContext.Current
    > Dim myPage As Page = CurrentContext.Handler
    > If Not myPage Is Nothing Then
    > myPage.Theme = myPage.Theme = CType(CurrentContext.Profile,
    > ProfileCommon).SiteTheme
    > End If
    > End Sub
    >
    >
    >
    >
    >
    >
    >
    >
    > "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
    > wrote in message news:%23pYLHH2%...
    >> The last line isn't particularly well written, which is why I'd expect
    >> converts to throw up some errors.
    >>
    >> the corrent vb.net line would be:
    >>
    >> myPage.Theme = ctype(CurrentContext.Profile, ProfileCommon).SiteTheme
    >>
    >>
    >> I say it's badly programmed because "as" tries and casts a value to a
    >> type, and returns null if it fails. It's used as a safe-conversion.
    >> However, since you aren't checking for null and are simply accessing a
    >> property, you might as well use a direct cast.
    >>
    >> myPage.Theme = ((ProfileCommon)CurrentContext.Profile).SiteTheme
    >>
    >> or check for null:
    >>
    >> ProfileCommon profile = CurrentContext.Profile as ProfileCommon;
    >> if (profile != null)
    >> {
    >> myPage.Theme = profile.SiteTheme;
    >> }
    >> else
    >> {
    >> //default theme perhaps?? what to do?
    >> }
    >>
    >>
    >> karl
    >> --
    >> MY ASP.Net tutorials
    >> http://www.openmymind.net/
    >>
    >>
    >> "Jon Paal" <Jon nospam Paal @ everywhere dot com> wrote in message
    >> news:eTDt2$1%...
    >>> Trying to convert this to VB and need some help. Standard converters
    >>> not accepting the code.
    >>> major problem is on the last line of code text
    >>> thanks for any help -
    >>>
    >>> ------------ C# code ------------------
    >>> public Global()
    >>> {
    >>> this.PreRequestHandlerExecute += new
    >>> EventHandler(Application_PreRequestHandlerExecute);
    >>> }
    >>>
    >>> private void Application_PreRequestHandlerExecute(Object sender,
    >>> EventArgs e)
    >>> void Application_PreRequestHandlerExecute(Object sender, EventArgs e)
    >>> {
    >>> HttpContext CurrentContext = HttpContext.Current;
    >>> Page myPage = CurrentContext.Handler as Page;
    >>> if (myPage != null)
    >>> {
    >>> myPage.Theme = (CurrentContext.Profile as
    >>> ProfileCommon).SiteTheme;
    >>> }
    >>> }
    >>>

    >>
    >>

    >
    >
     
    Karl Seguin, Dec 7, 2005
    #5
  6. Jon Paal

    Jon Paal Guest

    thanks for helping.
    I'll have to try and find a working solution for dynamic themes, because I'm getting in over my head with this one.
     
    Jon Paal, Dec 7, 2005
    #6
  7. Ahem... (only some converters have a problem with this code)
    The following was produced with our Instant VB C# to VB converter:

    Public Sub New()
    AddHandler PreRequestHandlerExecute, AddressOf
    Application_PreRequestHandlerExecute
    End Sub

    Private Sub Application_PreRequestHandlerExecute(ByVal sender As Object,
    ByVal e As EventArgs)
    Dim CurrentContext As HttpContext = HttpContext.Current
    Dim myPage As Page = TryCast(CurrentContext.Handler, Page)
    If Not myPage Is Nothing Then
    myPage.Theme = (TryCast(CurrentContext.Profile, ProfileCommon)).SiteTheme
    End If
    End Sub

    --
    David Anton
    www.tangiblesoftwaresolutions.com
    Instant C#: VB.NET to C# Converter
    Instant VB: C# to VB.NET Converter
    Instant C++: C# to C++ Converter
    Instant J#: VB.NET to J# Converter



    "Jon Paal" wrote:

    > Trying to convert this to VB and need some help. Standard converters not accepting the code.
    > major problem is on the last line of code text
    > thanks for any help -
    >
    > ------------ C# code ------------------
    > public Global()
    > {
    > this.PreRequestHandlerExecute += new EventHandler(Application_PreRequestHandlerExecute);
    > }
    >
    > private void Application_PreRequestHandlerExecute(Object sender, EventArgs e)
    > void Application_PreRequestHandlerExecute(Object sender, EventArgs e)
    > {
    > HttpContext CurrentContext = HttpContext.Current;
    > Page myPage = CurrentContext.Handler as Page;
    > if (myPage != null)
    > {
    > myPage.Theme = (CurrentContext.Profile as ProfileCommon).SiteTheme;
    > }
    > }
    >
    >
    >
     
    =?Utf-8?B?RGF2aWQgQW50b24=?=, Dec 8, 2005
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dinesh Upare

    help required urgent

    Dinesh Upare, Aug 13, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    1,017
    Carl Prothman [MVP]
    Aug 13, 2003
  2. Kashif
    Replies:
    6
    Views:
    563
    Kashif
    Nov 29, 2005
  3. SenthilVel

    Help Required for Help Context Id !!!!!!

    SenthilVel, Nov 30, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    3,192
    SenthilVel
    Dec 14, 2005
  4. Just D.
    Replies:
    0
    Views:
    462
    Just D.
    Mar 10, 2006
  5. Emiliano
    Replies:
    2
    Views:
    347
    Rajesh.V
    Oct 16, 2003
Loading...

Share This Page