Results 1 to 5 of 5

Thread: user control ubound for array

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    199

    user control ubound for array

    Hi to bound user control to create an array. in VB6 I have this code which is working fine:

    For j = 1 To 10
    Load iProject(iProject.UBound + 1)
    Next

    How to make this work in VB.NET 2010?

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: user control ubound for array

    first forget about arrays.
    Next, search MSDN for "List(of T)" .... it'll be easier to work with than arrays.
    Then hopefully the following code sample will make sense:

    Code:
    Dim myProjects as new List(of Project) ' I'm guessing at the class type here...
    
    ....
    dim newProject as New Project
    'Set properties here if needed
    myProjects.Add(newProject)
    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    Re: user control ubound for array

    If they are controls why not add them to the container instead of a List<T> ?

    vbnet Code:
    1. Me.Controls.Add(New Project)

    The above dynamically adds a control to a container like a Form.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: user control ubound for array

    True... true... I hadn't considered that. Depends on what you want to do with it later... with the list you can jsut do
    myProjects.items(2) and get the third item in the list, not nearly as easily done if it's only in the Controls collection....

    that said, you'll actually probably need to add it to both...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    199

    Re: user control ubound for array

    Hi guys thanks for the response... I found a class file on the net to create timer basically this is what I would like to achieve but I need to create a lot of timers which will be bound to list view row number. on Form main I will load this to generate timer base on the row number of my list view. Each timer is independent to each other. Please guide me how to accomplish it.

    HTML Code:
    Imports System.ComponentModel
    
    <DesignerAttribute(GetType(MyControlDesigner)), System.Serializable()> _
    Public Class cdTimer
        Inherits Label
    
        Dim tmr As Timer
    
        Dim ts As TimeSpan
        Dim tsElapsed As TimeSpan
    
        Dim canUpDate As Boolean = False
    
        Private _countDownTime As New time
        <TypeConverter(GetType(timeConverter)), _
        DesignerSerializationVisibility(DesignerSerializationVisibility.Content), _
        Description("Expand to set countdown time.")> _
        Public Property countDownTime() As time
            Get
                Return _countDownTime
            End Get
            Set(ByVal value As time)
                _countDownTime = value
                ts = New TimeSpan(countDownTime.hours, countDownTime.minutes, countDownTime.seconds)
                tsElapsed = TimeSpan.Zero
                MyBase.Text = countDownTime.ToString
            End Set
        End Property
    
        <EditorBrowsable(EditorBrowsableState.Never)> _
        <Browsable(False), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
        Public Overrides Property Text As String
            Get
                Return MyBase.Text
            End Get
            Set(ByVal value As String)
    
            End Set
        End Property
    
        <EditorBrowsable(EditorBrowsableState.Never)> _
        <Browsable(False), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
        Public Overrides Property AutoSize As Boolean
            Get
                Return True
            End Get
            Set(ByVal value As Boolean)
    
            End Set
        End Property
    
        Protected Overrides Sub OnInvalidated(ByVal e As System.Windows.Forms.InvalidateEventArgs)
            If canUpDate AndAlso tsElapsed = TimeSpan.Zero Then
                MyBase.Text = countDownTime.ToString
                ts = New TimeSpan(countDownTime.hours, countDownTime.minutes, countDownTime.seconds)
            End If
            MyBase.OnInvalidated(e)
        End Sub
    
        ''' <summary>
        ''' OnCreateControl
        ''' </summary>
        ''' <remarks>initializes the countdownTimer</remarks>
        Protected Overrides Sub OnCreateControl()
            MyBase.Text = countdownTime.ToString
            ts = New TimeSpan(countDownTime.hours, countDownTime.minutes, countDownTime.seconds)
            tsElapsed = TimeSpan.Zero
    
            tmr = New Timer
            tmr.Interval = 1000
            AddHandler tmr.Tick, AddressOf tmr_tick
    
            canUpDate = True
    
            MyBase.OnCreateControl()
        End Sub
    
        ''' <summary>
        ''' tmr_tick
        ''' </summary>
        ''' <param name="sender"></param>
        ''' <param name="e"></param>
        ''' <remarks>tmr.tick event - performs the countdown</remarks>
        Private Sub tmr_tick(ByVal sender As Object, ByVal e As System.EventArgs)
            If ts.TotalSeconds > 0 Then
                ts = ts.Subtract(New TimeSpan(0, 0, 1))
                tsElapsed = tsElapsed.Add(New TimeSpan(0, 0, 1))
                MyBase.Text = ts.ToString
                Me.Refresh()
            Else
                tmr.Enabled = False
            End If
        End Sub
    
        ''' <summary>
        ''' cdStart
        ''' </summary>
        ''' <remarks>starts the countdown</remarks>
        Public Sub cdStart()
            canUpDate = False
            tmr.Enabled = True
        End Sub
    
        ''' <summary>
        ''' cdStop
        ''' </summary>
        ''' <remarks>stops the countdown</remarks>
        Public Sub cdStop()
            canUpDate = True
            tmr.Enabled = False
        End Sub
    
        ''' <summary>
        ''' cdReset
        ''' </summary>
        ''' <remarks>resets the countdownTimer</remarks>
        Public Sub cdReset()
            canUpDate = True
            tmr.Enabled = False
            tsElapsed = TimeSpan.Zero
            Me.Invalidate()
        End Sub
    
    End Class
    Note: this class code is not mine

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width