Using A Custom Class In HashSet

May 30, 2010

I created a custom class which just stores 3 byte values, (R G B to be exact), which constantly change. So my idea was to store that class in a HashSet, then create a new instance of the class (with different byte values) then add that to the HashSet. There can be duplicates, which is why I decided to use a HashSet, which will ignore an item if it's allready been added. Doing this on a List would be too slow.But I've ran into a problem. Adding a custom class to hashset seems to only allow 1 to be added. I assume this is because its hashing the class object while ignoring the data (byte rgb values) it contains? Is there a way around this? It's possible to convert the RGB to Color and just use that in the HashSet, but conversion is a bit too slow.

View 2 Replies


ADVERTISEMENT

Create A Custom Class That Has Inside An Array Of Another Custom Class?

Jan 31, 2011

I want to create a custom class that has inside an array of another custom class (see my code below) but when the programm runs is crashes. Why? What is the right expression???? Plz help I'm a newbie in VB.net.....

Public Class ctrarray
Public nameclass As String
Public ctrlindex(glvar_spaces) As ctrlindexclass
End Class

[code]....

View 6 Replies

Interface And Graphics :: Making A Custom Class That Mocks The System.Drawing.Rectangle Class?

Jul 6, 2010

I'm making a custom class that mocks the System.Drawing.Rectangle class because the Rectangle class doesn't have a name property. I need a name property because I am adding all of my rectangles to a collection and I need a little more info stored than just their locale and size. So I changed the _onPaint event but nothing is working out when I run the program?

Public Class Rectanglar : Inherits UserControl
Public BackgroundColor As Color = Color.Blue
Public Sub New(ByVal name As String, ByVal XY As Point, ByVal Widthy As Integer, ByVal Heighty As Integer)

[code].....

View 5 Replies

.net - Using .Contains Method With Cached Hashset

Jul 26, 2011

I know that the .Contains method on a hashset is fast. My question is what is the best method for getting the hashset data before repetitively using the .Contains method?

I can think of 2 options. Both of these examples would be called in a loop of undetermined length.

1) Call the method that returns the cached hashset directly and use the .Contains method.

IF (GetHashSetMethod.Contains("TESTVALUE") THEN BLAH, BLAH, BLAH...

2) Create a new hashset outside of the loop and load the cached hashset data into it so the method that returns the hashset is only called once, then use the .Contains method.

DIM HashTest AS HASHSET(OF String) = GetHashSetMethod

Then in loop:

