Go Back  Xtreme Visual Basic Talk > Visual Basic .NET (2002/2003/2005/2008, including Express editions) > .NET General > 15 textboxes want to use 5 only ?!?!


Reply
 
Thread Tools Display Modes
  #1  
Old 03-31-2012, 06:19 AM
neo_matrix neo_matrix is offline
Freshman
 
Join Date: Mar 2009
Posts: 31
Default 15 textboxes want to use 5 only ?!?!


Hi all, does anyone know why this is not working for me?

I have 15 textboxes i want to put 5 random numbers from 1 to 48 in 5 of this textboxes.

my CODE:

Dim lstInt As New List(Of Integer)
Dim lstTB As New List(Of TextBox)
Dim rndm As New Random


For Each ctrl In Controls.OfType(Of TextBox)()
lstTB.Add(ctrl)
Next

Private Sub btdraw1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btdraw1.Click
Dim lstPicked As New List(Of Integer)

For i As Integer = 1 To 48
Dim index As Integer = rndm.Next(0, lstInt.Count)
lstPicked.Add(lstInt(index))
lstInt.RemoveAt(index)
Next





For i As Integer = 0 To 5
CType(lstTB(i), TextBox).Text = lstPicked(i).ToString
Next

AM I DOING SOMETHING WRONG THERE error message what i get is this:
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

THX IN ADVANCE FOR ANY HELP!
Reply With Quote
  #2  
Old 03-31-2012, 09:11 AM
Gruff's Avatar
Gruff Gruff is offline
Bald Mountain Survivor

Super Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA
Posts: 6,296
Default

Inside your loop 1 to 48 you are trying to grab a value from lstInt() when lstInt is empty. You can easily see this if you step through your code in debug mode.
__________________
Burn the land and boil the sea
You can't take the sky from me


~T
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->