Solved

Label Control Array not working

Posted on 2003-12-10
8
752 Views
Last Modified: 2011-10-03
Hi,

Have converted from vb6 to vb.net

Have a control array for Label that works fine in a converted form.

When I try to copy all controls and code onto another form, the code breaks at the first instance of Me.Label(30).
When I change the code to Me._Label_30 it works fine.

The previous form (That I copied from) works fine with Me.Label(30).

Any ideas where I'm going wrong??

Stuart
0
Comment
Question by:StuartK
  • 3
  • 3
  • 2
8 Comments
 
LVL 48

Expert Comment

by:Mikal613
ID: 9912098
.NET does not Support Control Arrays anymore
0
 
LVL 48

Expert Comment

by:Mikal613
ID: 9912106
0
 

Author Comment

by:StuartK
ID: 9912634
Mikal613,

This is what the upgrade converter converted it to from vb6

Public WithEvents Label As Microsoft.VisualBasic.Compatibility.VB6.LabelArray

Public WithEvents _Label_26 As System.Windows.Forms.Label
Public WithEvents _Label_27 As System.Windows.Forms.Label
Public WithEvents _Label_29 As System.Windows.Forms.Label
Public WithEvents _Label_28 As System.Windows.Forms.Label

So control arrays are simulated in vb.net

This works on the converted from vb6 form. It's when I copy and paste all controls from that form to a new form that the errors happen



0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 48

Expert Comment

by:Mikal613
ID: 9912677
VB6 is not VB.NET what works in VB6 doen not mean it will work in VB.NET

label1(13) will work in VB6 not in .NET


http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbconcontrolarraychangesinvisualbasicnet.asp 


label1_13 is for .NET in place of the Array

0
 
LVL 1

Accepted Solution

by:
Tygur earned 50 total points
ID: 9913062
Apparently, there's something you failed to copy.  There should be something like this:
Me.Label = New Microsoft.VisualBasic.Compatibility.VB6.LabelArray(components)
CType(Me.Label, System.ComponentModel.ISupportInitialize).BeginInit()

Then after BeginInit() is called, there should be something to add those labels to the LabelArray:
Me.Label.SetIndex(_Label_26, CType(26, Short))
Me.Label.SetIndex(_Label_27, CType(27, Short))

Once all the labels are added, EndInit() should be called:
CType(Me.Label1, System.ComponentModel.ISupportInitialize).EndInit()

Of course, _Label_26, _Label_27, and the rest of them should be initialized before being added to the LabelArray.  By the way, this should all be done when the form is loading, but I think you knew that much.
0
 

Author Comment

by:StuartK
ID: 9913088
Hi,

But it is working on the form (IN VB.NET) that was originally converted over from vb6.

i.e. Me.Label(20).Visible works fine in VB.NET on converted form from vb6(lets say Frm_Original)

      Me.Label(20).Visible DOESN'T WORK on a newly added form(Frm_New) , after all controls from Frm_Original are copied over.

Me._Label_20.Visible WORKS on Frm_New

Label is declared as
Public WithEvents Label As Microsoft.VisualBasic.Compatibility.VB6.LabelArray

0
 
LVL 1

Expert Comment

by:Tygur
ID: 9913207
You need to copy the other lines that I mentioned, too, not just the declaration.  Did you do that?
0
 

Author Comment

by:StuartK
ID: 9913780
Tygur,

Thank you. It was the code in the style of

Me.Label.SetIndex(_Label_26, CType(26, Short))
Me.Label.SetIndex(_Label_27, CType(27, Short))

that was missing.

Thank you very very much.

And also to Mikel613 for his comments.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question