|
If I am understanding your question correctly, what I would do is add each UnitClass object which is created during your loop to a collection along with a key so that you can access each object when needed.
Please let me know if I have got the wrong end of the stick!
|
|
|
|
|
The problem i have got is that the little code snippet i wrote will not work.
I do not seem able to create an object at run time using the contents of a variable as the object name.
|
|
|
|
|
It won't work for a couple of reasons. First, you reusing your loop variable as an instance of an object. What is n supposed to be?? Is it the loop variable or is it an object? It can't be both.
Second, your creating an instance of a class and then, on the next iteration of the loop, your replacing that instance with a new one. On top of that, since you're not adding these instances to a collection anywhere, the only remaining instance, when the loop terminates, goes out of scope and is destroyed. You have to add these to a collection somewhere to hang onto them.
|
|
|
|
|
The purpose of the for loop was more to help explain what I want to do than anything else.
How would i create n instances of an object, named object 1, 2, 3, ... n. where n is unknown until the app receives n UDP Datagrams at runtime?
I do intend to add them to an arraylist and sort by a particular variable using icomparable.
Regards, Chris
|
|
|
|
|
Why would you want to create named objects anyway?? It's easily done with an array or HashTable. A hashtable example:
Dim myCollection As New Hashtable
For n As Integer = 1 to m
Dim newObject As New SomeClass
myCollection.Add(n, newObject)
Next
|
|
|
|
|
So,ething like this should work:
Dim colObjects as new collection
For n as Integer = 0 to (number of devices)
colObjects.Add(new UnitClass(), n.toString)
Next
You can then access each object of the collection like this (replacing 1 with the number of the object:
Ctype(colObjects.Item("1"), UnitClass).<<property name>> = <<property value>>
Hope this helps
|
|
|
|
|
Thanks to both of you
Until the last couple of weeks, I haven't had to do any serious VB programming for almost 10 years (I mainly code asm for uprocessors), and it's changed a hell of a lot!
Still trying to grasp the system.collections basics...
Regards, Chris
|
|
|
|
|
Hello there,
I have developed an application in VB 2005 backend SQL 2005 Reporting Crystal report 9.0
well now the application is tested everything is done
Now in end simply i want to make a setup for an entire application so that it can be burn into cd's and and be installed on other computers..
Any one can help me with brief.???
Thanks
Kenny.
|
|
|
|
|
You can add a Setup project to your solution and use that. It's not meanth for more complicated installs though. Or, you can use Wise Package Studio, InstallShield, InnoSetup, ... Just Google for "create windows installer" and you'll find other packages that can do this.
|
|
|
|
|
can anybody help me with a vb code that will browse into the folder and then delete/empty all its contents say, to another folder.
phokojoe
|
|
|
|
|
Please, its so easy to do a search here to find the answer to this, there have been similar questions several times in the last few days.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Its really not that hard......
System.IO Perhaps?
And technically you cant delete a file and then move it to another folder.
Lloyd J. Atkinson
|
|
|
|
|
hi every one i want to develop a hotel reservation system. please can someone help, tell me all the requirements i am not very food in programming. i don't know where to start from. thank you. Steven
|
|
|
|
|
sturabumukiza wrote: hi every one i want to develop a hotel reservation system. please can someone help, tell me all the requirements i am not very food in programming. i don't know where to start from
So, why do you want to do this then?
|
|
|
|
|
Well first of all, YOU have to document the requirements, we can't do this as it's your system and you're supposed to know what is required. Once you have the requirements you can then make some decisions on what technologies to use, i.e. what programming language, database system etc. You can then start to design your application with these decisions in mind.
If what I have said makes no sense to you then I suggest reading some books on software design and development first before even contemplating any programming.
|
|
|
|
|
sturabumukiza wrote: i don't know where to start from
Turn off the PC, tell your client you were robbing them, or tell your teacher the subject is beyond you.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
|
Of course, if he onsells this, he is scum, and if he hands it in to class, he deserves to fail.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
I just give sample project instant of requirement. and that is done vb6.0 and done in long back.
He will get some idea. it is wrong Christian
|
|
|
|
|
Plus he will also be nothing but a Fool.
Lloyd J. Atkinson
|
|
|
|
|
Hi,
I am a beginner of VB2008 programming.
I tried to develop a simple class which takes array data and write them in Excel sheet as 2D array. However, it is not working. Could anyone tell me what went wrong? Here is my code.
Public Class WriteDtToExcel
Private ShNumber As Integer
Private CellX As Integer
Private CellY As Integer
Private ReadOnly DtA(CellX * CellY) As Double
Public Property SheetNumber() As Integer
Get
Return ShNumber
End Get
Set(ByVal value As Integer)
ShNumber = value
End Set
End Property
Public Property XSize() As Integer
Get
Return CellX
End Get
Set(ByVal value As Integer)
CellX = value
End Set
End Property
Public Property YSize() As Integer
Get
Return CellY
End Get
Set(ByVal value As Integer)
CellY = value
End Set
End Property
Public Sub New()
Dim i As Integer
For i = 0 To DtA.Length
DtA(i) = DtA.Length - i - 1
Next
End Sub
Public ReadOnly Property ArrayData() As Double()
Get
Return DtA
End Get
End Property
Sub WriteDtToExcel()
Dim objApp As Excel.Application
Dim objBook As Excel.Workbook
Dim objBooks As Excel.Workbooks
Dim objSheets As Excel.Sheets
Dim objSheet As Excel._Worksheet
Dim range As Excel.Range
Dim x As Integer
Dim y As Integer
' Create a new instance of Excel and start a new workbook.
objApp = New Excel.Application()
objBooks = objApp.Workbooks
objBook = objBooks.Add
objSheets = objBook.Worksheets
objSheet = objSheets(Me.SheetNumber)
'you can name the objsheet
'objSheet.Name = "First Sheet"
range = objSheet.Range("A1", Reflection.Missing.Value)
range = range.Resize(Me.XSize, Me.YSize)
'Set the range value to the array.
Dim PxDt(Me.XSize, Me.YSize) As Double
For y = 0 To Me.YSize
For x = 0 To Me.XSize
PxDt(x, y) = Me.ArrayData(Me.YSize * y + x)
Next
Next
range.Value = PxDt
'Return control of Excel to the user.
objApp.Visible = True
objApp.UserControl = True
'Clean up a little.
range = Nothing
objSheet = Nothing
objSheets = Nothing
objBooks = Nothing
End Sub
End Class
With my short knowledge, I was hoping to assign pixel size by:
WriteDtToExcel.xsize = 100: WriteDtToExcel.ysize=100: WriteDtToExcel.DtA=dtarray and so on, and then run the subroutine for data export to Excel.
Ofcause, it is not working at all.
Could someone advice me what was wrong with me.
cheers,
Whity Hwang
|
|
|
|
|
As a beginner, one of the most important things you need to learn about is the debugger. Look it up in the help and then step through your code to see what is going wrong.
With the information supplied its almost impossible to know what is wrong as you just say
SangGi Hwang wrote: Ofcause, it is not working at all
In what respect?
Anyway, try debugging and post more details when you know the exact error.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Hi,
How to convert speech to word converter...
give me idea for this...
thx in advance
kannan.c
|
|
|
|
|
Buy Dragon Naturally Speaking. Ponder why they'd create a whole product to do this, if it was so easy people could be told how to write it in a forum reply.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
If you want text to speech, then the System.Speech namespace should help. Try this article[^] for more information. However, this only works on version 3.0 of the .Net Framework and above. Otherwise, you'll need to use COM
|
|
|
|