Solved

Label Control Array not working

Posted on 2003-12-10
8
749 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

777 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