if (HashTest.Contains("TESTVALUE") THEN BLAH, BLAH, BLAH...

I have been using method 1. Should I even think about switching to method 2? Is there a 3rd option I haven't even thought of? Does it even matter because the data is cached to begin with?

View 2 Replies

Differences Between A HashSet(of T) And A List(of T)

Oct 10, 2011

What are the differences between a HashSet(of T) and a list(of T). I recently discovered HashSet and it seems to be substantially faster and uses much less memory than a list, so why use a list at all ?

View 5 Replies

Hashset For Contains With List(of String) .net?

Sep 20, 2010

Would the following:

Dim stringlist As List(Of String)
Dim stringlisthas = stringlist.Contains("thing1")
be any slower than
Dim stringlist As List(Of String)
Dim stringlisthash As New HashSet(Of String)(stringlist)
Dim stringlisthas = stringlisthash.Contains("thing1")

Is a hashset needed for contains?

View 1 Replies

Display A HashSet As Either A Collection Or An Array In The PropertyGrid?

Dec 21, 2011

How do I Display A HashSet As Either A Collection or an Array in the PropertyGrid.I wish there was some Attribute that allow me to display IEnumerable as an Array...but so far my attempts to do that have failed!My current solution is unacceptable in the new places I want to use it in

[Code]...

View 3 Replies

Generate Random Images Without Repeat Using Hashset?

Jan 10, 2010

I am trying to generate random images from access database using hashset as it is said to be unique and there won't be any repeated images appearing. But, it doesn't seem to work. ow can i get it to work? By the way, i am very new to the concept of hashset.

Private Function GetImageFromByteArray(ByVal picData As Byte()) As Image
If picData Is Nothing Then
Return Nothing

[code].....

View 1 Replies

How To Generate Random Images From Access Database Using Hashset?

Jun 22, 2010

I am trying to generate random images from access database using hashset as it is said to be unique and there won't be any repeated images appearing. But, it doesn't seem to work.

How can i get it to work? By the way, i am very new to the concept of hashset.
Private Function GetImageFromByteArray(ByVal picData As Byte()) As Image
If picData Is Nothing Then
Return Nothing
End If

' is this is an embedded object?
Dim bmData As Integer = If((picData(0) = 21 AndAlso picData(1) = 28), 78, 0)

' load the picture
Dim img As Image = Nothing
Try
Dim ms As New MemoryStream(picData, bmData, picData.Length - bmData)
img = Image.FromStream(ms)
Catch
End Try

' return what we got
Return img

End Function

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Panel1.Visible = False
Panel2.Hide()


Dim conn As New OleDbConnection
Dim DA As OleDbDataAdapter
Dim DS As New DataSet


conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db1.mdb;User Id=admin;Password=;"

DA = New OleDbDataAdapter("Select Empty, EmptyName, Target, TargetName from PicturesDisplayed", conn)
DA.Fill(DS)

Me.PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage


Dim oledbconnection As OleDbConnection
oledbconnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:Documents and SettingsAdministratorDesktopdb1.mdb;Jet OLEDB:System Database=system.mdw;")

oledbconnection.Open()
Dim command As OleDbCommand
command = New OleDbCommand("select count (*) from PicturesDisplayed", oledbconnection)
Dim count As Integer
count = command.ExecuteScalar()
oledbconnection.Close()


Dim randomImage As New HashSet(Of Integer)
' Create a integer and new Random object
Dim intPic As Integer
Dim rand As New Random

'Pick a random number between 0 and the number of images in database
intPic = rand.Next(0, count)
randomImage.Add(intPic)

PictureBox1.Height = 256
PictureBox1.Width = 256

PictureBox2.Height = 256
PictureBox2.Width = 256


Dim pic1x As Integer = _
(Me.ClientSize.Width - PictureBox1.Width) 2
Dim pic1y As Integer = _
(Me.ClientSize.Height - PictureBox1.Height) 2
PictureBox1.Location = New Point(pic1x, pic1y)


Dim pic2x As Integer = _
(Me.ClientSize.Width - PictureBox2.Width) 2
Dim pic2y As Integer = _
(Me.ClientSize.Height - PictureBox2.Height) 2
PictureBox2.Location = New Point(pic2x, pic2y)

' Now set the picturebox image equal to the image chosen from the array randomly using the random
PictureBox1.Image = GetImageFromByteArray(DS.Tables(0).Rows.Item(intPic).Item(0))
PictureBox1.Visible = True
PictureBox2.Image = GetImageFromByteArray(DS.Tables(0).Rows.Item(intPic).Item(2))
PictureBox2.Visible = False


If (randomImage.Count = count) Then
Me.Close()
End If

End Sub

View 1 Replies

.net - WP7 Custom Class UI Binding?

Feb 4, 2011

I have a map with a MapItemsControl in my WP7 app that contains pushpins bound to items in a collection of custom classes. The pushpins are bound to properties of the item in the collection via a DataTemplate.When an item is added to or removed from the collection, all pins display correctly, with properties as per bindings, but when just an items' properties are modified, the UI does not update. The bindings just seem to get values from the source item upon loading, but I'd like them to keep the UI elements updated when the source collection items' properties are updated.To illustrate, I'll create a similar example:

Heres a custom class:

Public Class Box
Property CurrentColor As Color
Property Location As GeoCoordinate
End Class

[code]....

Whenever I add or remove items from TempBoxes, the pins all render as they should (e.g. if I specify a color in the collection item, the pin shows the color).Tapping on the item triggers the BoxTouched sub, which causes the item's color to change in the collection, but the UI doesn't change (pin color stays the same).To get the UI to update the color, I have to get it to render the pins again, by adding something like this to BoxTouched:

BoxControl.ItemsSource = Nothing
BoxControl.ItemsSource = TempBoxes

View 1 Replies

Arrays In A Custom Class?

Feb 14, 2009

I can't figure out why this does not work.

Public arrs(32) As ARR
Public Class ARR
Public nr As Integer

[Code].....

View 2 Replies

C# - Custom Installer Class?

Aug 4, 2009

I'm working on a project which needs some third party components prequisites to be installed before installing my .NET Application. Can someone tell me how to do it ?? I'm using .NET prequisites components to install the components like (.NET Framework 3.5,Windows installer 3.1,Crystal Reports) but what if i have some third party components which is not listed in prequisite lists ...

View 2 Replies

Custom Number Class?

Jun 8, 2010

I recently had the problem of trying to store an enormous amount of decimal places in a variable. Someone suggested that I create my own class to handle this. However I have researched extensively and can't seem to find a suggestion as to how I would do this. Would I read each digit into a list? How would I get each digit as to loop through a decimal, for example, and add each digit would still only give me 28 decimal places

View 8 Replies

Listbox And A Custom Class To Add Value?

Oct 21, 2010

Error Unable to cast object of type 'System.Data.DataRowView' to type 'M8_Rating.myItem'.Any idea what the deal is?

Dim MyItems As New List(Of MyItem)
For Each selItem As myItem In lb_forms_SecurityMgr.SelectedItems()
MyItems.Add(New myItem With {.Description = selItem.Description, .Value = selItem.Value})

[code].....

View 5 Replies

Moving From VB6 And Custom Class?

Feb 13, 2010

I have some questions regarding the dispose method as per custom classes.I imported a class using the upgrade tool and got introduced to the finalize method and this line of code within:

MyBase.Finalize()From what I have read this method is the class destructor and I should not be using it. Instead I should implement the IDisposable interface.

[Code]...

View 2 Replies

Serialize A Class That Is Not A Custom Of Our Own?

Apr 14, 2010

I need to look at the properties of an object and I cannot instantiate this object in the proper state on my dev machine. I need my client to run some code on her machine, serialize the object in question to disk and then I can analyze the file.[code]...

View 2 Replies

.net - LINQ To XML And Distinct Custom Class?

Oct 14, 2009

I have a very interesting LINQ question. I have a document, that I am trying to filter results on, but to filter, I am matching on a REGEX result from one element of the XML. I have the following, working LINQ to XML to get the individual data that I'm looking for.

[Code]...

View 3 Replies

.net - VB Datagrid + Array With Custom Class?

May 14, 2012

I have created a class "student" and made an array which contains students.I would not only like to display the array in a datagridview, but the array should also be updated if the user makes changes to one of the students in the datagridview.

I succeeded in showing the array in the dgv: one way is using datasource prop, the other is doing is diagrammatically. However, i can't find out how to let the user edit the array by editing the dgv.

View 1 Replies

Add Custom Class To A Generic List?

May 10, 2010

I created two classes. One class is StudentClass and the other is HomeroomClass. The HomeroomClass contains a readonly property as a generic list of the StudentClass. [code]...

View 6 Replies

Add Validate To A Custom Class Property

Mar 20, 2011

I'm trying to add validation to one of my class properties:[code]The value for the golfer's handicap comes from a oombo box on the form. Even if I have nothing set for this property at runtime, my validation doesn't work. I tried putting the If statement under Get instead of Set, and tried mHandicap = value after an Else in the If statement, but nothing seems to work. I'm working in the dark here and can't find anything suitable online. I was hoping to not go down the path of ReadOnly or WriteOnly properties as I'm not at that stage yet, but does this make a difference for my purposes here? Can anyone guide me as to what I'd need to do from this point? If I've got it right, you can add validation in the class and this means that you then don't need to repeat this validation in the form??

View 3 Replies

Assignment Operators In Custom Class

Jun 19, 2009

I have a custom class that simply contains a public variable X.Let's say I have two instances of the class, A and B.If I execute an assignment operator, such as:A = B then I want A.X equal to the VALUE of B.X.But, I'm pretty sure that this will just assign B to the variable A.Assigning pointers, in C++ lingo.I looked in the VB.NET docs, which state that "The operator can be overloaded only as a relational comparison operator, not as an assignment operator."

View 7 Replies

Create Custom Button Using Class?

Nov 20, 2009

I use this code to create the same Button in multiple Forms[code]....

View 6 Replies

Creating Custom Generic Class?

Jan 1, 2011

Here are essential excerpts for the code creating the class and the page using it:

Imports System.Collections.ObjectModel
Public Class Test (Of T as xyz)
Inherits Collection (Of T)

[code].....

View 7 Replies

Custom Class And Random Numbers

May 30, 2009

I am still learning vb.net and decided to make a "horse race" to get a better understanding of inheritance and such. So first of all I made a horse class that inherits from the picturebox. I gave the horse properties such as image, height, width, x-position, and y-position. I also gave the horse a speed(between 1-1000). My idea was to have the horses start at the starting line and get them to move using a timer. Each time the timer fires the move method executes. The move method creates a new random number(seeded by DateTime.now.milisecond) between 1-1000, if the random number is lower than the speed of the horse it will "move" adding 1 to the x-position property.

Here is the code for the class :
Public Class Horse
Inherits PictureBox
Private m_speed As Integer
Private m_picture As Image
Private m_xposition As Integer
[Code] ....

Now things work as I expected for the most part, I created two new horses and gave them values, if one is "faster" than the other it will move faster. Here is the code I use to create two horses and put them in an array:
Private thisHorse As New Horse(700, My.Resources.Horse__Small_, 20, 30, 100, 100)
Private secondHorse As New Horse(700, My.Resources.Horse__Small_, 20, 150, 100, 100)
Private horseArray() As Horse = {thisHorse, secondHorse}

I give the horses visual representation using a loop during the load form event:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For Each i As Horse In horseArray
i.Visible = True
[Code] .....

The only problem is if I give them both the same speed they seem to move in unison. I have tried adjusting the x-axis increment and have seen them both jump at the same time. Now I realize since they have the same "speed" they should have close to the same movements but wouldn't the random factor in the move method create some discrepancy between the two? I have ran this multiple times and am still unsure what the problem is.

View 3 Replies

Custom Class As An Array Of Properties?

Sep 30, 2009

I'm moving my first steps in the VB.NET world (I come from VB6) and I'm stuck with the creation of a particular class.

Let's say we have a bus that always has 101 places. I'm trying to create a class containing the map of the bus, along with methods to graphically represent it.

My "Bus" class will have a couple of properties ("BusColor", "BusModel") related to the whole bus. Then it should have a property called "Places" whose type is a custom class thet represents every single place, along with, for example, the passenger name or the place number. This property should of course be an array.

This is my code so far (simplified):

Public Class BusMap
Private Const MAX_PLACES As Integer = 101
Private _BusModel As String = ""

[Code]....

but I wonder if there is a more standard way of doing this.

My second question is: how can I modify my class to be able to iterate its Places property with the "for each" statement? A quick search on the web showed up that I should implement the IEnumerable interface, but I'm still not enough confident with the concept of Interfaces.

View 6 Replies

Custom Class In DotNetNuke Module?

Mar 21, 2011

I know this can be done as there are other modules out there that have this, but I'm just not getting it to work.

I have created a custom module for a DotNetNuke site. I want to be able to create a class object within the module to hold the information about that object. I can create the object and everything complies. But when I go to use the object in the code-behind it states that the object is not defined. I'm not really sure where to go from here.

This is the beginning of the View.ascx.vb :

Namespace Modules.VacationForms
Public MustInherit Class View
Inherits PortalModuleBase

[Code].....

I'm really not sure why this is not working. I did download another module code to compare and as far as I can tell everything is the same.

View 2 Replies

Custom ComboBox And Class Items

Apr 14, 2009

I have a custom combobox. Items are of this class
Public Class CustomItemsCombo
Public Sub New(ByVal valore As Integer, ByVal descrizione As String)
Me.Valore= valore
Me.Descrizione= descrizione
End Sub
[Code] .....

View 2 Replies

Dynamic Array Of Custom Class

Jun 16, 2009

I've been programming in VB.net for a while off and on, but never really had a need to use custom classes till now.I built a function in a module to populate a class, The class how ever is supposed to refer to one instance.I need to create an array of this class but the amount of instances needed is not always known.Works fine till the class goes to populate the class array.[code]It's probably something simple, I've just starred at it to long. Keep gettitng "Object reference not set to an instance of an object."

View 1 Replies

Dynamic Custom Class Property

Dec 18, 2009

I have a For Each block loops through a list of objects, the objects are all instances of a single custom class I have made which has multiple properties.The logic used in this block uses a property of the custom class to do a set action, is it possible to dynamically supply which property it uses in the logic? This will be more efficient and prevent me from having to create this logic over for each property of the custom class.My best guess was that maybe it is possible with reflection, however my searches into reflection have left me more confused.

View 2 Replies

Get Properties And Methods For Custom Class?

Oct 29, 2009

Is it possible to iterate through the properties and methods of a custom class, getting the details about those properties and methods in the process.[code]....

View 2 Replies







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