Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Check boxes Generation

Posted on 2005-03-08
8
Medium Priority
?
221 Views
Last Modified: 2010-04-17
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
0
Comment
Question by:NEW_INDIA
  • 4
6 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 13486372
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
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 13488277
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
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 13488307
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 23

Expert Comment

by:gecko_au2003
ID: 13488314
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
 
LVL 3

Expert Comment

by:brckoslav
ID: 13493730
or you can use some sort of CheckedListBox
0
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 13540845
New India, what is happening with this question, just out of curiousty :) ??
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Screencast - Getting to Know the Pipeline

580 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