|
How to get the unique Serial number on usb flash drive()vb.net2005
I need your help, please! Thanks all..
gladys
|
|
|
|
|
http://www.codeguru.com/vb/controls/vb_shell/comments.php/c3049/?thread=39850
|
|
|
|
|
I have the need to write typed class that will hold single values as well as a collection of one value such as places lived. So I would have Name, Number, Income, Places Lived(multiple).
I have this done as a collection variable that holds the class with a .Add. When I try to set the value to the populated class in the code it says that the class cannot be converted to type Collections. What is the deal???
Cleako
|
|
|
|
|
cleako wrote: What is the deal???
If you were to post a skeleton of your class structure (the classes + public interfaces would be sufficient) it would make more sense.
cleako wrote: When I try to set the value to the populated class in the code it says that the class cannot be converted to type Collections. What is the deal???
I suspect that you are attempting to store an instance of the class PlaceLived into a Collection object, rather than create the collection and add the PlaceLived object to the collection.
|
|
|
|
|
Something like the following.
<br />
Public Class Person<br />
<br />
Private m_strName as String<br />
Private m_strNumber as String<br />
Private m_colPlacesLived as Collection<br />
<br />
Public Property P_Name as String<br />
Get<br />
Return m_strName<br />
Set (ByVal value as String)<br />
m_strName = value<br />
End Property<br />
...<br />
Public Property PlacesLived as Collection<br />
Get<br />
Return m_colPlacesLived<br />
Set (ByVal value as Collection)<br />
m_colPlacesLived.add(value)<br />
End Property<br />
<br />
End Class<br />
<br />
Public Class PlacesLived<br />
<br />
Private m_strAddress as String<br />
...<br />
Public Property PL_Address as String<br />
Get<br />
Return m_strAddress<br />
Set (ByVal value as String)<br />
m_strAddress = value<br />
End Property<br />
<br />
End Class<br />
That is the basic structure of what I am trying to do and when I set the values I do this.
<br />
Dim objPerson as new Person<br />
Dim objPlacesLived as PlacesLived<br />
<br />
objPerson.P_Name = "Name"<br />
<br />
For i as Integer = 0 to DataTable.Rows.Count - 1<br />
objPlacesLived = new PlacesLived<br />
<br />
objPlacesLived.PL_Address = "Address"<br />
<br />
objPerson.PlacesLived = objPlacesLived<br />
Next<br />
Any ideas??
Cleako
|
|
|
|
|
Your mixing types. your property is typed as a 'collection' but when setting a value to the property your using a 'placeslived'
make the property readonly return the collection
make a method to add a new placeslived to the collection.
|
|
|
|
|
cleako wrote: Set (ByVal value as Collection)
m_colPlacesLived.add(value)
You're adding a collection to m_colPlacesLived. Is this what you mean to do ? Or do you mean to make m_colPlacesLived = value ?
cleako wrote: objPerson.PlacesLived = objPlacesLived
Is PlacedLived a collection class ?
I'd expect you to just have a get accessor, because it returns a collection, which you can then call Add on, or Clear, or anything else. The setter is only needed if you want to pass an entire collection in. And if you want that, you don't want to use Add, you want to use =.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Ok Im completely lost now. Why would I use a Get only when I need the collection stored in that class?
Here is what I am trying to do, I want to see if I can successfully serialize the class into the XML I want and then I can add the beginning and ending tags as I need them. So I have multiple PlacesLived for example so I would have the Places_Lived_Data property which would hold multiple Places_Lived objects. I tried this morning to create a collection before I set it to the property and fill it with the objects there then I would set it equal to the property value which then tells me:
"To be XML serializable, types which inherit from ICollection must have an implementation of Add(System.Object) at all levels of their inheritance hierarchy. Microsoft.VisualBasic.Collection does not implement Add(System.Object)."
-- I think I found a solution. According to http://www.codeguru.com/forum/showthread.php?t=386776[^] I should be using Generic.List(Of PlacesLived) instead of Collection. That took care of the issue I was having and the XML output looks correct at first glance. Thanks!!!
I think I need the weekend to get here!
Cleako
-- modified at 8:03 Thursday 11th January, 2007
|
|
|
|
|
cleako wrote: Why would I use a Get only when I need the collection stored in that class?
because that returns the collection and you can then call methods on it, such as clear and add
cleako wrote: I think I found a solution
OK, great
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Hi there,
How do i make an arraylist available globaly. I know that the easy way is to make it a (Dare I say it ) Global variable.
|
|
|
|
|
you can make the variable shared within a class
public class Common
public shared oaArray as new arraylist
end class
-----
any code:
common.oarraylist.add("??????")
|
|
|
|
|
Thanks for that.
|
|
|
|
|
A global variable is the only way to make it available 'globally'. A better choice is to say 'who needs to see this, and in what context'. For example, can you pass it to the intended clients via a delegate ?
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Christain,
using 'shared' will also make it available globally to the project and within referenced objects.
|
|
|
|
|
Of course it will - the point is, he knows it's a bad idea, so why not talk about alternatives ?
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
A global variable is the only way to make it available 'globally'. A better choice is to say 'who needs to see this, and in what context'. For example, can you pass it to the intended clients via a delegate
posted by Christian Graus - C+++ MVP
This is a good question
I have had a look and 8 out of 27 procedures need to see my Global Var.BTW I have put 3 more in there.
1 is a arraylist
1 is a string
2 are int.
A little info.
my application is a image viewing program, i ask the user to select the directory that they want to view...put the dir listing into a string and put the image names into the array. The rest of the program deals with displaying the images by clicking on verious menu's & buttons. Which is why i need global var. I split up the directory listing and display that if the user want too.
if there is an easier way to do this, i am open to ideas....just remember i am a newbie to VB2005 programming
|
|
|
|
|
Christian, I don't claim to know it all so please teach me, I'm curious:
A delegate is a more or less a memory pointer to some routine. Given that, how would a delegate help? How does the delegate "expose" the arraylist variable? You would need to call a routine for adding or removing or searching, or returning the arraylist itself, etc. With all of that needed functionality could one single pointer give the developer that? You can't overload a delegate can you? Also, I would need to pass the pointer to every object that needed it which may or may not possible depending on how the object was created.
Thanks,
Nathan
|
|
|
|
|
nlarson11 wrote: Given that, how would a delegate help?
Because a global variable is essentialy the easy solution to the question 'how do I make this visible in more than one place', when often the real question is 'when my classes data is updated, I need to let some clients know about it'. As such, you can define an event, such as 'ImageListUpdated', which passes the list directly to the clients that subscribe to it. This means that the access to the information is one way, and rigidly defined in terms of when it occurs.
nlarson11 wrote: You can't overload a delegate can you?
More than one client can subscribe to an event, so even if three classes need the message, it is not a big deal
nlarson11 wrote: Also, I would need to pass the pointer to every object that needed it which may or may not possible depending on how the object was created.
When would that not be possible ? How is it different to having it exposed on a global, in that regard ?
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Another excellent reponce Christian
I don't need to define an event as the event is allready happening when the user selected the directory to view the images from. The images are on the users computer, all i'm doing is getting their path\file names. The problem comes when the user wants to flip though the images as this is a seperate event.
At the moment this is not a problem,as I'm using Public Shared var. (See I did not use the word Global)
a question.... how much time & memory would it take to load into a imagelist 300+ images, of course some of the images could be different sizes, which then rules out using Imagelist. Myself I have a directory which contains images of different sizes, and i'm sure other users would be the same. So I don't think that I'll be using Imagelist any time soon.;P
|
|
|
|
|
WestSideRailways wrote: how much time & memory would it take to load into a imagelist 300+ images
I"m not sure, but the images themselves are passed by ref, so I wouldn't expect it to be much
I'd just put them in a List if I had to pass them around.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Hi
I'm using vb.net 2005 , when I go to run the project from the design mode it's OK , but when I go to run the EXE of the project , I found that the splash screen is appearing and then the StartUp form is running behinde other windows openning programs ,
this problem isn't appear when I run the program from it's source on vb.net envirnment , but on Exe , it's appear .....
jooooo
|
|
|
|
|
I have a class that I want to save to viewstate. In order to save it to viewstate it has to be serializable. How do you serialize a class and then unserialize it.
thanks
John
|
|
|
|
|
You mark it as serialisable, if it contains only POD, that is all you need, I believe.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
This book shows you how to serialize a class and deserialize it.
good book
|
|
|
|
|
John,
<Serializable() _
public class MyEntity
public sName as string
<Xml.Serialization.XmlIgnore()>public oObj as object
.
.
end class
Note: private variables will not be serialized
Note: some variable types cannot be serialized
Note: if you dont' want the value to be seralized you need to ingore the value
Note: import these libraries
Imports System.io
Imports System.Xml
Imports System.Xml.Serialization
-------
To Serialize:
Public Function sSerializeEntity(ByVal oEntity As Object) As String
Dim oSerializer As New XmlSerializer(oEntity.GetType)
Dim oSR As New MemoryStream, bt() As Byte
Try
oSerializer.Serialize(oSR, oEntity)
bt = oSR.GetBuffer
sSerializeEntity = System.Text.Encoding.ASCII.GetString(bt)
oSR.Close()
oSR = Nothing
oSerializer = Nothing
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Function
-----------
To Deserialize:
Public Sub DeSerializeEntity(ByVal sEntity As String, ByRef oEntity As Object)
Dim oSerializer As New XmlSerializer(oEntity.GetType)
Dim oSR As MemoryStream
Try
oSR = New MemoryStream(System.Text.Encoding.ASCII.GetBytes(sEntity))
oEntity = oSerializer.Deserialize(oSR)
oSR.Close()
oSR = Nothing
oSerializer = Nothing
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
---------------
** to serlialize object **
Dim oMyEntity as new MyEntity
oMyEntity.sName = "Test"
dim sEntity As string = sSerializeEntity(oMyEntity)
'''''''serialized''''''' you can pass the value of sEntity anywhere
** to put back into an object **
Dim oMyEntity as new MyEntity
DeSerializeEntity(sEntity,oMyEntity)
'''''''deserialized''''''' now you can use the object
msgbox(oMyEntity.sName)
|
|
|
|