VB.Net to C# translation

G

Guest

Hi everyone,
I’m am new to C# and trying to convert to C# from VB.Net an article I found
at 4GuysFromRolla.com:
http://aspnet.4guysfromrolla.com/articles/090104-1.aspx titled Extending the
Calendar Control’s Date Navigation by Mehmet Genc.

What I am trying to accomplish is enhance the web calendar control that
comes with Visual Studio.Net so that it has two drop-down lists, containing
the months and years. This way, a user can quickly jump to a specific month
or year with one click. The code was written in VB.Net and I am trying to
convert it to C#.

There two parts to this code I am having problem translating:

1. After populating the drop-down list with the months there is a part of
the code that updates the control with the chosen month:
VB.Net version:
'Make the current month selected item in the list
drpCalMonth.Items.FindByValue(MonthName(DateTime.Now.Month)).Selected =
True

2. I am having difficulty translating the part that populates the year
drop-down list:
VB.Net version:
For intYear = DateTime.Now.Year - 20 To DateTime.Now.Year + 20
drpCalYear.Items.Add(intYear)
Next
 
G

Guest

I've figured out part two of my question above.

//Year list can be extended
int intYear;
int intEndYear = (DateTime.Now.Year + 5);

for(intYear = DateTime.Now.Year - 5;
intYear <= intEndYear;
++intYear)
 
G

Guest

As far as I know, there's no way to get the month name in .NET, apart from
using the VisualBasic namespace.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter & VB to C++ converter
Instant J#: VB to J# converter
 
A

Alvin Bruney - ASP.NET MVP

As far as I know, there's no way to get the month name in .NET, apart from
using the VisualBasic namespace.

TextBox1.Text = DateTime.Now.ToString("MMMM,dddd - yyyy");
prints
March,Wednesday - 2006
to a text box.


--
Warm Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley 2006
Blog: http://msmvps.com/blogs/Alvin/
 
G

Guest

Yes - you can write a function to get the month name via string manipulation
of date variables (in the same way you can write methods to do all sorts of
things), but there's no .NET method which returns the month name directly.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter & VB to C++ converter
Instant J#: VB to J# converter



Alvin Bruney - ASP.NET MVP said:
As far as I know, there's no way to get the month name in .NET, apart from
using the VisualBasic namespace.

TextBox1.Text = DateTime.Now.ToString("MMMM,dddd - yyyy");
prints
March,Wednesday - 2006
to a text box.


--
Warm Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley 2006
Blog: http://msmvps.com/blogs/Alvin/
-------------------------------------------------------



David Anton said:
As far as I know, there's no way to get the month name in .NET, apart from
using the VisualBasic namespace.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter & VB to C++ converter
Instant J#: VB to J# converter
 
G

Guest

This is not very obvious, but you can so something like this:

System.Globalization.DateTimeFormatInfo dtInfo = new
System.Globalization.DateTimeFormatInfo();
DateTime now = DateTime.Now;
Console.WriteLine(dtInfo.MonthNames[now.Month - 1]);

I agree it would be nice to have something like "DateTime.Now.MonthName"

David Anton said:
Yes - you can write a function to get the month name via string manipulation
of date variables (in the same way you can write methods to do all sorts of
things), but there's no .NET method which returns the month name directly.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter & VB to C++ converter
Instant J#: VB to J# converter



Alvin Bruney - ASP.NET MVP said:
As far as I know, there's no way to get the month name in .NET, apart from
using the VisualBasic namespace.

TextBox1.Text = DateTime.Now.ToString("MMMM,dddd - yyyy");
prints
March,Wednesday - 2006
to a text box.


--
Warm Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley 2006
Blog: http://msmvps.com/blogs/Alvin/
-------------------------------------------------------



David Anton said:
As far as I know, there's no way to get the month name in .NET, apart from
using the VisualBasic namespace.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter & VB to C++ converter
Instant J#: VB to J# converter



:

Hi everyone,
I'm am new to C# and trying to convert to C# from VB.Net an article I found
at 4GuysFromRolla.com:
http://aspnet.4guysfromrolla.com/articles/090104-1.aspx titled Extending the
Calendar Control's Date Navigation by Mehmet Genc.

What I am trying to accomplish is enhance the web calendar control that
comes with Visual Studio.Net so that it has two drop-down lists, containing
the months and years. This way, a user can quickly jump to a specific month
or year with one click. The code was written in VB.Net and I am trying to
convert it to C#.

There two parts to this code I am having problem translating:

1. After populating the drop-down list with the months there is a part of
the code that updates the control with the chosen month:
VB.Net version:
'Make the current month selected item in the list
drpCalMonth.Items.FindByValue(MonthName(DateTime.Now.Month)).Selected =
True

2. I am having difficulty translating the part that populates the year
drop-down list:
VB.Net version:
For intYear = DateTime.Now.Year - 20 To DateTime.Now.Year + 20
drpCalYear.Items.Add(intYear)
Next

-------------------------------------------------------------------------- ------
Your help would greatly be appreciated. Thanks
 
