Check boxes Generation

Hi,
This is a VB6 Question
I have labels on a form that are being generated dinamically, I need to be able to generate 10 check boxes dinamicaly for each label generated .
is this possible????


Thank you
NEW_INDIAAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike TomlinsonMiddle School Assistant TeacherCommented:
NEW_INDIA,

The code would look basically the same as the the sample I gave you that deals with only one checkbox.  Create a new project and add a Label.  To the right of the Label, add then CheckBoxes, Check1 thru Check10.  Now for the Label and all the CheckBoxes, set the Index property to 0 (zero):

Private Sub Command1_Click()
    Dim idx As Integer
    idx = Label1.Count
   
    Load Label1(idx)
    Label1(idx).Left = Label1(0).Left
    Label1(idx).Top = Label1(idx - 1).Top + Label1(idx - 1).Height + 15
    Label1(idx).Visible = True
   
    Load Check1(idx)
    Check1(idx).Left = Check1(0).Left
    Check1(idx).Top = Check1(idx - 1).Top + Check1(idx - 1).Height + 15
    Check1(idx).Visible = True

    Load Check2(idx)
    Check2(idx).Left = Check2(0).Left
    Check2(idx).Top = Check2(idx - 1).Top + Check2(idx - 1).Height + 15
    Check2(idx).Visible = True

    Load Check3(idx)
    Check3(idx).Left = Check3(0).Left
    Check3(idx).Top = Check3(idx - 1).Top + Check3(idx - 1).Height + 15
    Check3(idx).Visible = True

    ' Code repeats for Check4 thru Check9
    ' ...
    ' ...
    ' ...

    Load Check10(idx)
    Check10(idx).Left = Check10(0).Left
    Check10(idx).Top = Check10(idx - 1).Top + Check10(idx - 1).Height + 15
    Check10(idx).Visible = True
End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Shane Russell2nd Line Desktop SupportCommented:
Dim fso As New FileSystemObject
    Dim f As File
    Dim fsoStream As TextStream
    Dim Lines() As String
    Dim intPrev As Integer
    Dim LineCount As Integer
    Dim Lastchk As Integer
   
    Set f = fso.GetFile("c:\users.txt")
    Set fsoStream = f.OpenAsTextStream(ForReading)
   
    Lines() = Split(Trim(fsoStream.ReadAll), vbCrLf)
    'MsgBox ("No. of Lines: " & UBound(Lines))
   
   
   
    '
   
For i = 1 To UBound(Lines) + 1
intPrev = i - 1
Load chk(i)

'n = chk(i).Move(0, 10, "", "")
chk(i).Top = chk(intPrev).Top + chk(intPrev).Height
chk(i).Caption = "Checkbox " & i & Name
chk(i).Visible = True
'chk(0).Visible = False



Next i




    Set f = fso.GetFile("C:\users.txt")
    Set fsoStream = f.OpenAsTextStream(ForReading)
    ' Read the file line by line, printing the results to the Form
    Do While Not fsoStream.AtEndOfStream
   
       'ReDim strArray(cntLineCount)
       intLine = fsoStream.AtEndOfLine
        'Debug.Print strLine

       
        LineCount = UBound(Lines)
ReDim strArray(LineCount)
For x = 0 To LineCount
        strArray(x) = fsoStream.ReadLine
        'MsgBox strArray(i)
        'lblUsers(i).Caption = strArray(i)
        chk(x).Caption = "Save : " & strArray(x) & " ? "
        'Lastchk = UBound(x)
        chk(LineCount + 1).Visible = False
Next x
       
       

        cntLineCount = fsoStream.Line
       ' MsgBox cntLineCount
    Loop
    fsoStream.Close
    Set fsoStream = Nothing
    Set f = Nothing
    Set fso = Nothing
'===================================

I did it like that because when I put the items in the 2nd loop in the first loop it kept crashing out because it said it would pass the end of file. Because I added 1 to the UBound(Lines). I hope this helps :)

FYI - You need a reference to the Microsoft Runtime Scripting which you can do by going to Project --> References and checking the checkbox next to it in that list :)
0
Shane Russell2nd Line Desktop SupportCommented:
I forgot to mention that it reads the amount of lines from the text file and then that determines how many controls need to be created with regards to the checkboxes and then it loads each Name from the text file into each of the controls.

In the code, put this line of code in general declarations :

Private strArray() As String   '<-- This is the string array for holding all of the values
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Shane Russell2nd Line Desktop SupportCommented:
For this to work you need one checkbox which is called chk and you change the Index property from null to a 0 ( zero ) and then the coding does the rest with regards to creating the control :)
0
brckoslavCommented:
or you can use some sort of CheckedListBox
0
Shane Russell2nd Line Desktop SupportCommented:
New India, what is happening with this question, just out of curiousty :) ??
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.