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

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 303
  • Last Modified:

Check Boxes and Labels Generation

Hi smart people of the world,
Here is my problem:
I have 2 labels one under the other they are set as a column and I have 2 rows of 10 check boxes in front of them so

label    chk chk chk chk chk chk chk chk chk chk chk chk chk
label    chk chk chk chk chk chk chk chk chk chk chk chk chk

the labes are on a frame and the check boxes are on antoher frame
ok I have 2 set of labels with they respective check boxes, each label will be filled with text that will come from a file as caption, so then I can click on the check box I want those check boxes are 10 because I will use all of them with some other data here is my problem.

My question, I think some one already mention something to me about how to do this but I can not remember.
Can I generate more labels and more check boxes if necesary in the same order as these 2 are now? this is because now these are set fro 2 lines but if there is a new line in the text that I'm reading it will not be despalyed. so some how either I create maunal new label and new checkboxes or they could be generated dynamicaly.??

Thank you
0
NEW_INDIA
Asked:
NEW_INDIA
  • 3
  • 2
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Create a new project and add a Label, CheckBox and a CommandButton.  Set the Index property of the Label and the CheckBox to 0 (zero).  Paste the code below, run it, and hit the button several times:

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
End Sub
0
 
NEW_INDIAAuthor Commented:
Idle this is perfect but,
My bigest problem is that I would like if posible that as the txt file is open and I'm reading from it the system should be able to generate the labels and check required for the lines,
So I have a text file and I open it to read what's in it then if have 3 lines in the text file there should be 3 labels generated and 3 sets of check boxes , then if I add a new line to the textfile, there should be a new label box generated and a new check box set too.

is this possible????
Thanks
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
What you can do is simply create 1 label and 1 set of checkboxes.  These will all have an index of 0 (zero).  Start a counter at -1 and increment it each time you read in the lines from your file.  Then you can check this value against the upper bound of your label array.  If it exceeds the upper bound then you simply add more labels/checkboxes.  Something like:

    Dim i As Integer
    Dim ff As Long
    Dim inputLine As String

    i = -1    
    ff = FreeFile
    Open "D:\Theo\Users.txt" For Input As #ff
    While Not EOF(ff)
        Line Input #ff, inputLine
        i = i + 1
        If i > lbl.ubound Then
            Load lbl(i)
            lbl(i).Left = lb(0).Left
            lb(i).Top = lb(i - 1).Top + lb(i - 1).Height + 15
            lb(i).Visible = True

            ' do something similar for your checkboxes...

        End If
        lbl(i).Caption = inputLine
    Wend
    Close ff
0
 
NEW_INDIAAuthor Commented:
Sir,
this work perfect for the labes but now I'm on a problem,
now I have 10 lines in the text file so now I have 10 label boxes with names, this is perfect but now I have 1 check box and
I don't know how to change it so it can work for the check boxes too, also I have a command boton that was designed to check all boxes at the time now I have 10 labels 1 check box and if I click on check all it does not work enymore becasue the checkall.cmd have this
Public Function CheckAll()
'====================
Dim i As Single
i = 0
For i = 0 To 17
If chk(i).Value = vbChecked Then
chk(i).Value = vbUnchecked
Else
chk(i).Value = vbChecked
End If
Next
End Function
but this work no more ...

please help
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Change

    For i = 0 To 17

to

    For i = 0 To chk.ubound

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now