.net List(of T) Not Returning Indexed Object?

Sep 30, 2011

I'm working on a small game that is based on a map of grid squares.I have a class (clsGrid) that stores a few properties for each grid square.The grid square objects are organized into a list(of clsGrid).A loop and stream reader are successfully reading properties from a text file, putting the properties into grid objects, and adding the grid objects to a my list of grids. When retrieving a grid from the list of grids, I'm getting unusual results. Regardless of the index I give the list, I always seem to get the last indexed grid in the list.The debugger seems to suggest that the right numbers are being read into the stream reader and they are being added to gridHolder. However, the message box at the end will always show me the LAST grid.id, regardless of the index I give it.

'A subroutine that generates a map (list of grids)
Sub GenerateMap()
Dim reader As StreamReader = File.OpenText("map1.txt")[code]....

View 1 Replies


ADVERTISEMENT

List Of Integers Indexed By Key Or Index?

Jul 25, 2010

I would like to create a list of integers. The list will be items that I need to index by a key (string) or an index, which I set. For example I have items 1, 2, and 5. I would like to call Array(5) = 1. Where the the 5 is indexing a particular item 5, not the 5th item in the array. Using Array("5") = 1 could work as well. I tried using a List, but the only index is the ordered element of the list. I tried a Collection, but I kept getting errors that the items of the Collection are read only. How can I do this?

To be more specific, I have a simple game application which has a Player class. Each Player is trying to collect hits of say 3 fields {1,2,5}. I need to store how many times a player hits each of the 3 fields. So, I would like to read and write using logic like player(1).field(5) = 5. I want to add an object to the Player class which stores the number of times each of the 3 fields has been hit.

View 3 Replies

.net - Returning A List Using Entity Framework, 'System.Collections.Generic.List Cannot Be Converted To '1-dimensional Array

May 3, 2012

i have issue returning a list in a web method. here is the code

<WebMethod()> _
Public Function getTags(para_parents As String) As List(Of getTypeDetailsByParentName_Result)()
Dim context As New PPEntities

[code]....

the error is

Value of type 'System.Collections.Generic.List(Of SaftyonRoad.getTypeDetailsByParentName_Result)' cannot be converted to '1-dimensional array of System.Collections.Generic.List(Of SaftyonRoad.getTypeDetailsByParentName_Result)'

View 1 Replies

VS 2010 Return Items In A List Before Returning The List?

May 23, 2012

That was probably bad title, but I'll illustrate what I'm trying to do. I have a method in a class that I need to call several times. The method returns a List(Of String). I'm just grabbing some information from a database.

VB.NET
Public Function GetTestList() As List(Of String)
Dim int As Integer = 0

[code]....

View 4 Replies

Searching A List Box And Returning Matches To Another List Box?

Feb 24, 2011

I have a school project i am working on wich i am to build a program that randomly generates 500 alpha-numeric numbers (license plate numbers). the program needs to be able to search the 500 numbers and based on given criteria (a text box) that you put in return the matching results to another listbox. I got the 500 plate numbers to generate on form load but have been searching thru my textbook and cant seem to figure out how to take the imput from the text box and search the list box. Not asking for a ton of help but just a point in the right direction. i attached the assignment i was given from instructor.

[Code]...

View 5 Replies

List Of T Find Date Or Other Property In A Object In The List - Then Return Found Object?

Sep 3, 2009

After reading all the examples for list of T exists and Find and find first, none show how to handle multi-property objects. Below is bare bones example maybe someone could flesh out to show how this should be done.

Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim DatePriceList As New List(Of DateAndPrice)
DatePriceList.Add(New DateAndPrice(Date.Parse("1/1/2000"), 10.12))
DatePriceList.Add(New DateAndPrice(Date.Parse("1/2/2000"), 11.12))

[Code]...

View 3 Replies

Display A List (Of Object) Which Has Single Objects And Child List (Of Object)?

Sep 6, 2011

Limited to using v2.0 of .Net framework (we use VB.net) due to environmental constraints on our servers.I've got an ASP.net webpage which pulls data from a webservice that performs checks on user accounts in active directory. Operators can check multiple accounts at one time using the web interface. The webservice returns a list(of AccountCheck) objects which themselves contain single properties like username, email address, and List(of AccountError) objects which contain multiple properties.[code]What I want to do is using some kind of repeater, create multiple panels or divs which contain labels showing the username, email etc, and a gridview which has the accounterror list bound to it to show all the errors. The users could be checking 2, 5, 7 accounts at once, and is dynamic.

View 2 Replies

Cast A List Of Object To List Of Interface That Object Implements?

May 19, 2009

I am working in VB.net and have a Class, Foo, that implements an interface, IBar.I have a List of Foo's, but I need to pass a list of IBar's into a function, but I keep getting casting errors, even when I use DirectCast.My code is [code]MainWorks works, but it would be really annoying and inefficient to have to do that everywhere I want to call this function.

View 4 Replies

Asp.net - Returning Object From A Function?

Feb 8, 2012

If an object is created inside a function and the function returns that type of oject how is the memory handled.

