|
-
Feb 27th, 2007, 05:42 PM
#1
Thread Starter
New Member
keys for visual basic collections
I am looking in Microsoft's explanations- to add an item to a collection:
workOrders.Add(woNew,woNew.ID.ToString())
which seems simple enough, except when I translate it to textboxes
First of all what does ID stand for? Is it part of vb's vocabulary or is it a variable the writer dreamed up? In my collection of textboxes below, what corresponds to woNew.ID?
Public Class Form1
Dim manytextbox as New Microsoft.Visualbasic.Collection()
Private Sub MAKETEXTBOX(BYVAL horiz as Integer, byVal vert as Integer,byval sq as integer)
dim x as string=" "
manytextbox.Add(textbox1, tostring(x))
I get a wortless message about "Overload resolution failed because of no accessible 'toString' accepts this number of arguments. I don'thave too many arguments for ToString; I have only one argument called 'x'.
statements like
textbox1.text=manytextbox.count/9
textbox1.width=sq+3
have been working fine.
It's when I want to use a key that I have the problem.
I appreciate your help.
-
Feb 27th, 2007, 06:07 PM
#2
Re: keys for visual basic collections
ToString is to convert something to string and should be preceded by a non string variable, ie and integer for example
Code:
Dim i As Integer = 10
MessageBox.Show(i.ToString())
I guess [Highlight=VB] is not working
-
Feb 27th, 2007, 06:17 PM
#3
Re: keys for visual basic collections
First of all, don't use the Microsoft.VisualBasic.Collection class. That is there for compatibility with existing VB6 code and should not be used in new code. The .NET Framework provides numerous collection classes that are all specialised for certain circumstances and will almost universally be better than the Collection class.
How about you explain exactly what you want to achieve with this collection and we can suggest the best type of collection to use? Also, please alays specify your version. .NET 2.0 offers many more options for collections with its support for generics.
As examples, if you just want a collection of TextBoxes you'd use a List(Of TextBox). If you want a collection of Strings keyed on TextBox you'd use a Dictionary(Of TextBox, String). If you want a collection of TextBoxes keyed on String then you'd use a Dictionary(Of String, TextBox) or SortedList(Of String, TextBox).
-
Feb 28th, 2007, 03:26 PM
#4
Thread Starter
New Member
Re: keys for visual basic collections
OK. I want to arrange an array of textboxes 9 x 9 let the user insert values in some of the textboxes and then let the computer figure out what the other textbox values are. Yes, I am teaching the computer how to do Sudoku.
I'm sure it has been done 100 times before. But I haven't done it. I want to identify the locations numerically- 1 in the upper left corner and 81 in the lower right. These numbers never change and are, presumably, the keys. The value textbox1.text is where the numbers go that the computer figures.
Thank you for your assistance.
I am using Visual Basic 2005 Express.
-
Feb 28th, 2007, 04:00 PM
#5
Re: keys for visual basic collections
You have a fixed number of objects that is not going to change, so for that you would just use an array, not a collection. There's no need for a key because the numerical index of each element will identify it. You can use a one-dimensional array and have indexes 0 to 80 or you can use a two-dimensional array and have indexes (0,0) to (0,8) to (8,8). I'd go with the 2D array as it more logically matches the physical layout of the controls. You can iterate over a row or column just by changing one index or the other.
-
Mar 1st, 2007, 02:44 PM
#6
Thread Starter
New Member
Re: keys for visual basic collections
Thankyou. I think that should take care of me for the time being. Someday I am going to write the Village Idiot explanation of the whole oops process and relate it to Class Form1 and Sub Main() and all the other statements which seem to be out of context with the basic oops explanation.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|