Unable to create Control Array in VB6

Started by geneschneider, May 24, 2007, 05:25:51 AM

Previous topic - Next topic

geneschneider

That is becoming more evident as I learn more about Visual Basic. A few weeks ago I purchased a book Sam's Teach Yourself Visual Basic 6 which came with a companion CD. The CD is a learners edition which will not allow one to compile. Because I was using VBA through Excel I never installed the software. Late last evening I installed the software and tried to create a control array. It worked exactly as the books say it is suppose to. So it appears the VBA doesn't support control arrays. I'll have to try to export my form into the new software to continue with my programming. Once near completion I will purchase either the standard edition or the professional edition of VB6. Which do you think I should buy?
Thanks again for your help. Gene

Randem

That's VBA not VB6 and it is a cut down version of VB.

geneschneider

The VB I am using is what is available when you open a spreadsheet and then press the F11 key. It says Microsoft Visual Basic 6.0 so I do not know what VBE is. I don't know if it creates an exe file or not. Does the code you supplied creates ten frames and ten labels? I would like to use a dynamic array that will place the labels in a single frame, consisting of a matrix 10 wide by how many long depending on how many laps our race is. Some are 60 laps, some are 350 laps depending on the track. I will take your coding home and place it in my application and see what it creates.
 
Thanks

Randem

The code in the form looks like this:
 
Option Explicit
Option Compare Text
 
Private Sub Form_Load()
Dim i As Integer
Dim ctl As Control
 
 
For i = 1 To 10
 
   Load Frame1(i)
   With Frame1(i)
      .Top = Frame1(i - 1).Top   1000
      .Visible = True
      .Caption = Frame & i   1
      .ZOrder
   End With
   
   Load Label1(i)
   Set Label1(i).Container = Frame1(i)
   Label1(i).Caption = Label & i   1
   Label1(i).Visible = True
   Label1(i).ZOrder
   
   
Next i
 
End Sub
 
All that was needed was to create the first label/frame on the form.

Randem

No, you need to create a control array either dynamically or thru the IDE. The simpliest way thru the IDE is to copy and paste the same control. The IDE will ask you if you want to create a control array, answer yes. But with 384 items I would not do it that way. Use the method in the project to dynamically create the control array.
 
I have never heard of VBE unless that is the student edition. If that is the student edition you will not be able to create an exe from it.

geneschneider

I was hoping you could tell me! Did you get my post number 3? Here is my question, Is lblLap1 the same as lblLap(iLapCounter)if the value of iLapCounter was 1? I guess what I'm trying to determine is if I call all my labels lblLap what or how do I assign the index to the actual label?

Randem

You are supposed to open the Project1.vbp file only in VB6. What is VBE?

geneschneider

second note...
 
I tried to open the file Form1.frm and received an error message that the file is not supported by VBE? The file can not be loaded!. How do I open this file and the other two, Project1.vbp and Project1.vbw

geneschneider

Thanks for the coding. It is what I had in mind. However, when I create the labels I do not get the message You already have a control named lblLap. Do you want to create a control array? When I try to name the label in the properties window as lblLap() I get a warning message that I can't do that. How do I create the control array to begin with? There must be something simply that I am missing that I don't understand. Thanks again for your help. I'll look at your Dynamic Control Code. Maybe that will clarify it. Oh by the way, the 348 labels will be contained in a frame that I can scroll up or down as needed.

Randem

The you are using the index for the control already. Just change it a bit like this:
 
gasngLap(iLapCounter) = ActiveCell.Value
lblLap(iLapCounter) = gasngLap(iLapCounter)
lblLap(iLapCounter).BackColor = sngColor
lblLap(iLapCounter).Caption = Format(lblLap(iLapCounter), Fixed)  
 
Here is something that should help also. It's a project that creates controls dynamically. I think this is best since you have 348 lables and such (where are you showing these labels on a large screen TV?!?)
 
Dynamic Control Loading
https://randemsystems.com/freeware.html#Dynamic%20Control%20Loading

geneschneider

Forgive me, I am not a programmer. Just someone very interested in VB. I believe I am attemping it inside IDE. I am trying to record laps at a race track. As the car crosses the start finish line the flag is either green, yellow or red. Some races are 300 laps and I believe I can use the control array to index the value by 1 every lap. Thus using a fairly small procedure. Below is the global array and the Case statement. lblLap1 etc is where I will write the lap time and change color of the background according to the race condition. I believe the lap counter I have can be used as the index for the array. But again I am not a programmer and do this out of a labor of love. Let me know if you need any other information.
 
Public gasngLap(350) As Single  'Global Array of 350 locations
 
Public Sub WriteLapTimes(iLapCounter, sngColor)
 
Select Case iLapCounter
 
        Case Is = 1
            gasngLap(1) = ActiveCell.Value
            lblLap1 = gasngLap(1)
            lblLap1.BackColor = sngColor
            lblLap1.Caption = Format(lblLap1, Fixed)
     
       Case Is = 2
            gasngLap(2) = ActiveCell.Value
            lblLap2 = gasngLap(2)
            lblLap2.BackColor = sngColor
            lblLap2.Caption = Format(lblLap2, Fixed)
 
     'Copy and paste for 348 times! I hope not!}

Randem

All control arrays contain an Index property. Please post your code. Are you attempting to create this control array dynamically or inside the IDE?

geneschneider

I am trying to create a Control Array (using either a label or text box)and have not been successful. In am developing a spreadsheet in Excel 2000 using the VB6 software that comes with the Microsoft Office package. All the articles I have read say I need to use the Index property, yet I can not find that property. I have created a standard array which works. What am I missing?