Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > C# to VB help required

Reply
Thread Tools

C# to VB help required

 
 
Jon Paal
Guest
Posts: n/a
 
      12-07-2005
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;
}
}


 
Reply With Quote
 
 
 
 
Karl Seguin
Guest
Posts: n/a
 
      12-07-2005
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%(E-Mail Removed)...
> 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;
> }
> }
>



 
Reply With Quote
 
 
 
 
grey_christ@yahoo.com
Guest
Posts: n/a
 
      12-07-2005
You mean that myPage.Theme = (CurrentContext.Profile as
ProfileCommon).SiteTheme; line?

VB.Net version would be:
myPage.Theme = CType(CurrentContext.Profile, ProfileCommon).SiteTheme;

 
Reply With Quote
 
Jon Paal
Guest
Posts: n/a
 
      12-07-2005
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%(E-Mail Removed)...
> 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%(E-Mail Removed)...
>> 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;
>> }
>> }
>>

>
>



 
Reply With Quote
 
Karl Seguin
Guest
Posts: n/a
 
      12-07-2005
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%(E-Mail Removed)...
> 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%(E-Mail Removed)...
>> 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%(E-Mail Removed)...
>>> 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;
>>> }
>>> }
>>>

>>
>>

>
>



 
Reply With Quote
 
Jon Paal
Guest
Posts: n/a
 
      12-07-2005
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.



 
Reply With Quote
 
=?Utf-8?B?RGF2aWQgQW50b24=?=
Guest
Posts: n/a
 
      12-08-2005
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;
> }
> }
>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create a VD with required properties on a required Web Server (Windows Advanced Server 2000 has 3 Web Servers) Just D. ASP .Net 0 03-10-2006 06:02 AM
Help Required for Help Context Id !!!!!! SenthilVel ASP .Net 4 12-14-2005 11:48 AM
PLEASE HELP, Techie Help desperately required... David Dean Computer Support 6 10-31-2005 01:04 PM
Thunderbird: Newsgroup settings - help required please Morgan Firefox 1 04-01-2005 01:44 PM
help pls. textbox required only when checkbox is checked (help with validation) Emiliano ASP .Net Web Controls 2 10-16-2003 09:09 PM



Advertisments