Results 1 to 6 of 6

Thread: keys for visual basic collections

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2007
    Posts
    5

    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.

  2. #2
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    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
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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).
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    New Member
    Join Date
    Feb 2007
    Posts
    5

    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.

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    New Member
    Join Date
    Feb 2007
    Posts
    5

    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
  •  



Click Here to Expand Forum to Full Width