convert this function in vb.net to C#

K

Karunakararao

Hi All

I done this function VB.NET

i want convert this function in C# pls help me.


Sub CustomPager(ByVal STCPagerGrid As Object)
Dim intCtr As Integer
Static intLastItem As Integer
Static intCount As Integer
Static intTotalPage, lintCurrentPage As Integer

For intCtr = 0 To STCPagerGrid.Controls.Count - 1
If STCPagerGrid.Controls(intCtr).GetType.ToString =
"System.Web.UI.WebControls.DataGridLinkButton" Then
If IsNumeric(STCPagerGrid.controls(intCtr).text) =
True And Left(STCPagerGrid.controls(intCtr).text, 1) <> "[" Then
STCPagerGrid.controls(intCtr).text = "[" &
STCPagerGrid.controls(intCtr).text & "]"
If STCPagerGrid.Controls(intCtr).Text = "..." And
intCtr = 0 Then
STCPagerGrid.Controls(intCtr).Text = "[<<]"
End If
If STCPagerGrid.Controls(intCtr).Text = "..." And
intCtr > 0 Then
STCPagerGrid.Controls(intCtr).Text = "[>>]"
End If
End If
If STCPagerGrid.controls(intCtr).controls.count > 0 Then
CustomPager(STCPagerGrid.controls(intCtr))
End If
Next
End Sub


Regards
Venu.
 
N

Niki Estner

Karunakararao said:
Hi All

I done this function VB.NET

i want convert this function in C# pls help me.

What exactly is your problem? The sub looks pretty straightforward, why
don't you just convert it?

BTW: You should really think about discarding that code and rewriting it:
it's quite ugly; You don't use most of the variables you declare, you do far
too many string comparisons and that loop would be a lot more readable using
"foreach".
Sub CustomPager(ByVal STCPagerGrid As Object)
Dim intCtr As Integer
Static intLastItem As Integer
Static intCount As Integer
Static intTotalPage, lintCurrentPage As Integer

For intCtr = 0 To STCPagerGrid.Controls.Count - 1
If STCPagerGrid.Controls(intCtr).GetType.ToString =
"System.Web.UI.WebControls.DataGridLinkButton" Then
If IsNumeric(STCPagerGrid.controls(intCtr).text) =
True And Left(STCPagerGrid.controls(intCtr).text, 1) <> "[" Then
STCPagerGrid.controls(intCtr).text = "[" &
STCPagerGrid.controls(intCtr).text & "]"
If STCPagerGrid.Controls(intCtr).Text = "..." And
intCtr = 0 Then
STCPagerGrid.Controls(intCtr).Text = "[<<]"
End If
If STCPagerGrid.Controls(intCtr).Text = "..." And
intCtr > 0 Then
STCPagerGrid.Controls(intCtr).Text = "[>>]"
End If
End If
If STCPagerGrid.controls(intCtr).controls.count > 0 Then
CustomPager(STCPagerGrid.controls(intCtr))
End If
Next
End Sub
 
P

PseudoBill

After cleaning up your code so that it was compilable in VB.NET (you
were missing an "End If", I ran it through the VB.NET to C# converter
Instant C# (www.instantcsharp.com) and got the following:

//INSTANT C# NOTE: These were formerly VB static local variables:
private int intLastItem;
private int intCount;
private int intTotalPage;
private int lintCurrentPage;

public void CustomPager(object STCPagerGrid)
{
int intCtr = 0;
//INSTANT C# NOTE: VB local static variable moved to class level
//Static intLastItem As Integer
//INSTANT C# NOTE: VB local static variable moved to class level
//Static intCount As Integer
//INSTANT C# NOTE: VB local static variable moved to class level
//Static intTotalPage, lintCurrentPage As Integer
//INSTANT C# NOTE: VB local static variable moved to class level
//Static lintCurrentPage As Integer

//INSTANT C# WARNING: Unlike VB, the ending condition is tested on
each iteration in C# for loops. If STCPagerGrid.Controls.Count - 1
changes within the loop, you will need to make the necessary
modification:
for (intCtr = 0; intCtr <= STCPagerGrid.Controls.Count - 1;
intCtr++)
{
if (STCPagerGrid.Controls.GetType().ToString ==
"System.Web.UI.WebControls.DataGridLinkButton")
{
if
(Microsoft.VisualBasic.Information.IsNumeric(STCPagerGrid.Controls[intCtr].Text)
== true & STCPagerGrid.Controls[intCtr].Text.Substring(0, 1) !=
"[")
{
STCPagerGrid.Controls[intCtr].Text = "[" +
STCPagerGrid.Controls[intCtr].Text + "]";
if (STCPagerGrid.Controls[intCtr].Text == "..." & intCtr == 0)
{
STCPagerGrid.Controls[intCtr].Text = "[<<]";
}
if (STCPagerGrid.Controls[intCtr].Text == "..." & intCtr >
0)
{
STCPagerGrid.Controls[intCtr].Text = "[>>]";
}
}
if (STCPagerGrid.Controls[intCtr].controls.Count > 0)
{
CustomPager(STCPagerGrid.Controls[intCtr]);
}
}
}

}
 
F

Frank Eller [MVP]

Hi,
I done this function VB.NET

i want convert this function in C# pls help me.

Just a note from me: You should really consider learning to read and
understand both, C# and VB.NET. Such situations will happen very often ...

Regards,

Frank Eller
www.frankeller.de
 

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