VS 2008 - Are Arrays Considered A Type Of Collection Like Lists
Mar 2, 2010
Ever since I started using VB.Net I have been using the Generic List collection List(Of <Type>). Arrays, I haven't used so much. I used them a lot more when I wrote C code years ago.
1.) Are arrays considered a type of collection like Lists, Dictionary, Queue etc are? Or are they in their own category.
2.) Can I iterate over an array with a For Each loop like I can with other collections or do I stick with the normal For loop for arrays?
3.) There are certain methods that return arrays. Can I set a list object to hold this return value instead of an array?
View 6 Replies
ADVERTISEMENT
Jun 24, 2011
I have been assigned a program for homework in which I need to take in information about songs from a text file and then be able to sort the list alphabetically, by genre and by length. I also need to be able to filter it by genre. The user can then move songs they choose from the master list to a playlist where again the list can be sorted by either genre or play order.My book only covered sorting array when they are one dimensional however I need to be able to sort a multidimensional array by different columns. I asked my teacher but she had so much going on that we didn't really have time to get into it, so I decided to ask here.
I'm not looking for code, just to get pointed in the right direction. For instance rather than using a multidimensional array would it be better to pull the values in and then put them into an array of song objects with properties for each value? And if I choose to go that route is an array the best structure to use? I have to use an array of some type, but the problem says nothing about whether or not it can be a list or other array type structure.
View 6 Replies
May 2, 2012
I declare my 2D lists:
Dim _invoiceitems As New List(Of List(Of String))
Dim _dbitems As New List(Of List(Of String))
Each List is filled like this: Example Code To fill:
_invoiceitems.Add(New List(Of String))
_invoiceitems(0).Add("Code #")
_invoiceitems(0).Add("Quantity")
Well, now i need a third list called (_changesitems) Note that this result with the differences: be the result of subtraction of quantities if this is found (dbitems - invoiceitems).
View 1 Replies
Jun 13, 2010
I've had experience with using hashvalues from String objects. E.g., if I have StringA and StringB both equal to "foo", they'll both compute out the same hashvalue, because they're set to equal values. Now what if I have a List, with T being a native data type. If I tried to compute the hashvalue of ListA and ListB, assuming that they'd both be the same size and contain the same information, wouldn't they have equal hashvalues as well?
Assuming as sample dataset of 'byte' with a length of 5
{5,2,0,1,3}
View 3 Replies
Nov 11, 2011
I have a pipe delimited file with 3 values on each line, something like this:
0001|234587|Bracket, 3 x 3 x 0.125, Steel
0001|254378|Bracket, 4 x 4 x 0.125, Steel
0003|234587|Hinge, 4 x 4 x 0.125, Brass
The first Value can be duplicated in the file, the second value also can be duplicated. There are no instances of BOTH values duplicated on 2 or more lines. I need to read another file and get the first 2 values, then look up those two on one line to get the proper 3rd value. The "other" file looks a bit like this:
0E0522070001EF54ED7823458700FF00FFA5A5A5A5
-----------XXXX-----------XXXXXX--------------------- (X's are the data, the rest is filler to comply with some code unknown to me)
Right now I have code to read all into an array (split on vbcrlf), then split each line on "|" and populate three arrays, I then go thru every element of the first column that matches the value I am looking for and test that the second column also matches the second value and if so, return the third array contents at the same index. This seems crude and inefficient. Cannot use a hashtable (I don't think) as it only supports 2 values. A List(Of) doesn't seem to work either and I don't want to use a database.
View 6 Replies
Dec 23, 2011
Find common values in multiple arrays with PHP Pretty much does what I need, but in PHP, I need VB. My situation is I am trying to create an intelligent stock pick system based on multiple stock locations. At the point of invoicing, we loop through the items invoiced and check the stock database for available stock.
If all items on the invoice are available to pick from stock location 1, then all should be picked from stock location 1... etc. If all most items are available from stock location 1 except one or two, then pick all stock from stock location 1 except for the exceptions which should be picked from the location with the highest available stock. Finding highest available stock is simple, but I can't work out how to analyse the stock availability from multiple locations and finding the common stock locations.
[Code]...
View 2 Replies
Mar 17, 2010
I was wondering how you create a form with three lists. Each list representing a different array.
I guess the question is how do you take an array and make it into a list so it shows up on a list box?
View 2 Replies
Dec 15, 2011
my binary search isnt working, i think it has to do with the fact that im using a list and its searching thru an array
List
Option Strict On
Public Class Form1
[Code].....
View 9 Replies
Jun 21, 2010
I'm performing some statistics on a txt file that has multiple columns using a collection list (vb.net 2008). My files can contain 100,000+ samples per file. How would I code my function to have it perform work on the first 3000 samples and continue the calculations on every 3000 samples thereafter?
Private Sub decimationButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles decimationButton.Click
Dim lines() As String = System.IO.File.ReadAllLines(inputFileName) '("TEXT_FILE")
Dim list As New List(Of Double())
[code]....
View 1 Replies
Jun 27, 2011
Basically what I'm having to do is create a program that takes a list of CaseIDs and compares them to a table on a remote SQL server. However, the table holding the CaseIDs on the remote server has nearly 120,000 records.
Currently my plan is to query all records on the remote server, save the query and the current list to tables in an Access DB file and then run an outer join to see which CaseIDs have no matching records on the remote server.
I believe this will be a much slower process than I would like. If I could load both queries into arrays or lists in VB and then compare them (therefore, not having to write 120,000 records to a DB file), it would be much faster.
View 10 Replies
Dec 30, 2009
I am trying to export a dataset to a csv file
VB
Private Sub ExportDatasetToCsv(ByVal MyDataSet As DataSet)
Dim str As New StringBuilder
For Each dr As DataRow In MyDataSet
[code]....
I am getting an error on this line: For Each dr As DataRow In MyDataSet The error is Expression is of type 'System.Data.DataSet', which is not a collection type.
View 3 Replies
Jun 27, 2012
I'd like to give a homework assignment to a person learning VB.NET. I'd like it to use basic inheritance and a variety of data structures including queues, lists, arrays, or stacks in a windows forms application. I was thinking of a pizza-ordering application. This would allow them to utilize some basic inheritance and practice using .NET UI elements.
View 2 Replies
Sep 10, 2009
Dim A As Collection
Set A = New Collection
Dim Arr2(15, 5)
[Code].....
How can I access the Arr2 through A? For example, I want to do the following:
A.Item(1) (1,1) = 15
so the above would change the first element of the first two-dimensional array inside the collection...
View 4 Replies
Aug 11, 2009
I have some code like this:
Dim col As Collection = New Collection
col.Add(value1, "key1")
col.Add(value2, "key2")
' later...
For Each item As String In col
' want to get valueX and keyX here; currently, "item" holds the value
Next
How can I get both the value and key within the loop? Maybe there is another class that makes this easier?
View 1 Replies
Sep 14, 2009
I have recently moved from VB 2003 to VB 2005. While I am finding a lot of the new features quite useful, I am having trouble with List (of T). I want to be able to do something like this
Function GetList(MyObjectType as Type) as datatable
Dim list as new List(of MyObjectType)
End Function
Function GetList(MyObjectType as String) as datatable
Dim list as new List(of GetType(MyObjectType))
End Function
VB 2005 does not allow me to do this at all. Must the "type of" be srongly declared at all times? Can't this be done dynamically?
View 2 Replies
Oct 30, 2010
the statement Dim state(49) As String and maintain a list of certain states. The list of states should always be in alphabetical order and occupy consecutive elements of the array. The buttons in the program should give the user the following options: (a) Take the state specified by the user in a text box and insert it into its proper position in the array. If the state is already in the array, so report. (b) Take the state specified by the user in a text box and delete it from the array. If the state is not in the array, so report. (c) Display the states in the array. "
Private Sub states_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
state(0) = "Alabama"
[code]....
View 1 Replies
Dec 16, 2011
I am trying to make it so when I use Me.Controls("Timer1") for example I can access specific commands for a timer such as Stop() Start(), I tried CType() and typed in "Timer" as the type but it says the control type can't be converted to the "Timer" type.
View 11 Replies
Jun 16, 2009
I am very close to cracking a problem I've had in visual basic 2008 that i am running out of visual studio 2008. I would like to generate a graph on a form using MSChart. I have got the first bit sorted out ie i can get a graph to show on a form using the following code (I've only put the first tranche in for the purpose of this question:[code] I can't get the array or string to be compatible with the one dimensional, comma-delimited array that I need to populate the y-axis values of the chart.
View 9 Replies
May 16, 2012
GetDocumentType() works fine but adding into the collection cause error, it is not adding anything into it.
Imports System
Imports System.Collections.Generic
Imports System.Collections
Imports System.Collections.ObjectModel
[Code] .....
View 3 Replies
Jun 7, 2011
During the design of a new application I was wondering if using a module with properties is considered to be a bad practice. Some example code:
Module modSettings
public property Setting1 as string
public property DatabaseObject as IDatabaseObject
End Module
The code above is just an example to emphasize my question. In the past, this structure was used a lot in VB6. In the past I used it as well in my .NET projects.
But nowadays with buzzwords like Dependency Injection, Testability and Separation of Concerns the above structure smells bad. I can't really describe why, but it just feels wrong. I must admit I'm not very familiar with the keywords above, yet.So I'm wondering whether the above code really is a bad practice. If so, what would you use a Module for?
View 4 Replies
Mar 16, 2011
VB.NET has classes and Modules, so my first question is what is the difference? Also, I noticed that C# does not have modules, but just classes, is there something in place of modules or were they removed for C#?
View 1 Replies
Apr 1, 2011
I have two lists. One list is a list of names, the other list is a list of how many times each name is found in the first list noted in the database
so...
Nick
John
Jim
Jack
is the firs tlist
10
13
13
2
is the second list. Nick had 10, john 13 and so on.I want to sort the second list from large to small, but have the index for the first list still linked to the correct amount of calls.i do it this way so I can
for x = 0 to num_of_names
string = lst_name(x) & "-" & lst_count(x)
next x
View 3 Replies
Oct 28, 2009
I can't figure out how to determine the type of an object in a collection. I want to do a For Each ... Next loop over the items in the DropDownItems collection of a ToolStripMenuItem. For those items that are ToolStripMenuItems themselves I want to take some kind of action. (The collection can contain other types of items, such as ToolStripSeparators). So I need to say something like: If Typeof(item) = ToolStripMenuItem Then .
View 1 Replies
Jul 8, 2010
I have recently started .NET programming, and looked at both VB.NET and C#. In VB.NET, a strongly typed Datatable cosisted of a collection of strongly types rows. Therefore, for example, this statement would work:
lCustomerTable As CustomerDataSet.CustomerTable
lCustomerRow as CustomerDataSet.CustomerTable.CustomerRow
lCustomerTable = TableAdapter.GetData
lCustomerRow = lCustomerTable.Rows(0)
However in C#, it seems i have to explicitly cast the returned Row to a CustomerRow:
lCustomerRow = (CustomerDataSet.CustomerTable.CustomerRow)lCustomerTable.Rows[0]
Should the dataset not create the object type definitions when creating the table adapters and SQL dataTables?
View 2 Replies
Jun 22, 2011
I'm OK with both C# and VB.NET..I have a function GetListOfBook, that returns LINQ to SQL result that has a collection of objects like the following:[code]
View 4 Replies
Nov 10, 2011
I am using VB .NET 1.1 and wanted to make sure if inside a key value pair class "Dates" (collection type) a key by name "TerminationDate" exists.
If Not Dates.Item("TerminationDate") Is Nothing Then
'Do x y z'
End if
But this is throwing an exception: Argument Index is not a valid value.
View 2 Replies
Mar 1, 2011
In many projects I work on, whenever I have to return a read only collection, I use the IEnumerable<T> interface and make it type specific like so:
CODE:
Most of the time, I return a List but in some functions and read only properties I return an array which also serves the purpose alright by kind courtesy of Extension Methods.
My question is am I violating any design principles by returning IEnumerable<T>s instead of specific types (e.g.: List<T>, HashSet<T>, Stack<T> or Arrays)?
View 8 Replies
Oct 18, 2010
You need to test for the backspace character, and if it's there, fix up the input.Maybe something like this:
If Right$(TxtQP.Text, 1) = vbBs Then
TxtQP = Left$(TxtQP, len(TxtQP)-1)
End If
Or is the backspace not showing up in the string, but as the input character kicking off your procedure?
View 1 Replies
Oct 10, 2010
I use to use Structures quite a lot in the VB6 days, and try to avoid them now with .NET. Just wondering if using structures in 2010 instead of a Class is considered nasty?
View 6 Replies
Feb 15, 2012
which one cannot be considered as a counter variable?
counter = counter +1
counter = counter -1
counter = counter +3
counter = counter *2
View 10 Replies