.Net Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - More.Net Development

Closed Thread
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 27th, 2009, 03:00 PM
jwebb001 jwebb001 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2009
Posts: 3 jwebb001 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 27 m 28 sec
Reputation Power: 0
Concatenate two Integers '2009/10' (VB)

Hi,

I found the some code which populates a dropdown list with current year, -4 years and + 11 years, ie. 2005 to 2020;

Sub Populate_YearList()

ddl_year.Items.Add("Include All")

'Year list can be extended
Dim intYear As Integer

For intYear = DateTime.Now.Year - 4 To DateTime.Now.Year + 11
ddl_year.Items.Add(intYear)
Next

ddl_year.Items.FindByValue(DateTime.Now.Year).Selected = True

End Sub

The rest of the code can be seen here:
aspnet.4guysfromrolla.com/demos/Cal_2.aspx

However, I would like it appear as 2005/06, 2006/07, 2007/08, etc.

When I try to add even the "/" I get 'Object not set as a reference' error or 'Input string not formatted properly'.

Any suggestions would be most appreciated.

Thanks in advance.

James.

Reply With Quote
  #2  
Old October 28th, 2009, 09:55 AM
f'lar's Avatar
f'lar f'lar is offline
ASP.Net MVP
Dev Shed Specialist (4000 - 4499 posts)
 
Join Date: Aug 2003
Location: WI
Posts: 4,245 f'lar User rank is General 6th Grade (Above 100000 Reputation Level)f'lar User rank is General 6th Grade (Above 100000 Reputation Level)f'lar User rank is General 6th Grade (Above 100000 Reputation Level)f'lar User rank is General 6th Grade (Above 100000 Reputation Level)f'lar User rank is General 6th Grade (Above 100000 Reputation Level)f'lar User rank is General 6th Grade (Above 100000 Reputation Level)f'lar User rank is General 6th Grade (Above 100000 Reputation Level)f'lar User rank is General 6th Grade (Above 100000 Reputation Level)f'lar User rank is General 6th Grade (Above 100000 Reputation Level)f'lar User rank is General 6th Grade (Above 100000 Reputation Level)f'lar User rank is General 6th Grade (Above 100000 Reputation Level)f'lar User rank is General 6th Grade (Above 100000 Reputation Level)f'lar User rank is General 6th Grade (Above 100000 Reputation Level)f'lar User rank is General 6th Grade (Above 100000 Reputation Level)f'lar User rank is General 6th Grade (Above 100000 Reputation Level)f'lar User rank is General 6th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 1 Day 10 h 32 m 45 sec
Reputation Power: 1401
Send a message via Google Talk to f'lar
The problem is your intYear variable is specifically defined and an integer, and an integer cannot have a "/" in it. But that code is old now anyway. If you're using Visual Studio 2008, I'd write it like this:

Code:
Sub Populate_YearList()
    ddl_year.DataSource = Enumerable.Range(DateTime.Now.Year - 4, 15).Select(Function(i) String.Format("{0}/{1:N2}", i, i-1999) )
    ddl_year.DataBind()

    ddl_year.Items.FindByValue(DateTime.Now.Year).Selected = True
End Sub
__________________
Primary Forum: .Net Development
Holy cow, I'm now an ASP.Net MVP!

[Moving to ASP.Net] | [.Net Dos and Don't for VB6 Programmers]

http://twitter.com/jcoehoorn

Last edited by f'lar : October 29th, 2009 at 09:08 AM.

Reply With Quote
  #3  
Old October 28th, 2009, 01:30 PM
jwebb001 jwebb001 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2009
Posts: 3 jwebb001 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 27 m 28 sec
Reputation Power: 0
OK cool. Many thanks for that....

Unfortunately we have VS2003 at work. Tried it today and it didn't like Enumerable.Range and Function.

Sub Populate_YearList()
ddl_year.DataSource = Enumerable.Range(DateTime.Now.Year - 4, 15).Select(Function(i) String.Format("{0}/{1}", i, i-1999) )
ddl_year.DataBind()

ddl_year.Items.FindByValue(DateTime.Now.Year).Selected = True
End Sub

If anyway can translate to 1.1 that would be great.

Thanks.

Reply With Quote
  #4  
Old October 29th, 2009, 09:13 AM
f'lar's Avatar
f'lar f'lar is offline
ASP.Net MVP
Dev Shed Specialist (4000 - 4499 posts)
 
Join Date: Aug 2003
Location: WI
Posts: 4,245 f'lar User rank is General 6th Grade (Above 100000 Reputation Level)f'lar User rank is General 6th Grade (Above 100000 Reputation Level)f'lar User rank is General 6th Grade (Above 100000 Reputation Level)f'lar User rank is General 6th Grade (Above 100000 Reputation Level)f'lar User rank is General 6th Grade (Above 100000 Reputation Level)f'lar User rank is General 6th Grade (Above 100000 Reputation Level)f'lar User rank is General 6th Grade (Above 100000 Reputation Level)f'lar User rank is General 6th Grade (Above 100000 Reputation Level)f'lar User rank is General 6th Grade (Above 100000 Reputation Level)f'lar User rank is General 6th Grade (Above 100000 Reputation Level)f'lar User rank is General 6th Grade (Above 100000 Reputation Level)f'lar User rank is General 6th Grade (Above 100000 Reputation Level)f'lar User rank is General 6th Grade (Above 100000 Reputation Level)f'lar User rank is General 6th Grade (Above 100000 Reputation Level)f'lar User rank is General 6th Grade (Above 100000 Reputation Level)f'lar User rank is General 6th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 1 Day 10 h 32 m 45 sec
Reputation Power: 1401
Send a message via Google Talk to f'lar
1.1? Ugh. I'd want need to at least move up to 2005, which has iterator blocks and proper generics support.

That said, here you go:
Code:
Sub Populate_YearList()

    ddl_year.Items.Add("Include All")

    'Year list can be extended
    Dim Year As Integer = DateTime.Now.Year - 4
    For i As Integer = 0 To 15
        ddl_year.Items.Add( String.Format("{0}/{1:n2}", Year, Year - 1999) )
        Year += 1
    Next i

    ddl_year.Items(4).Selected = True 
End Sub

Not sure I got the "n2" format right, but you can look that up. Just search msdn for string.format.

Last edited by f'lar : October 29th, 2009 at 09:16 AM.

Reply With Quote
  #5  
Old November 6th, 2009, 12:51 PM
jwebb001 jwebb001 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2009
Posts: 3 jwebb001 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 27 m 28 sec
Reputation Power: 0
Thumbs up

Thanks f'lar. Sorry I haven't replied sooner. I will give it a try.
I appreciate you taking time out to help.

Best regards.

Jwebb001.

Quote:
Originally Posted by f'lar
1.1? Ugh. I'd want need to at least move up to 2005, which has iterator blocks and proper generics support.

That said, here you go:
Code:
Sub Populate_YearList()

    ddl_year.Items.Add("Include All")

    'Year list can be extended
    Dim Year As Integer = DateTime.Now.Year - 4
    For i As Integer = 0 To 15
        ddl_year.Items.Add( String.Format("{0}/{1:n2}", Year, Year - 1999) )
        Year += 1
    Next i

    ddl_year.Items(4).Selected = True 
End Sub

Not sure I got the "n2" format right, but you can look that up. Just search msdn for string.format.

Reply With Quote
Closed Thread

Viewing: Dev Shed ForumsProgramming Languages - More.Net Development > Concatenate two Integers '2009/10' (VB)


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek