Solved

Label Control Array not working

Posted on 2003-12-10
8
760 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Get Actionable Data from Your Monitoring Solution

Your communication platform is only as good as the relevance of the information you send. Ensure your alerts get to the right people every time with actionable responses. Create escalation rules that ensure everyone follows the process and nothing is left to chance.

 
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

Turn Insights into Action

Communication across every corner of your business is essential to increase the velocity of your application delivery and support pipeline. Automate, standardize, and contextualize your communication processes with xMatters.

Question has a verified solution.

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

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

691 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