Use IList(Of IList(Of String) - Pass It As A Parameter To Another Method?

Aug 2, 2011

I'm trying to use a variable that is simply a list of a list of strings.I've declared it as follows:

Dim iRows As New List(Of List(Of String))

Then I'm trying to pass it as a parameter to another method and I've defined the method as follows:

Public Sub Import(ByVal Rows As IList(Of IList(Of String)))
For Each Row As IList(Of String) In Rows
ImportRow(Row)[code]....

Unfortunately, when I try to run that code I get the following error where it tries to pass my variable to my method.

System.InvalidCastException was unhandled by user code
Message="Unable to cast object of type 'System.Collections.Generic.List1[System.Collections.Generic.List1[System.String]]' to type 'System.Collections.Generic.IList1[System.Collections.Generic.IList1[System.String]]'."

When I change the method definition to use the types rather than the interfaces as follows, it works.

Public Sub Import(ByVal Rows As List(Of List(Of String)))
For Each Row As IList(Of String) In Rows
ImportRow(Row)[code]....

So, is it not possible to use generics with interfaces in this way? It works fine as long as I'm not nesting them.

View 3 Replies


ADVERTISEMENT

Use The IList(Of T).Max Function?

Jul 8, 2011

How do I use the IList(Of T).Max function in my example below?

Dim myList as IList(Of Integer)
For x = 1 to 10
myList.add(x)
Next

'Error: 'Max' is not a member of 'System.Collections.Generic.IList(Of Integer)'
MsgBox(myList.Max())

View 2 Replies

Expose ILIst Members To 6.0 Through COM

Nov 23, 2010

i have to develop API in .Net 4.0 which can be used in VB 6.0,i know how to use this and currently i am using my this API in VB successfully.but Stuck at one place,i have collection class and i have to expose it to VB with having functionality of List class of .Net.[code]i know that generic is not supported in VB, but i think with this declaration in VB 6.0 it creates interface class for class B as IList.but in VB using object creation of class B it doesn't provides me members of LIST in intellesense like (Add,Remove of List Class)

View 2 Replies

C# - Pass An Integer As A String Parameter To A Method Without Calling .ToString()?

Mar 12, 2010

In VB.NET, it is entirely possible to pass an integer as a string parameter to a method without calling .ToString() - it's even possible to call .ToString without the ()'s. The code will run without a problem, VB will interpret the integer as a string without having been told to. In C#, these would cause compilation errors - you are required to call .ToString() and to call it correctly in that situation before it will compile. Is there a way to make the VB compilation process check for the same things as the C# compilation process? Would it be best practice in a mixed team to force this check?

View 3 Replies

.net - Add Items From ObjectCollection To An IList(Of SomeType)?

Nov 12, 2010

How could I add ObjectCollection items to an IList(Of SomeType)?I have tried with:

For Each obj As SomeType In listBox.Items 'ObjectCollection MyObject.ItProperty.Add(obj) 'IList Next

View 2 Replies

Implementing IList (Of T) In Generic Class

Jun 26, 2009

I am creating a generic class that is Implementing IList(Of T) which requires that I implement the GetEnumorator of both IEnumerable(Of T) and IEnumerable. When looking at the members of IList(Of T) I see only one GetEnumorator function, yet it implements IEnumerable(Of T) and IEnumerable. How can I use one function to implement both interfaces when the function definitions only vary by return type?

View 8 Replies

Possible To Add Multiple Strings Per Item In A Ilist?

Mar 17, 2012

is it possible to add multiple strings per item in a Ilist?If so can someone point me in the right direction? I've looked on the msdn and can only find examples on how to add one string per item

View 16 Replies

Step Through An IList One Field At A Time?

Feb 8, 2011

I'm using the Dynamic LINQ library code sample to dynamically return some data. The number of columns I'm returning is variable depending on user input. I'm enumerating the IQueryable into an IList. What I need to do is step through the Ilist one field at a time. I can get one row at a time by iterating through the IList's rows but I can't for the life of me pull one field out of the collection.For example, here I'm returning two columns (hard coded for testing but in prod it will be variable depending on what fields the user chooses):

Dim Dynq = dc.dt _
.Where("RUN_ID = """ & runNumber & """ and Upper_Pressure > 95") _
.OrderBy("Upper_Pressure") _

[code]....

Now I can pull a field out of the Ilist if I know the column name with something like:

something.Run_ID.ToString

but I wont know the columns I'm using until runtime and dynamically inserting it in a variable that's set at runtime doesn't work.So in Summary I have a Ilist that looks something like this

1 | Auto
2 | Auto
3 | Manual
4 | Manual

and I'd like a way to return

1
and then return
Auto
and then
2
etc...

View 1 Replies

Casting From Generic IList To Object During DataBind?

Feb 18, 2010

Okay, so I have a Generic IList of custom objects that I want to use as a datasource for a repeater.

Dim productRows As IList(Of MyCustomObject)()
'fill list with data
rptResults.DataSource = productRows

[code]......

View 1 Replies

Get Values From A IList(Of T) And Output To A Listbox'Dim J As Integer?

May 28, 2012

i am having trouble displaying the values i get from an IList(Of T) and displaying that in a listbox found on another form. I have used a for loop to get the values from the IList, then i can display that in a msgbox. for eg:

Dim j As Integer
Dim path As String = ""
For j = 0 To best_tour.Count - 1

[code]....

best_tour is ot type IList() path keeps the name found in the list everything works fine inside the loop..but it does not populate the lst_output listbox.I have tried using files, but in vain. It just get the values from the list but does not display that on the listbox.If that can help, then listbox is found in a panel on the form2, but taking it out of the panel does not affect anything.

View 7 Replies

VS 2005 Get Item Type For A Given Generic.IList

Mar 25, 2009

I have a piece of code that does an action to any collection that implements generic.IList<T>However to do this it needs to get the type <T> of the generic list.e.g. If I pass in a variable of type Generic.List(Form) then in my code I need to get the fact that the list is made of Forms. To add complexity the list may be empty (So you can't just look at Item(0).GetType)

View 6 Replies

.net - Does Not Throw Compiler Error When Setting Dictionary To IList

Jul 6, 2011

I am updating a legacy application, and it was reading a dll from another project for a Dictionary(of Guid, String) of items and using them.

The requirements have changed, and the method that was returning the Dictionary is now returning an IList.

This is the odd behavior of this; the intellisense is not throwing a cast error, nor is the compiler. It does not throw an error until runtime when it tries to set the Dictionary to the IList.

Example:

Dim someDictionary As Dictionary(Of Integer, String) = New Dictionary(Of Integer, String)
Dim someList As IList(Of Integer)
someDictionary = someList

why the compiler is not catching this?

View 1 Replies

How To Implement Find On IList And Update Object Properties

Dec 7, 2010

I am declaring an IList:
Dim OrigVendors as IList
OrigVendors = new List( of IVendors)
I populate the OrigVendors variable and what I want to do is find all the objects that have the ID I am looking for. Then I need to update a property on that object for only the ones found. Is this do able with an IList or do I need to use some other type of collection? I am using VB.net.

View 1 Replies

List To IList Polymorphism Attempt Results In InvalidCastException?

Jan 29, 2010

In a program I am writing (in VB.NET, 2008), I have 2 classes, "Receipt" and "Group", each with similar properties, both implementing a custom interface entitled "IIDUser". In my program, I have a number of lists of "Receipt" and "Group", declared like:Friend receipts as List(Of Receipt)

I have written a few functions that apply equally to managing both lists of receipts and groups, declared like this one:Friend Function getNextAvailableUserLabel(ByRef theList As IList(Of IIDUser), ByVal startLabel As Short) As Short

Then called like this:getNextAvailableUserLabel(receipts, s)

I did all this in an attempt for interface-based polymorphism, as I thought writing 2 identical functions (except for that one would be for lists of receipts while the other for lists of groups) would be bad practice (and waste time). However, I get an "InvalidCastException" during runtime. It is explained, "Unable to cast object of type 'System.Collections.Generic.List`1[Receipt_Sorter_v2.Receipt]' to

[Code]...

View 4 Replies

Unable To Cast From List(of Object) To IList(of Interface)?

Apr 19, 2011

I'm new to generics and am having some issues when using with interfaces.I'm developing with VS2008 - .NET 3.5 Ultimately, I'd like to create an interface that inherits the IList(Of T) interface and add a function definition to the derived interface that adds a new element of type T to the list and returns the index of the newly added item.

I have everything figured out but am stuck on a casting issue. If I execute the following line of code at runtime:CType(New clsObjectFactoryList(Of clsIDNamePair), ifObjectFactoryList(Of ifIDNamePair))

View 9 Replies

Consolidating And Filtering IList Items, Looking For Paterns, Practices, Or Existing Methods?

Sep 11, 2010

I'm reading a binary file into a bindinglist of (t); to be bound to a datagridview.Each line in the file represents a single transaction but I need to consolidate and or filter transactions that meet certain criteriaI know how to do this from a mechanical standpoint (looping the list while adding each item, and adding a new item, or merging the data with an existing item), but I'm looking for a practice, pattern, existing components, or something else that I'm missing (I'm drawing a blank for keywords to search).I don't want to reinvent the wheel if I don't have too. I'm particularly concerned with speed and performance issues with 100k plus records to process in some instances.Currently working with .NET 2.0, but will move to 3.5 if a particularly sexy solution exists.

View 2 Replies

Pass A Method Like A Parameter Of Another Method

Feb 4, 2011

Is there a way to choose between different methods and pass one into another method ?

Sub conditionnal_binding(ByVal list_box_reference As ListBox, ByVal list_box_final As ListBox, _
ByVal dico_source As Dictionary(Of String, List(Of String)), _
ByVal my_methode As ??? )
' DO SOMETHING
End Sub

I wrote ??? because I don't know how to call another method inside a method.
I would like to choose between different "sub-methods". Here is how I would like to use my method :

conditionnal_binding(ListBox1, ListBox3, HTML.dico_basic_attribut, best_method)
conditionnal_binding(ListBox1, ListBox3, HTML.dico_basic_attribut, some_method)
conditionnal_binding(ListBox1, ListBox3, HTML.dico_basic_attribut, another_method)

View 5 Replies

Pass An Object As A Parameter To A Fortran Method?

Aug 25, 2010

I'm currently working on being able to import a DLL written in Fortran into Visual Basic. I've got all the basics down, so now I'm trying to take it a step further. The title basically says it all, but I'll explain what it is I'm trying to do anyways.

For kicks and giggles, let's just assume I want to pass an object that has three double values in it, possibly representing a point in space in three dimensions. In my Fortran method, I want to take that object, print out the x value, then change the x value to 7.5. Here's my Fortran code that does just that.[code]...

View 2 Replies

Pass Null Parameter Fill Method Of Tableadapter?

Jan 17, 2012

I have already defined in my SELECT statement in TableAdapter to tell it what to do if the parameters are Null:

SELECT a.ID, a.NameID, b.BNameID
FROM a INNER JOIN b
ON a.ID = b.ID
WHERE ((@NameID IS NULL) OR (a.NameID = @NameID))
AND ((@BNameID IS NULL) OR (b.BNameID = @BNameID))

View 4 Replies

Reference To The String In The Heap Is Passed Even When You Pass The String ByVal To A Method?

Mar 2, 2011

So strings are reference types right? My understanding is a reference to the string in the heap is passed even when you pass the string ByVal to a method.

String myTestValue = "NotModified";
TestMethod(myTestValue);
System.Diagnostics.Debug.Write(myTestValue); /* myTestValue = "NotModified" WTF? *[code].....

And what is going on under the hood? I would have bet my life that the value would have changed....

View 5 Replies

Optional Method Parameter And String.Empty?

Apr 19, 2012

I have traditionally coded empty strings like this "", but for a couple of years now, I have been using String.Empty.I also normally never use optional parameters, but I'm refactoring a solution that's tied into my ERP, and I don't want to break anything. One of the changes was to add a parameter to proc, which pushes a new parameter into the method from which it is called. I coded it like this:

Optional BackReferenceID As String = String.Empty

But I got a syntax error "Constant expression is required." I guess String.Empty is non-deterministic??? Anyway, it seems like a bug. The workaround is of course to use double quotes.

View 1 Replies

Convert String Value To Type And Pass As Type Parameter.

Nov 19, 2010

i am getting all filenames from a directory.parsing out the directory names & the .vb extension then converting those filesnames to classes.Every file in the LPCriteria direcotry is its own class with a "Evaluate" function.[code]

View 1 Replies

AddressOf With Parameter - Method Which Requires A Parameter To Be Passed In

Mar 1, 2009

I have a method which requires a parameter to be passed in. I would like to use the Addhandler to call the method through a dynamically created button control's click event.

When I include () in the AddressOf, VS complains: 'AddressOf' operand must be the name of a method (without parentheses).

When I exclude the brackets, VS complains: Method '...' does not have a signature compatible with delegate...

My code:

CODE:

View 5 Replies

Populate A List(Of Object) In A Class Method, Where The List Was Passed To The Method As A Parameter

Aug 13, 2011

I'm trying to code a class of RandomNumber. One of the class methods needs to populate a "List (Of RandomNumber)" ... which was passed as a parameter to the method ... with 10 random numbers between 1 and 50. DEAD SIMPLE :)

View 6 Replies

How To Pass Parameter For Function

Dec 9, 2009

I have a statement:
dat.XoaNhanVien(Me.dtgcapnhatthongtin.CurrentRow.Cells(1).Value, message)
That is a function for deleting info. Now I want to create other function and get above function to parameter. I mean:
Public Function func(Byval func as " What type can be ?")

View 13 Replies

How To Pass Parameter To EXE File

Oct 7, 2010

I am currently still learning to use VB.Net feature. Currently I am trying to execute a .exe file where there will be passing parameters to run the script. E.g. this how it works on the command prompt line:
C:Documents and Settingsproject1>textfile.exe file1.txt file2.txt file3.txt file4.txt
Above line will be able to run the textfile.exe script.

I am using VB .Net to create a User Interface where user will be able to use the 'OPEN CLICK' button to choose the files (which will display on a textbox) and click on a 'START' button to run the program. I managed to find a code - process.start() feature, however it cant seem to work..

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim MyProg As String
Dim executable As String
executable = "C:Documents and Settingsproject1 extfile.exe"
MyProg = TextBox1.Text
Process.Start(x, MyProg)

View 4 Replies

Object Must Pass Itself As A Parameter?

Sep 10, 2011

I have various shape objects, and I want each unique shape to implement a saveToDB method that simply calls a DB object that implements a Save method with an object as its input paramter. This DB.Save method will be a long case function that implements the proper SQL commands based on the type of attributes possessed by the input parameter object.how do I implement the SaveToDB method in my Shape class? Is it something like this:

Function Shape.SaveToDB
DB.Save(Me)
End Function

The goal here is to let each shape save itself without it knowing anything about database operations; I want to isolate db-specific information in my intermediary DB object, so the DB object will have to figure out what type of object wants to be saved into the SQL database and then execute whatever SQL instructions are needed. And then if I override the SaveToDB method in each shape subclass, I can avoid the case statement entirely, replacing it with a series of unique methods such as db.SaveCircle (ob), db.SaveSquare (ob), etc., sincle the caller already knows what it is.

View 4 Replies

Pass A DataRow As A Parameter To A Sub?

Apr 22, 2010

Is it possible to pass a DataRow as a parameter to a sub?The following example will (hopefully) make clear what I want to do.

Code:
myDataAdapter.Fill(myDataSet)
For Each myDataRow In myDataSet.Tables.Item(0).Rows
MySub(myDataRow)
Next

And the sub:

Code:
Private Sub MySub(ByVal drData As DataRow)
End Sub

I get an error at design time: Error 2 Expression does not produce a value.

View 3 Replies

Pass A Field As A Parameter

Jan 27, 2010

I have the following function:[code]I need to know if it's possible for a function to take a parameter as a type of field?

View 3 Replies

Pass A Parameter To A Query?

Feb 26, 2009

I am trying to load a combo box based on a selection of data from another combo box. I am not sure how I would pass the value to the object. My thought is I am loading all the table data onto my object and then I would run the query on the object. However I am at loss as to how I would go about doing that.

Private Sub cboOrder_SelectedIndexChanged(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles cboOrder.SelectedIndexChanged
Dim selecteditem As String

[Code]....

View 4 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved