any one who can translate this vb.net to C# ?

K

Kylin

Public Class test1
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents Button2 As System.Web.UI.WebControls.Button
Protected WithEvents Label1 As System.Web.UI.WebControls.Label

'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region
Private _refreshState As Boolean
Private _isRefresh As Boolean

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Me.label1.Text = "Page Refreshed =" + _isRefresh.ToString
End Sub

Protected Overrides Sub LoadViewState(ByVal savedState As Object)
Dim AllStates As Object() = savedState
MyBase.LoadViewState(AllStates(0))
_refreshState = Boolean.Parse(AllStates(1))
_isRefresh = _refreshState = Session("__ISREFRESH")
End Sub

Protected Overrides Function SaveViewState() As Object
Session("__ISREFRESH") = _refreshState
Dim AllStates() As Object = New Object(2) {}
AllStates(0) = MyBase.SaveViewState
AllStates(1) = Not (_refreshState)
Return AllStates

End Function


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

End Sub
End Class
 
K

Kevin Spencer

That would be you, as soon as you learn C#.

You probably will get some responses. However, asking in a public newsgroup
for some stranger to rewrite your code is just plain crazy. Why? Because, as
my mother used to say, "You're going to put that into your mouth? You don't
know where it's been!" And, if you don't know C#, you will never know
whether or not what some stranger writes for you is good code or bad code.
Believe it or not, there are some terribly unscrupulous, dishonest, lazy,
and crazy people out there. The Internet doesn't have any filters on it.
Unlike certain dishonest ISPs, the Internet itself doesn't claim to protect
you from anything or anyone. And what are you going to tell your boss when
the code that you copied and pasted into his hard-bought software, that he
paid you to write, breaks? "Well, darn, boss, the total stranger that gave
it to me for free must not have known how to program correctly." If your
boss is any good, and he probably didn't become a boss by NOT being any
good, he will probably reply "I didn't pay some stranger to write my code. I
paid you. You're fired."

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Sometimes you eat the elephant.
Sometimes the elephant eats you.
 
G

Guest

The following is produced by our Instant C# VB.NET to C# converter (it can
also be produced with our free Demo Edition at www.instantcsharp.com):

public class test1 : System.Web.UI.Page
{

#region Web Form Designer Generated Code

//This call is required by the Web Form Designer.
[System.Diagnostics.DebuggerStepThrough()]
private void InitializeComponent()
{

//INSTANT C# NOTE: Converted event handlers:
this.Load += new System.EventHandler(Page_Load);
Button1.Click += new System.EventHandler(Button1_Click);

}
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.Label Label1;

//NOTE: The following placeholder declaration is required by the Web
Form Designer.
//Do not delete or move it.
private object designerPlaceholderDeclaration;

//ORIGINAL LINE: Private Sub Page_Init(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles base.Init
override protected void OnInit(System.EventArgs e)
{
base.OnInit(e);
//CODEGEN: This method call is required by the Web Form
Designer
//Do not modify it using the code editor.
InitializeComponent();
}

#endregion
private bool _refreshState;
private bool _isRefresh;

//INSTANT C# NOTE: This method is an event handler
//ORIGINAL LINE: Private Sub Page_Load(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles base.Load
private void Page_Load(object sender, System.EventArgs e)
{
//Put user code to initialize the page here
this.label1.Text = "Page Refreshed =" +
_isRefresh.ToString();
}

protected override void LoadViewState(object savedState)
{
object[] AllStates = savedState;
base.LoadViewState(AllStates[0]);
_refreshState = bool.Parse(AllStates[1]);
_isRefresh = _refreshState == Session["__ISREFRESH"];
}

protected override object SaveViewState()
{
Session["__ISREFRESH"] = _refreshState;
object[] AllStates = new object[3];
AllStates[0] = base.SaveViewState();
AllStates[1] = ! (_refreshState);
return AllStates;

}



//INSTANT C# NOTE: This method is an event handler
//ORIGINAL LINE: Private Sub Button1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button1.Click

private void Button1_Click(object sender, System.EventArgs e)
{

}
}

As Kevin mentioned, certainly learn C# yourself and verify that the
translation is correct. You certainly don't want to translate thousands of
lines of code manually, but you do need to know whether the converted code is
good or not.

Enjoy,
David Anton
www.tangiblesoftwaresolutions.com
Home of the Instant C# VB.NET to C# converter
and the Instant VB C# to VB.NET converter
 
G

Guest

