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
Medium Priority
221 Views
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
Question by:NEW_INDIA
• 4

LVL 86

Accepted Solution

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

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

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

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

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
' ...
' ...
' ...

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

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")

'MsgBox ("No. of Lines: " & UBound(Lines))

'

For i = 1 To UBound(Lines) + 1
intPrev = i - 1

'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")
' 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
'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

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

LVL 23

Expert Comment

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

ID: 13493730
or you can use some sort of CheckedListBox
0

LVL 23

Expert Comment

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

## Featured Post

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
###### Suggested Courses
Course of the Month14 days, 6 hours left to enroll