Solved

Label Control Array not working

Posted on 2003-12-10
8
744 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
 
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

707 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now