Yes, definitely learn C#. However, if you attempt converting thousands of
lines of code by hand your boss is going to say "are you crazy? - they have
tools for this!". For a trivial snippet it's one thing, but even for an
entire file it's error-prone and likely to induce carpal tunnel syndrome.

Learn C#, construct your own test, and then find a converter that passes
your tests.
(we obviously hope it'll be our's - Instant C#).

David Anton
www.tangiblesoftwaresolutions.com
Home of the Instant C# VB.NET to C# converter
and the Instant VB C# to VB.NET converter
 
K

Kevin Spencer

Hi David,

I'm impressed!

--

Kevin Spencer
Microsoft MVP
..Net Developer
Sometimes you eat the elephant.
Sometimes the elephant eats you.

David Anton said:
The following is produced by our Instant C# VB.NET to C# converter (it can
also be produced with our free Demo Edition at www.instantcsharp.com):

public class test1 : System.Web.UI.Page
{

#region Web Form Designer Generated Code

//This call is required by the Web Form Designer.
[System.Diagnostics.DebuggerStepThrough()]
private void InitializeComponent()
{

//INSTANT C# NOTE: Converted event handlers:
this.Load += new System.EventHandler(Page_Load);
Button1.Click += new System.EventHandler(Button1_Click);

}
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.Label Label1;

//NOTE: The following placeholder declaration is required by the
Web
Form Designer.
//Do not delete or move it.
private object designerPlaceholderDeclaration;

//ORIGINAL LINE: Private Sub Page_Init(ByVal sender As System.Object,
ByVal
e As System.EventArgs) Handles base.Init
override protected void OnInit(System.EventArgs e)
{
base.OnInit(e);
//CODEGEN: This method call is required by the Web Form
Designer
//Do not modify it using the code editor.
InitializeComponent();
}

#endregion
private bool _refreshState;
private bool _isRefresh;

//INSTANT C# NOTE: This method is an event handler
//ORIGINAL LINE: Private Sub Page_Load(ByVal sender As System.Object,
ByVal
e As System.EventArgs) Handles base.Load
private void Page_Load(object sender, System.EventArgs e)
{
//Put user code to initialize the page here
this.label1.Text = "Page Refreshed =" +
_isRefresh.ToString();
}

protected override void LoadViewState(object savedState)
{
object[] AllStates = savedState;
base.LoadViewState(AllStates[0]);
_refreshState = bool.Parse(AllStates[1]);
_isRefresh = _refreshState == Session["__ISREFRESH"];
}

protected override object SaveViewState()
{
Session["__ISREFRESH"] = _refreshState;
object[] AllStates = new object[3];
AllStates[0] = base.SaveViewState();
AllStates[1] = ! (_refreshState);
return AllStates;

}



//INSTANT C# NOTE: This method is an event handler
//ORIGINAL LINE: Private Sub Button1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button1.Click

private void Button1_Click(object sender, System.EventArgs e)
{

}
}

As Kevin mentioned, certainly learn C# yourself and verify that the
translation is correct. You certainly don't want to translate thousands
of
lines of code manually, but you do need to know whether the converted code
is
good or not.

Enjoy,
David Anton
www.tangiblesoftwaresolutions.com
Home of the Instant C# VB.NET to C# converter
and the Instant VB C# to VB.NET converter

Kylin said:
Public Class test1
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents Button2 As System.Web.UI.WebControls.Button
Protected WithEvents Label1 As System.Web.UI.WebControls.Label

'NOTE: The following placeholder declaration is required by the Web
Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region
Private _refreshState As Boolean
Private _isRefresh As Boolean

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Me.label1.Text = "Page Refreshed =" + _isRefresh.ToString
End Sub

Protected Overrides Sub LoadViewState(ByVal savedState As Object)
Dim AllStates As Object() = savedState
MyBase.LoadViewState(AllStates(0))
_refreshState = Boolean.Parse(AllStates(1))
_isRefresh = _refreshState = Session("__ISREFRESH")
End Sub

Protected Overrides Function SaveViewState() As Object
Session("__ISREFRESH") = _refreshState
Dim AllStates() As Object = New Object(2) {}
AllStates(0) = MyBase.SaveViewState
AllStates(1) = Not (_refreshState)
Return AllStates

End Function


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

End Sub
End Class
 
B

billmiami2

You certainly don't want to translate thousands of
lines of code manually, but you do need to know whether the converted
code is
good or not. <<

Perhaps it was overkill, but I learned C# by translating thousands of
lines of VB.NET manually. It was tedious but didn't take as long as
you might think. It works!

Bill E.
 
G

Guest

Sure - do a few thousand lines to learn. But eventually there are
diminishing returns to doing it by hand.
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top