Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Control Array is 20 times slower in VB. NET compare to vb6 1

Status
Not open for further replies.

codecref

Programmer
Dec 8, 2003
118
0
0
US
hi guys
here is the code I took from msdn.microsoft which is implementing control array, I have about 1500 or 3000 label in my project which only 5 to 10 of them will display at a time and they will just in and out of screen (implementing sort of timeline such as premiere) and in VB6 it was not PERFECT, but it was okay to sliding and loop through all 3000 in one third of a second but its taking about 5 to 10 second to do the same in vb .net


CODE FROM MICROSOFT:
Code:
Public Class cLabelArray

    Inherits System.Collections.CollectionBase

    Private ReadOnly HostForm As System.Windows.Forms.Form

    Public Sub New(ByVal host As System.Windows.Forms.Form)
        HostForm = host
        Me.AddNewLabel()
    End Sub

    Public Function AddNewLabel() As System.Windows.Forms.Label
        ' Create a new instance of the Label class.
        Dim aLabel As New System.Windows.Forms.Label
        ' Add the Label to the collection's internal list.
        Me.List.Add(aLabel)
        ' Add the Label to the controls collection of the form 
        ' referenced by the HostForm field.
        HostForm.Controls.Add(aLabel)
        ' Set intial properties for the Label object.

        aLabel.Top = Count * 25
        aLabel.Left = 100
        aLabel.Tag = Me.Count

        aLabel.Text = "Label " & Me.Count.ToString

        Return aLabel
        AddHandler aLabel.Click, AddressOf ClickHandler
    End Function

    Default Public ReadOnly Property Item(ByVal Index As Integer) As System.Windows.Forms.Label
        Get
            Return CType(Me.List.Item(Index), System.Windows.Forms.Label)
        End Get
    End Property

    Public Sub Remove()
        ' Check to be sure there is a Label to remove.
        If Me.Count > 0 Then
            ' Remove the last Label added to the array from the host form 
            ' controls collection. Note the use of the default property in 
            ' accessing the array.
            HostForm.Controls.Remove(Me(Me.Count - 1))
            Me.List.RemoveAt(Me.Count - 1)
        End If
    End Sub

    Public Sub ClickHandler(ByVal sender As Object, ByVal e As System.EventArgs)
        MessageBox.Show("you have clicked Label " & CType(CType(sender, System.Windows.Forms.Label).Tag, String))

    End Sub

End Class

Loop I do for all labels:

Code:
        With TimeScroll

            vCursor = (.Value / .Maximum) * Subx.TimeOUT(1, Subx.Max(SelStream))

            For I = 1 To Subx.Max(1)
                If I > Subx.Max(1) Then Exit For
                If Not (Subx.TimeIN(1, I) - vCursor) < 0 And (Subx.TimeIN(1, I) - vCursor) > Me.Width Then
                    StreamOne(I).Left = (Subx.TimeIN(1, I) - vCursor)
                    StreamOne(I).Left = (Subx.TimeIN(1, I) - vCursor)
                End If
            Next I
End With
 
Could you maybe just create 10 labels and then as they move left out of sight move them back to the right hand side and uupdate the text property with the next bit of data you wish to display? That way you don't have to hold a large number of labels in your Control collection which would speed it up.

Durkin
 
I would agree with Durkin. Working with 10 labels and controling their location, content and visibility will result in a much beter performing system.

I remember an old app I wrote in VB that had ~500 images (used in a graphical selection bar). On NT it would run acceptably, on 98 it would die. Because of the memory management differences between the OS's, it operated differently. Redesigning the ap to use ~50 images with dynamic content resulted in a program that ran significantly faster, and fine on both NT and 98.

-Rick

----------------------
 
well as average they may showup 5 to 10 but if user want to zoom-out , maybe 300 of them will show up concurrently and I don't think loading that amount of control in zoom-out/in event will be faster... however implementing that code is also not eacy...

I've seen many application that have thousands of instances and worked smoothly (I Don't know how) probably just by picturebox which is not easy for me to implement,

but why was it so FAST in VB6? and its so frustrating in .NET? and why is .NET so slow in just running my application? it takes about 10 seconds just to load my 3 form contain application with less than 1000 lines of code

what am I doing wrong? or what is Bill Gates doing wrong?
 
Load times can be longer because the Framework must be loaded into memory. Wether the framework gets loaded each time you run your app, or just the first time, I'm not sure. I've heard rummors that if you put an empty .net application in startup, that it will load the framework so the first run of your app won't take so long to load.

Bill Gates is doing nothing wrong. He doesn't even code. He just manages and makes lots of money.

VB.Net is not VB. VB.Net is fully Object Oriented. That means that alot of things that were done one way in VB can not be done that same way in VB.Net. Just because it is different does not mean it is bad.

What do you have in these 3000 labels? is it text? images? if it is images you can probrably use GDI+ and have the system running with instant response instead of the 1 sec delay you had in VB, or the 5 to 10 sec in VB.Net.

Just think, if you have a 32k image in each of those 3000 labels, you're looking at almost 100 megs of memory. Not to mention an overhead of the actual label.

-Rick

----------------------
 
its only text I am loading in the label, and no image... but what I am saying is how to make the code above faster? is there other method that vb.net is not using as vb6 was using so to make it same like before...

thanks for your replies
 
Here is the project I am working on ... same project from VB.net and VB6, you compare yourself the speed...

believe it or not, what I did for .net version was just updating (Label.left property) only those 5 or 10 labels that suppose to show up. it means:

VB6.exe file will update all 1245 labels
VB.NET.exe file will only update 5 to 10 labels....

compare the performance and judge yourself.

PS: you must load the SRT file given into app

Download HERE
 
forgot to add

PS2: in VB.NET Exe file you must click ADD before browsing
 
You could try putting the labels in an array. Like:

Dim lbls(NumOfLbls) as label

then loop through. Say you were populating them with text from a datatable(dt). You would do the following:

Code:
dim lbl as label
Dim lbls(dt.rows.count - 1) as label

for i = 0 to dt.rows.count - 1
    lbl = new label
    'Put in your label properties here.
    lbl.height = 10
    lbl.width = 50
    lbl.text = dt.rows(i).item(0)

    'Add to form controls collection (Me being the containing form)
    Me.Controls.Add(aLabel)
next i
Then do your loop as per VB6. You may have have to muck around with the widths of the labels etc. to get it looking right.
Also, I haven't tried this code, just written it down here as a idea so there may be problems with it.

Durkin
 
thanks for you reply

I couldn't understand what was lbls() defined for and how do I use it?
 
Hi. Sorry for not getting back sooner. I was away. I'm sure you've resolved this at this stage but anyway..
I should have had an extra line at the end of the loop like:

lbls(i) = lbl

This will give you your control array.

Durkin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top