Need help converting C# code to VB.NET code...

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

    Need help converting C# code to VB.NET code...

    I downloaded a web timer control from
    http://www.eggheadcafe.com/articles/20021006.asp and it's written in C#. The
    code and .DLL comes with the download so I'm trying to convert the sample
    which was written in C# to VB (ASP.NET). Here is the following code in the
    Default.aspx page...

    private void PgTimer1_Elapse d(object sender, System.EventArg s e)
    {
    if (Application["PgTimer"] == null)
    {
    Application["PgTimer"] = 0;
    }

    string strResult = "Elapsed Event: " + DateTime.Now.Mi llisecond;
    Application["PgTimer"] = (int)Applicatio n["PgTimer"] + 1;

    Response.Write( "Instance: " + Application["PgTimer"].ToString() + ": " +
    strResult);
    }

    Can anyone help me convert this to its VB.NET equivalent?

    Here is what I have so far...

    Private Sub PgTimer1_Elapse d(ByVal sender As System.Object, ByVal e As
    System.EventArg s) Handles PgTimer1.Elapse d
    Dim strResult As String
    Dim intNum As Integer

    strResult = "Elapsed Event: " & DateTime.Now.Mi llisecond

    ' The following line is just a placeholder only until I figure out
    ' how to convert the following C# code.
    '
    ' Application["PgTimer"] = (int)Applicatio n["PgTimer"] + 1;
    intNum += 1

    Response.Write( "Instance: " & intNum.ToString () & ": " + strResult)
    End Sub


  • Shiva

    #2
    Re: Need help converting C# code to VB.NET code...

    Hi,
    You can check this one out:

    -- Not Tested --
    Private Sub PgTimer1_Elapse d (ByVal sender As Object, ByVal e As EventArgs)
    Handles PgTimer1.Elapse d
    If (Application("P gTimer") Is Nothing) Then Application("Pg Timer") = 0

    Dim strResult As String = "Elapsed Event: " & DateTime.Now.Mi llisecond
    Application("Pg Timer") = DirectCast (Application("P gTimer"), Int32) + 1

    Response.Write ("Instance: " & Application("Pg Timer").ToStrin g() & ": "
    & strResult)
    End Sub
    -- Not Tested --

    "Unforgiven " <stthomp@hotmai l.com> wrote in message
    news:uUSe#ColEH A.1652@TK2MSFTN GP09.phx.gbl...
    I downloaded a web timer control from
    http://www.eggheadcafe.com/articles/20021006.asp and it's written in C#. The
    code and .DLL comes with the download so I'm trying to convert the sample
    which was written in C# to VB (ASP.NET). Here is the following code in the
    Default.aspx page...

    private void PgTimer1_Elapse d(object sender, System.EventArg s e)
    {
    if (Application["PgTimer"] == null)
    {
    Application["PgTimer"] = 0;
    }

    string strResult = "Elapsed Event: " + DateTime.Now.Mi llisecond;
    Application["PgTimer"] = (int)Applicatio n["PgTimer"] + 1;

    Response.Write( "Instance: " + Application["PgTimer"].ToString() + ": " +
    strResult);
    }

    Can anyone help me convert this to its VB.NET equivalent?

    Here is what I have so far...

    Private Sub PgTimer1_Elapse d(ByVal sender As System.Object, ByVal e As
    System.EventArg s) Handles PgTimer1.Elapse d
    Dim strResult As String
    Dim intNum As Integer

    strResult = "Elapsed Event: " & DateTime.Now.Mi llisecond

    ' The following line is just a placeholder only until I figure out
    ' how to convert the following C# code.
    '
    ' Application["PgTimer"] = (int)Applicatio n["PgTimer"] + 1;
    intNum += 1

    Response.Write( "Instance: " & intNum.ToString () & ": " + strResult)
    End Sub



    Comment

    • Cor Ligthert

      #3
      Re: Need help converting C# code to VB.NET code...

      Hi Unforgiven,

      Some months ago OHM showed me that I gave a wrong advice and he was right.



      I tested this as well (what is not in this thread) with the application
      state, just to see the behaviour of a webpage.

      From that I know that probably the Session.Item is a better choose for what
      you want to do, the application goes fine when there is only one client
      busy. With more pages you get probably unpredictable results/.

      I show you this thread because the code you want is in my opinion almost
      complete there.

      Cor.



      "Unforgiven "
      [color=blue]
      > I downloaded a web timer control from
      > http://www.eggheadcafe.com/articles/20021006.asp and it's written in C#.[/color]
      The[color=blue]
      > code and .DLL comes with the download so I'm trying to convert the sample
      > which was written in C# to VB (ASP.NET). Here is the following code in the
      > Default.aspx page...
      >
      > private void PgTimer1_Elapse d(object sender, System.EventArg s e)
      > {
      > if (Application["PgTimer"] == null)
      > {
      > Application["PgTimer"] = 0;
      > }
      >
      > string strResult = "Elapsed Event: " + DateTime.Now.Mi llisecond;
      > Application["PgTimer"] = (int)Applicatio n["PgTimer"] + 1;
      >
      > Response.Write( "Instance: " + Application["PgTimer"].ToString() + ": " +
      > strResult);
      > }
      >
      > Can anyone help me convert this to its VB.NET equivalent?
      >
      > Here is what I have so far...
      >
      > Private Sub PgTimer1_Elapse d(ByVal sender As System.Object, ByVal e As
      > System.EventArg s) Handles PgTimer1.Elapse d
      > Dim strResult As String
      > Dim intNum As Integer
      >
      > strResult = "Elapsed Event: " & DateTime.Now.Mi llisecond
      >
      > ' The following line is just a placeholder only until I figure out
      > ' how to convert the following C# code.
      > '
      > ' Application["PgTimer"] = (int)Applicatio n["PgTimer"] + 1;
      > intNum += 1
      >
      > Response.Write( "Instance: " & intNum.ToString () & ": " + strResult)
      > End Sub
      >
      >[/color]


      Comment

      • Unforgiven

        #4
        Re: Need help converting C# code to VB.NET code...

        That works, thanks Shiva.

        -U

        Shiva wrote:
        : Hi,
        : You can check this one out:
        :
        : -- Not Tested --
        : Private Sub PgTimer1_Elapse d (ByVal sender As Object, ByVal e As
        : EventArgs) Handles PgTimer1.Elapse d
        : If (Application("P gTimer") Is Nothing) Then Application("Pg Timer")
        : = 0
        :
        : Dim strResult As String = "Elapsed Event: " &
        : DateTime.Now.Mi llisecond Application("Pg Timer") = DirectCast
        : (Application("P gTimer"), Int32) + 1
        :
        : Response.Write ("Instance: " & Application("Pg Timer").ToStrin g() &
        : ": " & strResult)
        : End Sub
        : -- Not Tested --
        :
        : "Unforgiven " <stthomp@hotmai l.com> wrote in message
        : news:uUSe#ColEH A.1652@TK2MSFTN GP09.phx.gbl...
        : I downloaded a web timer control from
        : http://www.eggheadcafe.com/articles/20021006.asp and it's written in
        : C#. The code and .DLL comes with the download so I'm trying to
        : convert the sample which was written in C# to VB (ASP.NET). Here is
        : the following code in the Default.aspx page...
        :
        : private void PgTimer1_Elapse d(object sender, System.EventArg s e)
        : {
        : if (Application["PgTimer"] == null)
        : {
        : Application["PgTimer"] = 0;
        : }
        :
        : string strResult = "Elapsed Event: " + DateTime.Now.Mi llisecond;
        : Application["PgTimer"] = (int)Applicatio n["PgTimer"] + 1;
        :
        : Response.Write( "Instance: " + Application["PgTimer"].ToString() + ":
        : " + strResult);
        : }
        :
        : Can anyone help me convert this to its VB.NET equivalent?
        :
        : Here is what I have so far...
        :
        : Private Sub PgTimer1_Elapse d(ByVal sender As System.Object, ByVal e As
        : System.EventArg s) Handles PgTimer1.Elapse d
        : Dim strResult As String
        : Dim intNum As Integer
        :
        : strResult = "Elapsed Event: " & DateTime.Now.Mi llisecond
        :
        : ' The following line is just a placeholder only until I figure out
        : ' how to convert the following C# code.
        : '
        : ' Application["PgTimer"] = (int)Applicatio n["PgTimer"] + 1;
        : intNum += 1
        :
        : Response.Write( "Instance: " & intNum.ToString () & ": " + strResult)
        : End Sub


        Comment

        • Joel Cade, MCSD

          #5
          Re: Need help converting C# code to VB.NET code...

          For future reference, here's a cool tool I've used in the past.



          Joel Cade, MCSD .Net, MCAD, MCP
          Fig Tree Solutions, LLC
          Find your domain name at HugeDomains. Start using this domain right away.


          *** Sent via Developersdex http://www.developersdex.com ***
          Don't just participate in USENET...get rewarded for it!

          Comment

          • Herfried K. Wagner [MVP]

            #6
            Re: Need help converting C# code to VB.NET code...

            * "Unforgiven " <stthomp@hotmai l.com> scripsit:[color=blue]
            > I downloaded a web timer control from
            > http://www.eggheadcafe.com/articles/20021006.asp and it's written in C#. The
            > code and .DLL comes with the download so I'm trying to convert the sample
            > which was written in C# to VB (ASP.NET). Here is the following code in the
            > Default.aspx page...[/color]

            From my FAQ (<URL:http://dotnet.mvps.org/dotnet/faqs/>):

            Converters for converting source code between .NET programming languages:

            C# to VB.NET Translator
            <URL:http://www.aspalliance .com/aldotnet/examples/translate.aspx>

            ConvertCSharp2V B
            <URL:http://www.kamalpatel. net/ConvertCSharp2V B.aspx>

            Clarity Consulting C# Converter
            <URL:http://csharpconverter .claritycon.com/>

            CSharp to VB.NET Code Converter
            <URL:http://www.ragingsmurf .com/vbcsharpconvert er.aspx>

            Convert C# to VB.NET
            <URL:http://www.gotdotnet.c om/Community/UserSamples/Details.aspx?Sa mpleGuid=c62234 8b-18a9-47d6-8687-979975d5957d>

            SharpDevelop @ic#code
            <URL:http://www.icsharpcode .com/OpenSource/SD/>

            Commercial:

            Octopus .NET Translator
            <URL:http://www.remotesoft. com/octopus/>

            Commercial VB/VB.NET to C# converter (rather useless):

            TransKing
            <URL:http://www.e-iceblue.com/>

            --
            M S Herfried K. Wagner
            M V P <URL:http://dotnet.mvps.org/>
            V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

            Comment

            Working...