Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Label Control Array not working

Posted on 2003-12-10
8
Medium Priority
?
777 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
 

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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
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 200 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

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

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

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Integration Management Part 2
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

916 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