Syntax - Object Initialiser List(Of T)
Jul 15, 2010I have been looking at some C# code:
[Code]...
But I would like a List(Of Employee) as it is bugging me as to why this doesnt work in vb.net?
I have been looking at some C# code:
[Code]...
But I would like a List(Of Employee) as it is bugging me as to why this doesnt work in vb.net?
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]...
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 RepliesI 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 RepliesSuppose 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.
I am using Visual Basic Express 2008 to make a simple game. I am trying to declare a dataset object and datatable but I'm getting a bizarre syntax error and I can't find a help reference.
Line A - I dimension GameTable as an Object
Line B - I instantiate the object
Line C - I edit data in the GameTable
Line D - I display the data in Visual Basic
Line C will crash in runtime if I don't do sometype of "New" declaration
Line B is my attempt at a "New" Declaration by I get an error message I don't understand - "Type Expected" - I think I have the syntax wrong here.
[Code]...
What is wrong with this Anonymous Object Initialize syntax?
If (Not row Is Nothing) Then
Dim info As New CultureInfo(Conversions.ToString(row.Item("cultureId"))) With { _
.NumberFormat = New With {.CurrencySymbol = Conversions.ToString(row.Item("symbol")), _
[code].....
I have a form called document_form. I have three variables:
Dim Doc1, Doc2, Doc3 as Document_form
How do I check if a particular form exists? I want to show Doc1. If it does not exist I have to first create it.
Something similar to:
If Doc1 = Null Then
Doc1 = new (document_form).
End If
I have a list( of clsCourseList) which is a class that contains a boolean value "Scheduled" I want to return a boolean value if ANY of the items in the list of clsCourseList contain a "Scheduled" value of False.I was playing around and have this (courseList is the list of clsCourseList
courseList.Exists(Item.Scheduled = False)
but I receive an error for the item keyword. I don't really understand the syntax its just something I found online, but it was in C#.
The purpose of this is to quickly check if all classes are scheduled, without looping through each one as there are hundreds and this takes place a few times in the program.
What's the best Object Browser / Syntax Training Manual? Looking for a good reference guide which helps me understand what I'm seeing with the object browser.
View 1 RepliesIn an ASP.NET 3.5 VB web app, I successfully manage to cache an object containing several personal details such as name, address, etc. One of the items is CreditNum which I'd like to change in the cache on the fly. Is there a way to access this directly in the cache or do I have to destroy and rebuild the whole object just to change the value of objMemberDetails.CreditNum?The cache is set using:
Public Shared Sub CacheSet(ByVal key As String, ByVal value As Object)
Dim userID As String = HttpContext.Current.User.Identity.Name
HttpContext.Current.Cache(key & "_" & userID) = value
End Sub
In the following two code snippets, the code does the same thing, when I tested this.
Dim test As New Class1 Dim test As New Class1() Do the parantheses make a difference in some way? Is there an explanation of this in the msdn library?
what is the syntax for blank list view object... for example:[code]what is the syntax for classlistview is blank? as in no record(s) were retrieved.
View 3 RepliesIn C# I have been performing a FindAll in a generic list as follows:List<group.category> tlist = list.FindAll(p => p.parid == titem.catid);Two questions, is this the appropriate way of performing such a thing and how do I convert this to VB.Net
View 1 RepliesDoes 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).
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]....
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]....
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?
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 RepliesI have 2 classes
Public Class Shipper
Public Property ShipperID As Long
Public Property CreateDate As DateTime
[Code].....
How to know if a List(Of T) contains any control object without using a loop ?This doesn't work
Dim lstObject As New List(Of Object)
lstObject.Add("STRING")
lstObject.Add(2)
[code].....
I would like to ask what is the efficiency way the clean and dispose the object collected in the List (Of Object)?
Is that by calling the List.Clear() method will automatic clean all the object collected by it?
I am able to populate an object and output everything. How do I remove say the name2 object?
la.Remove(Logins("name2")) doesn't seem to work.
Private Sub btnListArray_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnListArray.Click
[code]....
Anyone have VB.Net or VBA code to ascertain if an Excel Object is positioned over (Hiding) spreadsheet data?I have code to create/position a chart object. Where would I begin to determine if there is data "under" an object.
View 7 RepliesMVC 3 razor VB.NET project. I have resorted to manual building a list for a drop down box so I can insure certain values are available in the select list and also to control what the first item is in the list. The below is my code snippet for the part that is giving me problems..
[Code]...
I have a class that has a property that I declare like this:
VB.NET
Private _DirectoryList As List(Of FileDirectoryInfo) ''' <summary> ''' Array of directories. ''' </summary> ''' <value>Object</value> ''' <returns>Directory array list</returns> ''' <remarks>N/A</remarks> Public Property Directory As List(Of FileDirectoryInfo) Get Return _DirectoryList End Get Set(ByVal value As List(Of FileDirectoryInfo)) _DirectoryList = value End Set End Property
[Code]...
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 RepliesI've seen a lot of posts for how to do this in C#, but I'm working in VB and they don't work and I can't seem to get them to convert. Anyone know this? C# is something like: if (x is IEnumerable)
[Code]...
I've created A list of object "emails" which contains the "email" object which has 3 parameters (String Address, String Subject, String Body)I then want to add to the list by creating more instances of "email". However, I've tried so many different ways and it's having none of it.
Public Class Test
Public emails As List(Of Email)
[code].....
If I click button1 I get the error "Object reference not set to an instance of an object".
Using MVC3 and Razor View engine, I created a VB.NET web application in VS 2010. This creates the default Account and Home Controller along with corresponding Action Views.Now if I open any vbhtml file I get the following error message in the Error List window.
Error 50 Syntax error. C:****MVC3AppVBViewsAccountLogOn.vbhtml MVC3AppVB
(See screenshot here http://www.flickr.com/photos/7672540@N07/5469248676/)
[code].....