Example:

Public Function GetEmployee(employeeid as integer) as employee
Dim oEmployee as new employee
oEmployee.FirstName="Bob"

[code]....

Does the variable that receive the object still a pointer to the memory location that was used inside the function?What about when you do a oEmployee2=oEmployee.Is oEmployee2 just a pointer? And any changes to oEmployee will now affect the other. Just trying to understand it from a memory perspective and how that scope works?

View 2 Replies

Returning Json Result With Object Name MVC?

Oct 28, 2010

When a json result is returned by the controller the object name seems to be missing, I normally wouldn't mind but the flexbox jquery plugin requires the json result in a particular format.

[Code]...

View 2 Replies

Returning Object From COM Assembly Into VBA (Access)?

Mar 15, 2011

I have an assembly in VB .NET 2.0 that I am trying to use to call a webservice.This will be COM visible, and return the results to Access in VBA.The .NET Assembly passes all tests and executes perfectly.I was experiencing "Object does not support this property or method" errors when calling the methods from VBA.I broke it down to a certain object that was being returned and added some test methods to the .NET DLL.There is a "Patient" object I want to return.It looks like this (made it very very simple to test it):

Option Strict On
Option Explicit On
<ComClass(Patient.ClassId, Patient.InterfaceId, Patient.EventsId)> _

[code].....

View 1 Replies

Function Returning An Object With Type Specified In The Argument

Mar 22, 2011

How can I create a function that returns an object of a certain type, which the user of the function specify in the argument (using vb.net 2010) ?

[Code]...

The code above doesn't work, but maybe it can explain what I want to achieve. Using this feature, I want to hydrate my data transfer objects from datatable. Client will just call this function, specifying which DTO the client wants, and this function will just create that DTO and populating the properties with reflection GetType.GetProperties().

View 2 Replies

Session Object Not Returning On Page Redirect

Jun 11, 2012

So In Default.master.cs PageLoad I have the following[code]...

However this is causing the following exception!object reference not set to an instance of an object.

View 1 Replies

WINNT Object Only Returning 100 Users From Active Directory

Mar 15, 2011

