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

U

Unforgiven

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_Elapsed(object sender, System.EventArgs e)
{
if (Application["PgTimer"] == null)
{
Application["PgTimer"] = 0;
}

string strResult = "Elapsed Event: " + DateTime.Now.Millisecond;
Application["PgTimer"] = (int)Application["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_Elapsed(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles PgTimer1.Elapsed
Dim strResult As String
Dim intNum As Integer

strResult = "Elapsed Event: " & DateTime.Now.Millisecond

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

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

Shiva

Hi,
You can check this one out:

-- Not Tested --
Private Sub PgTimer1_Elapsed (ByVal sender As Object, ByVal e As EventArgs)
Handles PgTimer1.Elapsed
If (Application("PgTimer") Is Nothing) Then Application("PgTimer") = 0

Dim strResult As String = "Elapsed Event: " & DateTime.Now.Millisecond
Application("PgTimer") = DirectCast (Application("PgTimer"), Int32) + 1

Response.Write ("Instance: " & Application("PgTimer").ToString() & ": "
& strResult)
End Sub
-- Not Tested --

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_Elapsed(object sender, System.EventArgs e)
{
if (Application["PgTimer"] == null)
{
Application["PgTimer"] = 0;
}

string strResult = "Elapsed Event: " + DateTime.Now.Millisecond;
Application["PgTimer"] = (int)Application["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_Elapsed(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles PgTimer1.Elapsed
Dim strResult As String
Dim intNum As Integer

strResult = "Elapsed Event: " & DateTime.Now.Millisecond

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

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

Cor Ligthert

Hi Unforgiven,

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

http://tinyurl.com/3suad

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"
 
U

Unforgiven

That works, thanks Shiva.

-U

Shiva wrote:
: Hi,
: You can check this one out:
:
: -- Not Tested --
: Private Sub PgTimer1_Elapsed (ByVal sender As Object, ByVal e As
: EventArgs) Handles PgTimer1.Elapsed
: If (Application("PgTimer") Is Nothing) Then Application("PgTimer")
: = 0
:
: Dim strResult As String = "Elapsed Event: " &
: DateTime.Now.Millisecond Application("PgTimer") = DirectCast
: (Application("PgTimer"), Int32) + 1
:
: Response.Write ("Instance: " & Application("PgTimer").ToString() &
: ": " & strResult)
: End Sub
: -- Not Tested --
:
: : 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_Elapsed(object sender, System.EventArgs e)
: {
: if (Application["PgTimer"] == null)
: {
: Application["PgTimer"] = 0;
: }
:
: string strResult = "Elapsed Event: " + DateTime.Now.Millisecond;
: Application["PgTimer"] = (int)Application["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_Elapsed(ByVal sender As System.Object, ByVal e As
: System.EventArgs) Handles PgTimer1.Elapsed
: Dim strResult As String
: Dim intNum As Integer
:
: strResult = "Elapsed Event: " & DateTime.Now.Millisecond
:
: ' The following line is just a placeholder only until I figure out
: ' how to convert the following C# code.
: '
: ' Application["PgTimer"] = (int)Application["PgTimer"] + 1;
: intNum += 1
:
: Response.Write("Instance: " & intNum.ToString() & ": " + strResult)
: End Sub
 
H

Herfried K. Wagner [MVP]

* "Unforgiven said:
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...

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>

ConvertCSharp2VB
<URL:http://www.kamalpatel.net/ConvertCSharp2VB.aspx>

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

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

Convert C# to VB.NET
<URL:http://www.gotdotnet.com/Community/...mpleGuid=c622348b-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/>
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top