G

Guest

My code should proabably be revised to:

System.Globalization.DateTimeFormatInfo dtInfo = new
System.Globalization.DateTimeFormatInfo();
DateTime now = DateTime.Now;
Console.WriteLine(dtInfo.GetMonthName(now.Month));

rmacias said:
This is not very obvious, but you can so something like this:

System.Globalization.DateTimeFormatInfo dtInfo = new
System.Globalization.DateTimeFormatInfo();
DateTime now = DateTime.Now;
Console.WriteLine(dtInfo.MonthNames[now.Month - 1]);

I agree it would be nice to have something like "DateTime.Now.MonthName"

David Anton said:
Yes - you can write a function to get the month name via string manipulation
of date variables (in the same way you can write methods to do all sorts of
things), but there's no .NET method which returns the month name directly.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter & VB to C++ converter
Instant J#: VB to J# converter



Alvin Bruney - ASP.NET MVP said:
As far as I know, there's no way to get the month name in .NET, apart from
using the VisualBasic namespace.

TextBox1.Text = DateTime.Now.ToString("MMMM,dddd - yyyy");
prints
March,Wednesday - 2006
to a text box.


--
Warm Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley 2006
Blog: http://msmvps.com/blogs/Alvin/
-------------------------------------------------------



As far as I know, there's no way to get the month name in .NET, apart from
using the VisualBasic namespace.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter & VB to C++ converter
Instant J#: VB to J# converter



:

Hi everyone,
I'm am new to C# and trying to convert to C# from VB.Net an article I
found
at 4GuysFromRolla.com:
http://aspnet.4guysfromrolla.com/articles/090104-1.aspx titled Extending
the
Calendar Control's Date Navigation by Mehmet Genc.

What I am trying to accomplish is enhance the web calendar control that
comes with Visual Studio.Net so that it has two drop-down lists,
containing
the months and years. This way, a user can quickly jump to a specific
month
or year with one click. The code was written in VB.Net and I am trying
to
convert it to C#.

There two parts to this code I am having problem translating:

1. After populating the drop-down list with the months there is a part
of
the code that updates the control with the chosen month:
VB.Net version:
'Make the current month selected item in the list

drpCalMonth.Items.FindByValue(MonthName(DateTime.Now.Month)).Selected =
True

2. I am having difficulty translating the part that populates the year
drop-down list:
VB.Net version:
For intYear = DateTime.Now.Year - 20 To DateTime.Now.Year + 20
drpCalYear.Items.Add(intYear)
Next
 
G

Guest

Even more compact:
MessageBox.Show(System.Globalization.DateTimeFormatInfo.CurrentInfo.GetMonthName(someDate.Month));

It still might be too awkward for us to incorporate into Instant C# or
Instant C++ however...
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter & VB to C++ converter
Instant J#: VB to J# converter



rmacias said:
This is not very obvious, but you can so something like this:

System.Globalization.DateTimeFormatInfo dtInfo = new
System.Globalization.DateTimeFormatInfo();
DateTime now = DateTime.Now;
Console.WriteLine(dtInfo.MonthNames[now.Month - 1]);

I agree it would be nice to have something like "DateTime.Now.MonthName"

David Anton said:
Yes - you can write a function to get the month name via string manipulation
of date variables (in the same way you can write methods to do all sorts of
things), but there's no .NET method which returns the month name directly.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter & VB to C++ converter
Instant J#: VB to J# converter



Alvin Bruney - ASP.NET MVP said:
As far as I know, there's no way to get the month name in .NET, apart from
using the VisualBasic namespace.

TextBox1.Text = DateTime.Now.ToString("MMMM,dddd - yyyy");
prints
March,Wednesday - 2006
to a text box.


--
Warm Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley 2006
Blog: http://msmvps.com/blogs/Alvin/
-------------------------------------------------------



As far as I know, there's no way to get the month name in .NET, apart from
using the VisualBasic namespace.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter & VB to C++ converter
Instant J#: VB to J# converter



:

Hi everyone,
I'm am new to C# and trying to convert to C# from VB.Net an article I
found
at 4GuysFromRolla.com:
http://aspnet.4guysfromrolla.com/articles/090104-1.aspx titled Extending
the
Calendar Control's Date Navigation by Mehmet Genc.

What I am trying to accomplish is enhance the web calendar control that
comes with Visual Studio.Net so that it has two drop-down lists,
containing
the months and years. This way, a user can quickly jump to a specific
month
or year with one click. The code was written in VB.Net and I am trying
to
convert it to C#.

There two parts to this code I am having problem translating:

1. After populating the drop-down list with the months there is a part
of
the code that updates the control with the chosen month:
VB.Net version:
'Make the current month selected item in the list

drpCalMonth.Items.FindByValue(MonthName(DateTime.Now.Month)).Selected =
True

2. I am having difficulty translating the part that populates the year
drop-down list:
VB.Net version:
For intYear = DateTime.Now.Year - 20 To DateTime.Now.Year + 20
drpCalYear.Items.Add(intYear)
Next
 
