O
Ot
I am an experienced programmer, but new to VB.NET. If you don't mind
answering a really fundamental question, it would be appreciated.
I am writing an application in which I want to have a "list" in the program
sort of like this (psuedocode)
ItemList
...NumberOfItems
...Item (number of occurrences is NumberOfItems)
.....ItemID
.....ItemAttribute1
.....ItemAttribute2
.....ItemAttribute3
...end Item
End ItemList
I want the ability to write a function that is handed the ItemID and
returns a structure that is the right occurrence of the Item. It is not
critical whether it returns a new distinct occurrence of Item, or a pointer
to the Item in the ItemList.
Also a subroutine to add to the list (but only if it isn't already there).
It feels like I am writing an "object" -- that is a class? -- that exposes
the two "methods" Add and Find. Unsure if this is actually the case. The
ItemList and data would appropriately be private to the object. I would
expect the user to be able to instantiate an instance of my "object" and
then use the subroutine and function to manipulate it.
I suppose I want a separate Type called Item. (Exactly best way to declare
so it can be used globally?) It doesn't feel VBish to declare this
globally, but nevertheless, I want the caller to be able to make use of the
description provided for an individual item. The caller needs to be able
to access all the fields.
Then I might have a separate variable called NumberOfItems which would
indicate how many. But this doesn't seem VBish. I suspect that when I
declare an array I might get a freebie. An attribute of the array that is
the count of the number of contents. I haven't seen exactly how to do that
however. I was hoping that something like ItemList.Count might
automatically be there for use locally.
My guess is that my subroutine/function would somehow use a "For each Item
in ItemList" or somesuch and then have a simple if/then in the loop to find
the right Item by matching ItemID. I can see how a simple for/next works,
but not really how a "for each" might work.
For i = 1 to NumberOfItems
If ItemToFind = ItemID(i)
Return Item(i)
endif
next i
On the other hand, perhaps there is a built-in linear search function that
I don't know about.
My frustration is the I could write this in COBOL (with a limitation on the
largest number in ItemList), FORTRAN (same limitation), IBM360 assembler
language (no limitation), as well as a number of others from FoxBase to
SAS. I am not thinking in VB yet, I need a little guidance.
TIA!
answering a really fundamental question, it would be appreciated.
I am writing an application in which I want to have a "list" in the program
sort of like this (psuedocode)
ItemList
...NumberOfItems
...Item (number of occurrences is NumberOfItems)
.....ItemID
.....ItemAttribute1
.....ItemAttribute2
.....ItemAttribute3
...end Item
End ItemList
I want the ability to write a function that is handed the ItemID and
returns a structure that is the right occurrence of the Item. It is not
critical whether it returns a new distinct occurrence of Item, or a pointer
to the Item in the ItemList.
Also a subroutine to add to the list (but only if it isn't already there).
It feels like I am writing an "object" -- that is a class? -- that exposes
the two "methods" Add and Find. Unsure if this is actually the case. The
ItemList and data would appropriately be private to the object. I would
expect the user to be able to instantiate an instance of my "object" and
then use the subroutine and function to manipulate it.
I suppose I want a separate Type called Item. (Exactly best way to declare
so it can be used globally?) It doesn't feel VBish to declare this
globally, but nevertheless, I want the caller to be able to make use of the
description provided for an individual item. The caller needs to be able
to access all the fields.
Then I might have a separate variable called NumberOfItems which would
indicate how many. But this doesn't seem VBish. I suspect that when I
declare an array I might get a freebie. An attribute of the array that is
the count of the number of contents. I haven't seen exactly how to do that
however. I was hoping that something like ItemList.Count might
automatically be there for use locally.
My guess is that my subroutine/function would somehow use a "For each Item
in ItemList" or somesuch and then have a simple if/then in the loop to find
the right Item by matching ItemID. I can see how a simple for/next works,
but not really how a "for each" might work.
For i = 1 to NumberOfItems
If ItemToFind = ItemID(i)
Return Item(i)
endif
next i
On the other hand, perhaps there is a built-in linear search function that
I don't know about.
My frustration is the I could write this in COBOL (with a limitation on the
largest number in ItemList), FORTRAN (same limitation), IBM360 assembler
language (no limitation), as well as a number of others from FoxBase to
SAS. I am not thinking in VB yet, I need a little guidance.
TIA!