I have this problem that just recently started happening.I've created this snippet that isolates the problem, which is basically, the same VBScript that used to return all of my users from Active Directory, now only returns the first 100 users.If I filter by group, then i get all of the groups (which is more than 100).The problem started happening last November, then went away for a while and has come back.The server guys tell me that nothing should have changed there.When I run this script for various domains, i get a numbered list of just the first 100 users.I'm running this on IIS (which hasn't changed)[code]

View 2 Replies

Extension For Dataset Returning List Of Objects

Apr 6, 2010

I want to define a function similar to:[code]My current definition is having an issue with the following statement:GetList = (From x In oDS.Tables(0) Select New T(x)).ToList.I can't figure out how to get to create a New object of type T, any suggestions?

View 2 Replies

LINQ Returning List Of Anonymous Types

Mar 11, 2009

Any best approach to what I'm trying to achieve (linq to sql, returning list of data to show in a grid/list etc etc)... Its complaining about anonymous type conversion, and from what I'm reading, thats not elegant way of doing it.

Public Function GetHistory(ByVal historyId As Integer) As List(Of ?????????)
Using dc As New myDataContext(Application.GetConnection)
Return (From t In dc.ActionTypes, a In t.MyTable Where a.HistoryID = historyId Select a.ActionOn, a.ActionBy, t.Description, a.ImpactedItem, a.ActionDescription).ToList
End Using
End Function

View 4 Replies

VS 2008 Way Of Returning Datatable Data As List?

Sep 29, 2011

I have a Business Logic Layer that contains function that return datatables. I'm writing a function that will return just the records that begin with the string passed in. this is what I've come up with so far:

Public Function FetchBusinessAreas(ByVal area As String) As List(Of BusinessArea)
Dim AreasList As New List(Of BusinessArea)
Dim dt As DataTable

[code].....

View 2 Replies

Linq To Xml Query Returning A List Of All Child Elements?

Mar 8, 2010

I have got an xml document which looks something like this.

<Root>
<Info>
</Info>
<Info>

[Code]...

How can i write a linqToXML query so that it returns me an IEnumerable containing each child element, in this case all five child elements of , so that i could iterate over them. The order of child elements is not definite, neither is number of times the may appear.

View 1 Replies

Javascript - Response Object Not Returning Excel Stream In Update Panel?

Oct 11, 2010

I am generating an Excel file upon a click of a button in an update panel. It is throwing a parsing error.If I keep the button outside the update panel it is working fine. Why isn't it working in the update Panel?

Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("Content-Disposition",
String.Format("attachment;filename={0}", filename))[code].....

View 1 Replies

How To Quickly Transform A List(Of Object) Into A List(Of "Object.field")

May 29, 2012

Suppose I have a list of Cat.

Public Class Cat
Public Property id As Guid
Public Property name As String
Public Property race As catRace
End Class

How can I quickly transform this List(Of Cat) into a List(Of Guid) using the id property?

I could do :

Dim newList As List(Of Guid)
For each item in catList
newList.Add(item.id)
Next

But I think there must be a way to do this faster (1 LOC). I just can't find how.

View 3 Replies

C# - Returning List Of Null-terminated Strings From External Function Into .NET

Mar 29, 2012

I am trying to call an external C++ function using VB.NET (answers in C# are fine, I can convert back) which returns a list of device names. This comes in the form of a pointer to a null-terminated array of null-terminated char arrays (correct me if I've misunderstood what I'm dealing with) with a function signature:

long GetNames(char*** names)

Most of the answers to similar questions I've found have involved something more like:

long GetNames(char** names, int length)

It appears from what I've read that I need to give it an IntPtr but I'm uncertain as to how this should be initialized, and in my case I don't know the length of the array. At the moment, in the VB module, I have:

<DllImport("MyExternal.dll", CallingConvention:=CallingConvention.Cdecl)> _
Function GetNames(ByRef names as IntPtr) As UInteger
End Function

I've tried calling the function by passing an IntPtr initialized as IntPtr.Zero or using Marshall.AllocHGlobal, but I always get an AccessViolationException.

Any ideas on how I should be calling this function and how I get the return value into a managed string array would be greatly appreciated.

EDIT: I've found a sample function call in native C as follows:

char **tmplist;
GetNames(&tmplist)

View 2 Replies

Error On Returning List Of String 2008 Desktop Application

Nov 22, 2010

I'm trying to create a ntier desktop application using vb.net 2008.I'm trying this [code]...

View 6 Replies

Error On Returning List Of String Program Desktop Application

Nov 22, 2010

I'm trying to create a ntier desktop application using vb.net 2008.[code]...

By the way what i want to achieve is how to get the data as a List(Of String),because if i put the getMenu function into the presentation layer directly,it gives me the data as i expected..Also if i return as a string instead of List(Of String),it gives me the single data.

View 2 Replies

Search For Files Recursively While Updating A Progress Bar And Returning The File List To The Application From BackgroundWorker?

Dec 10, 2011

I am currently trying to develop an application which will backup large folders to a specified destination. To find all the files in the specified 'backup' directory I am using the following code.

[Code]...

I have tried putting my GetFilesRecursive function into a separate background worker to run first so I can update the GUI however I am struggling on how to return the List of found files back to my application (I get cross-threading exception) and how to update the progress bar to show the progress of the GetFileRecursive function so the user knows it is processing the list of files and has not crashed/frozen.

View 1 Replies

C# - WCF Serialization And Interfaces - Error: List(of Object) Cannot Be Converted To List(of IMyInterface)

Oct 16, 2009

Does link text mean I have to return a concrete implementation? Even though I am using svcutil with the /r that includes my entites(where IMyInterface is defined). I get no errors but it changes all List(of IMyInterface) to list(of Object) and I cannot deserialize it on the client

Error: list(of object) cannot be converted to list(of IMyInterface).

View 1 Replies

Does An Object Retrieved From A List Get A Copy Of That Object Or A Reference To It

Feb 1, 2012

In VB.net, when I retrieve a value from a list do I get a copy of that value or a reference to it?

dim blah as someObject
dim listOfBlahs as list(of someObject)
listOfBlah.add(new someObject(1))

[Code]....

View 2 Replies

Why Is List.add() Adding Items To Object AND Source Object As Well

Jun 15, 2011

I need to be able to add elements to a copy of mylist.testlist without modifying the global mylist object. (Which seems to be happening via the below code.)When I am working on x, which should be a totally separate object, mylist is getting modified as well. How can I fix this? I have worked with lists extensively and never seen this behavior before. I have tested and reproduced the problem in .NET 3.5 and .NET 4.0 on Win 7 Pro 32bit.

Source Code:

Public Class Form1
Public mylist As New test
Sub Main()

[code]....

View 1 Replies

Create List Of Child Objects From List Of Parent Object?

Jun 2, 2011

I would like to create list of child objects from list of parent object. Like If i have list of bookingroom which has one member room then i would like to create list of room from it.

eg. code:

Dim BookingRoomList As List(Of BookingRoom) = New List(Of BookingRoom)
Dim RoomList As List(Of Room) = New List(Of Room)
BookingRoomList = BookingRooms.FillGrid()

[Code]....

Is there any short cut method instead of iterating over for earch?

View 1 Replies

Copy List Object To Another List Object

Jun 15, 2012

I am having a problem when setting VB.NET list object to another.I create an instance on ReadLocations and than create an object of ReadLocation where then I loop through ReadLocations and set ReadLocation1 equal to rl. What happens is that if I then go and change ReadLocation1 to something else (assdfhsd) it will also change the ReadLocations index. I am really confused why it would be doing that unless it is "=" sign means referencing instead of actually setting the value. Please help as I am a C# developer but the program I am modifying is in VB.NET.[code]

View 1 Replies

.net - Searching A List Of Objects In An Object List Using Linq?

Dec 22, 2010

I have 2 classes

Public Class Shipper
Public Property ShipperID As Long
Public Property CreateDate As DateTime

[Code].....

View 1 Replies







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