G

Guest

Thanks guys, your suggestions have been very helpful.

rmacias said:
My code should proabably be revised to:

System.Globalization.DateTimeFormatInfo dtInfo = new
System.Globalization.DateTimeFormatInfo();
DateTime now = DateTime.Now;
Console.WriteLine(dtInfo.GetMonthName(now.Month));

rmacias said:
This is not very obvious, but you can so something like this:

System.Globalization.DateTimeFormatInfo dtInfo = new
System.Globalization.DateTimeFormatInfo();
DateTime now = DateTime.Now;
Console.WriteLine(dtInfo.MonthNames[now.Month - 1]);

I agree it would be nice to have something like "DateTime.Now.MonthName"

David Anton said:
Yes - you can write a function to get the month name via string manipulation
of date variables (in the same way you can write methods to do all sorts of
things), but there's no .NET method which returns the month name directly.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter & VB to C++ converter
Instant J#: VB to J# converter



:

As far as I know, there's no way to get the month name in .NET, apart from
using the VisualBasic namespace.

TextBox1.Text = DateTime.Now.ToString("MMMM,dddd - yyyy");
prints
March,Wednesday - 2006
to a text box.


--
Warm Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley 2006
Blog: http://msmvps.com/blogs/Alvin/
-------------------------------------------------------



As far as I know, there's no way to get the month name in .NET, apart from
using the VisualBasic namespace.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter & VB to C++ converter
Instant J#: VB to J# converter



:

Hi everyone,
I'm am new to C# and trying to convert to C# from VB.Net an article I
found
at 4GuysFromRolla.com:
http://aspnet.4guysfromrolla.com/articles/090104-1.aspx titled Extending
the
Calendar Control's Date Navigation by Mehmet Genc.

What I am trying to accomplish is enhance the web calendar control that
comes with Visual Studio.Net so that it has two drop-down lists,
containing
the months and years. This way, a user can quickly jump to a specific
month
or year with one click. The code was written in VB.Net and I am trying
to
convert it to C#.

There two parts to this code I am having problem translating:

1. After populating the drop-down list with the months there is a part
of
the code that updates the control with the chosen month:
VB.Net version:
'Make the current month selected item in the list

drpCalMonth.Items.FindByValue(MonthName(DateTime.Now.Month)).Selected =
True

2. I am having difficulty translating the part that populates the year
drop-down list:
VB.Net version:
For intYear = DateTime.Now.Year - 20 To DateTime.Now.Year + 20
drpCalYear.Items.Add(intYear)
Next
 
S

shobana.shetty

that was a good one...thanks a lot ..iam using ur code in my app

My code should proabably be revised to:

System.Globalization.DateTimeFormatInfo dtInfo = new
System.Globalization.DateTimeFormatInfo();
DateTime now = DateTime.Now;
Console.WriteLine(dtInfo.GetMonthName(now.Month));

rmacias said:
This is not very obvious, but you can so something like this:

System.Globalization.DateTimeFormatInfo dtInfo = new
System.Globalization.DateTimeFormatInfo();
DateTime now = DateTime.Now;
Console.WriteLine(dtInfo.MonthNames[now.Month - 1]);

I agree it would be nice to have something like "DateTime.Now.MonthName"

David Anton said:
Yes - you can write a function to get the month name via string manipulation
of date variables (in the same way you can write methods to do all sorts of
things), but there's no .NET method which returns the month name directly.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter & VB to C++ converter
Instant J#: VB to J# converter



:

As far as I know, there's no way to get the month name in .NET, apart from
using the VisualBasic namespace.

TextBox1.Text = DateTime.Now.ToString("MMMM,dddd - yyyy");
prints
March,Wednesday - 2006
to a text box.


--
Warm Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley 2006
Blog: http://msmvps.com/blogs/Alvin/
-------------------------------------------------------



As far as I know, there's no way to get the month name in .NET, apart from
using the VisualBasic namespace.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter & VB to C++ converter
Instant J#: VB to J# converter



:

Hi everyone,
I'm am new to C# and trying to convert to C# from VB.Net an article I
found
at 4GuysFromRolla.com:
http://aspnet.4guysfromrolla.com/articles/090104-1.aspx titled Extending
the
Calendar Control's Date Navigation by Mehmet Genc.

What I am trying to accomplish is enhance the web calendar control that
comes with Visual Studio.Net so that it has two drop-down lists,
containing
the months and years. This way, a user can quickly jump to a specific
month
or year with one click. The code was written in VB.Net and I am trying
to
convert it to C#.

There two parts to this code I am having problem translating:

1. After populating the drop-down list with the months there is a part
of
the code that updates the control with the chosen month:
VB.Net version:
'Make the current month selected item in the list

drpCalMonth.Items.FindByValue(MonthName(DateTime.Now.Month)).Selected =
True

2. I am having difficulty translating the part that populates the year
drop-down list:
VB.Net version:
For intYear = DateTime.Now.Year - 20 To DateTime.Now.Year + 20
drpCalYear.Items.Add(intYear)
Next
 

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