473,396 Members | 1,853 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Convert VB code to C# code

I need help converting the VB code

Private Sub Button1_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
Dim cntrlTester As Control
Dim chkTester As CheckBox
Dim sb As New System.Text.StringBuilder
For Each cntrlTester In _
Page.Controls(1).Controls
If TypeOf cntrlTester Is _
System.Web.UI.WebControls.CheckBox Then
chkTester = cntrlTester
sb.Append(chkTester.ID & _
" : " & chkTester.Checked.ToString & _
"<br>")
End If
Next
Label1.Text = sb.ToString
End Su
<form id="Form1" method="post" runat="server"><p><asp:CheckBox id="CheckBox1" runat="server"
text="checkbox1"></asp:checkbox></p><p><asp:CheckBox id="CheckBox2" runat="server"
text="checkbox2"></asp:checkbox></p><p><asp:CheckBox id="CheckBox3" runat="server"
text="checkbox3"></asp:checkbox></p><p><asp:Label id="Label1" runat="server"></asp:label></p><p><asp:Button id="Button1" runat="server" text="button"></asp:button></p></form

TO C# code for Visual Studio .NE

Thanks

bebo
Jul 21 '05 #1
7 3777
Cor
Hi bebop,

This must be so easy, here some links to get the basic differences.
The HTML part stays the same.

Code C# and VB
http://www.harding.edu/USER/fmccown/...omparison.html

Language compare
http://msdn.microsoft.com/library/en...quivalents.asp

I hope this helps a little bit?

Cor

Private Sub Button1_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
Dim cntrlTester As Control
Dim chkTester As CheckBox
Dim sb As New System.Text.StringBuilder
For Each cntrlTester In _
Page.Controls(1).Controls
If TypeOf cntrlTester Is _
System.Web.UI.WebControls.CheckBox Then
chkTester = cntrlTester
sb.Append(chkTester.ID & _
" : " & chkTester.Checked.ToString & _
"<br>")
End If
Next
Label1.Text = sb.ToString
End Sub
<form id="Form1" method="post" runat="server"><p><asp:CheckBox id="CheckBox1" runat="server" text="checkbox1"></asp:checkbox></p><p><asp:CheckBox id="CheckBox2" runat="server" text="checkbox2"></asp:checkbox></p><p><asp:CheckBox id="CheckBox3" runat="server" text="checkbox3"></asp:checkbox></p><p><asp:Label id="Label1" runat="server"></asp:label></p><p><asp:Button id="Button1" runat="server"
text="button"></asp:button></p></form>
TO C# code for Visual Studio .NET

Thanks.

bebop

Jul 21 '05 #2
It helps a little but not much because the comparison isn't the same

In VB code it uses a foreach

Private Sub Button1_Click _ (ByVal sender As System.Object, _ ByVal e As System.EventArgs) _
Handles Button1.Click
Dim cntrlTester As Control
Dim chkTester As CheckBox
Dim sb As New System.Text.StringBuilder
For Each cntrlTester In _ Page.Controls(1).Controls //the C# equivalent uses an array with a foreach and VB code
If TypeOf cntrlTester Is _ //doesn't use an array at the link
System.Web.UI.WebControls.CheckBox Then // http://www.harding.edu/USER/fmccown/WWW
chkTester = cntrlTester /vbnet_csharp_comparison.htm
sb.Append(chkTester.ID & _
" : " & chkTester.Checked.ToString & _
"<br>")
End If
Next
Label1.Text = sb.ToString
End Sub
Jul 21 '05 #3
I got the following via Instant C#:

//INSTANT C# TODO TASK: Insert the following converted event handlers
at the end of the 'InitializeComponent' method for forms or into a
constructor for other classes:
//Button1.Click += new System.EventHandler(Button1_Click);

private void Button1_Click(object sender, System.EventArgs e)
{
CheckBox chkTester = null;
System.Text.StringBuilder sb = new System.Text.StringBuilder();
foreach (Control cntrlTester in Page.Controls[1].Controls)
{
if (typeof(cntrlTester) == System.Web.UI.WebControls.CheckBox)
{
chkTester = cntrlTester;
sb.Append(chkTester.ID + " : " + chkTester.Checked.ToString() +
"<br>");
}
}
Label1.Text = sb.ToString();
}
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Jul 21 '05 #4
I tried your code in Visual Studio C# .NET

got errors:

The type or namespace name 'cntrlTester' could not be found(are you
missing a using directive or an assembly reference?)

and

Cannot implicitly convert type 'System.Web.UI.Control' to
'System.Web.UI.WebControls.CheckBox'

Did you get the same errors when you tried the code?

bebop


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 21 '05 #5
Here is the sanitized code: (Instant C# is fixing the conversion of
VB's TypeOf for the next release)

//INSTANT C# TODO TASK: Insert the following converted event handlers
at the end of the 'InitializeComponent' method for forms or into a
constructor for other classes:
//Button1.Click += new System.EventHandler(Button1_Click);

private void Button1_Click(object sender, System.EventArgs e)
{
CheckBox chkTester = null;
System.Text.StringBuilder sb = new System.Text.StringBuilder();
foreach (Control cntrlTester in Page.Controls[1].Controls)
{
if (cntrlTester is System.Web.UI.WebControls.CheckBox)
{
chkTester = (CheckBox)cntrlTester;
sb.Append(chkTester.ID + " : " + chkTester.Checked.ToString() +
"<br>");
}
}
Label1.Text = sb.ToString();
}
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Jul 21 '05 #6
I got it working changed some lines so that the CheckBox value is
displayed in the Label.

Thanks.

bebop

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 21 '05 #7
Friends

For Good Result Plzzzzzzzz go To url

http://www.ellkay.com/

Here You are able to convert the Vb.Net Code To C# and Vice-Versa

For MOre Queries Contact

Vikram
+9891122245
devilin_hotm@yahoo.com
Nov 8 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Eric Lilja | last post by:
Hello, I've made a templated class Option (a child of the abstract base class OptionBase) that stores an option name (in the form someoption=) and the value belonging to that option. The value is...
4
by: aevans1108 | last post by:
expanding this message to microsoft.public.dotnet.xml Greetings Please direct me to the right group if this is an inappropriate place to post this question. Thanks. I want to format a...
6
by: Ricardo Quintanilla | last post by:
i have a code that sends data to a socket listening over as400 platform, the socket responds to me as a "byte array". then i need to convert the "byte array" into a string. the problem is that...
5
by: simon | last post by:
I have datetime variable: Datetime tsEndTime; Should I use (DateTime): tsEndTime=(DateTime)rdr.GetValue(15) or is better to use: tsEndTime=Convert.ToDateTime(rdr.GetValue(15))
3
by: Thubaiti | last post by:
Hi, I have this code in my ASP.NET and I want to convert it to C# (code behind) <asp:Repeater id="subCategoryRepeater" runat="server"> <ItemTemplate> <ul> <li> <asp:HyperLink...
25
by: Charles Law | last post by:
I thought this was going to be straight forward, given the wealth of conversion functions in .NET, but it is proving more convoluted than imagined. Given the following <code> Dim ba(1) As...
7
by: patang | last post by:
I want to convert amount to words. Is there any funciton available? Example: $230.30 Two Hundred Thirty Dollars and 30/100
6
by: patang | last post by:
Could someone please tell me where am I supposed to put this code. Actually my project has two forms. I created a new module and have put the following code sent by someone. All the function...
3
by: mrajanikrishna | last post by:
Hi Friends, I am accepting a number from the user entered in a textbox. I want to assign to a variable in my code and assignt this to that variable. double num1 = (double)txtNum1.text; ...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.