Wrox Programmer Forums
|
BOOK: Visual Basic 2005 Programmer's Reference
This is the forum to discuss the Wrox book Visual Basic 2005 Programmer's Reference by Rod Stephens; ISBN: 9780764571985
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Visual Basic 2005 Programmer's Reference section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 19th, 2006, 03:07 AM
Authorized User
 
Join Date: Jan 2006
Posts: 43
Thanks: 1
Thanked 0 Times in 0 Posts
Default Length of a Control Array

Hi, How to find the length of control array. pls guide me.

Thanks


 
Old September 19th, 2006, 08:07 AM
Rod Stephens's Avatar
Wrox Author
 
Join Date: Jan 2006
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
Default

VB .NET doesn't have control arrays so I presume you're using VB 6. There a control array has LBound and UBound properties that give its lower and upper bounds. For example, this code loops through the text box array named txtData:

    For i = txtData.LBound To txtData.UBound
        txtData.Text = ""
    Next i
If the array might be missing elements (i.e. you deleted one), see:

    http://vb-helper.com/howto_safe_control_arrays.html

HTH,

Rod


Rod
RodStephens@vb-helper.com
Author of "Visual Basic 2005 Programmer's Reference"
http://www.vb-helper.com/vb_prog_ref.htm

Sign up for the free VB Helper Newsletters at http://www.vb-helper.com/newsletter.html
 
Old September 19th, 2006, 11:18 PM
Authorized User
 
Join Date: Jan 2006
Posts: 43
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Ha, im sorry, my actual code is

dim lbl as label

do while ctr < 10
    lbl=new label
    lbl.setbounds(x...)
    me.addcontrols(lbl)
loop
' i actually want to remove the 10 instances of the label.
I try me.removecontrols, but i only remove it the added controls and not the instances.

so please

 
Old September 22nd, 2006, 08:12 AM
Rod Stephens's Avatar
Wrox Author
 
Join Date: Jan 2006
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
Default

How about:

    For i As Integer = Me.Controls.Count - 1 To 0 Step -1
        If TypeOf Me.Controls(i) Is Label Then
            Me.Controls.RemoveAt(i)
        End If
    Next

Rod


Rod
RodStephens@vb-helper.com
Author of "Visual Basic 2005 Programmer's Reference"
http://www.vb-helper.com/vb_prog_ref.htm

Sign up for the free VB Helper Newsletters at http://www.vb-helper.com/newsletter.html





Similar Threads
Thread Thread Starter Forum Replies Last Post
Control Array vikrantbaliyan Pro Visual Basic 2005 0 October 5th, 2007 05:38 AM
Is a control array useful for INSERT into a table? frresh VB Databases Basics 3 April 17th, 2007 01:41 PM
Array Static control ? n_quoc_tuan Visual C++ 1 July 27th, 2004 04:32 AM
control array of textbox greatmanu Excel VBA 1 October 24th, 2003 09:36 AM
Dynamic Control array carl.dufresne@sita.aero Visual C++ 6 September 3rd, 2003 08:48 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.