Link to home
Start Free TrialLog in
Avatar of inimicaljords
inimicaljordsFlag for United States of America

asked on

VB6 large frame with scroll bar

I am making a program that has a lot of checkboxes.  What I have set up is 2 frames, one inside of the other, with a lot of checkboxes and a scrollbar to scroll up and down.  The problem that I have is that I have around 1300 checkboxes that I have to make. In-order to make it so that I can have scroll bars is to put a frame inside of a frame(thats the only way I know).  I found out that the frame height has a maximum limit of about 11520. I filled up one whole colum with only 40 checkboxes.  Since i have such a high volume there is no way to fit all 1300 checkboxes into that frame and make it viewable.  

Is there any other way to make it so I can put all the checkboxes into one frame with just a vertical scroll bar?

Appreciate the help.

Jordan
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Try put your chekboxes controls into a picturebox instead..
Examples:

Create a Scrollable Form
http://www.thescarms.com/vbasic/ScrollForm.htm

Adding Scroll Bars to Forms, PictureBoxes and User Controls
http://vbaccelerator.com/codelib/ssubtmr/sbrclass.htm

http:Q_10301080.html
Avatar of arif_eqbal
arif_eqbal

Well you can add the checkBoxes Dynamically....

On the Form or on the Frame put a vertical scroll bar and say 20 check boxes on the scrolling of scroll bars move the check boxes up by setting their top property and once they are out of the form or frame area you can store their value in an array and destroy them, also when the checkbox goes uot of frame area a new one will become visible at the bottom and so on.....

If you have 1300 checkboxes, I would suggest that putting them all on one scrolling frame is not very user friendly. I would group them by category if possible, and using "pages" instead of scrolling.

I would create a control array of checkboxes. In fact, to save having to manually add them to the form and position, I would create a single checkbox and use a formula to add the other checkboxes at run time (here's a gotcha - VB6 sets the .Visible property to False on any controls created at run time).

For example, create a new project, add a checkbox called Check1 to the form and set its .Index property to zero. Then add the following code to Form_Load

Private Sub Form_Load()
    Dim Row&, Col&
    Dim Rows&, Cols&
       
    Rows& = 10: Cols& = 10
    For Row& = 0 To Rows& - 1
        For Col& = 0 To Cols& - 1
            If Not (Row& = 0 And Col& = 0) Then
                Load Check1(Cols& * Col& + Row&)
                With Check1(Cols& * Col& + Row&)
                    .Visible = True 'N.B. VB6 sets .Visible property to FALSE by default for controls added at run time
                    .Left = Check1(0).Left + Check1(0).Width * Col& * 1.05 '5% gap between each
                    .Top = Check1(0).Top + Check1(0).Height * Row& * 1.05
                End With
            End If
        Next Col&
    Next Row&
   
End Sub

This will give you a nice grid of checkboxes (you'll need to fiddle the number of rows and columns and the gap factor to make it look nice). You then set the .Caption of each control (use the formula Cols& * Col& + Row& for the index of the check box e.g. Cols& * 1 + 1 for the second checkbox in the second row - we start counting from zero on both axes).

Once the user has set the first hundred options, they click a command button (e.g. "Next Page"), and you save the 100 results (e.g. to a module level boolean array with 1300 elements). You then reset all the checkbox values and redefine the captions for the second 100 results, and so on until they have set all 1300 options.

Hope this helps,
-David




Have you think about to use listview instead so that you can enable checkbox for 1300?

I think it is more dynamic way to list 13000 checkbox
How did you determine that there was a limitation to the height of the frame control?

There is a limitation (in VB) to the size of a form based on your screen settings (which can be overcome), but it doesn't appear that that limitation applies to controls inside the form.

Are you getting that number by setting the form height in code, then applying Frame1.Height = Form1.ScaleHeight ??
If so, then there would be an apparent limitation since Windows has restricted the size of your form.
Avatar of inimicaljords

ASKER

Erick, i have it set up that way. have the frame the same size as the maximum form then on load has it change to make it smaller.  

I don't really prefer a list view.  I just want a vertical scroll to go up and down.

I don't know how to create the boxes dynamically.  Anyone mind to help explain that as well.  1300 boxes is a lot, they all have if statements, if checked then ... else ...  How would I make it dynamically?
Erick, i have it set up that way<<<

Set the frame size during design time, or runtime - but not based on the dimensions of your form.

Some more interesting reading...
"INFO: Maximum Number of Controls on a Form"
http://support.microsoft.com/default.aspx?scid=kb;en-us;229756
My code above shows you how to create controls dynamically. As I mentioned, a trap for newbies is that the "Visible" property is set to FALSE for controls created at run time.

However, I think EDDYKT's suggestion is better. Use a listbox instead. If you set the "Style" property to "Checkbox", you can easily have 1300 checkboxes inside it.

-David
Followup.. example of using a listbox full of checkboxes.

1) Create a new standard project
2) Add a listbox to the form called List1, and set its Style property to "Checkbox"
3) Add a command button to the form called Command1
4)Insert the following code into the form:

Option Explicit

Private Sub Form_Load()
    Dim i&
       
    List1.Clear
    For i& = 1 To 1300
        List1.AddItem Format(i&)
    Next i&
End Sub

Private Sub Command1_Click()
    Dim i&
   
    For i& = 0 To List1.ListCount - 1
        If List1.Selected(i&) Then MsgBox List1.List(i&)
    Next i&
   
End Sub

5) Run the program, check a few checkboxes and click the command button. It will msgbox each checked item.

-David
David, That is a much better way than what I was doing but I still have a few questions about added the list dynamically.  I have never tried anything with a listbox,but I like it alot!

1) In the code it says 1 to 1300 which it creates a name from 1 to 1300.  I understand that completely but am wanting to figure out if there was a way to change there name dynamically.  like if I put all 1300 names into the code and say listbox 1 name = "whatever" and continue on untill all 1300 are there.  Will that work?

2) I also want each one of them to do a different code.  Basically, I want them to add an item if check and if uncheck delete an item and have a command to check all and uncheck all.  I am unsure on how to put the if statements for each checkbox since there are no actual checkboxes.  

I was totally unaware that you could do the checkboxes in the listbox.  I am learning a lot from all of you!  Thanks a bunch!  All of you guys are awesome.

ignore the first question i figured it out by using

List1.AddItem "name of list"

but still not sure how to do an if statement for it.

is it like
if list1.addItem "name of list" = 1
    addfile
    Else
    deletefile
try like:

...
if list1.list(1) = "name of list" then
addfile
Else
deletefile
...
List1.Clear
   
List1.AddItem Format(i&)
       
If List1.List(1) = 1 Then
createfile
Else
deletefile
End If

this does not work. also when i do list1.additem "item" it doesn't make it a checkbox it does the standard but if i do the list1.additme format(i&) it does the checkbox but i can't name it
ASKER CERTIFIED SOLUTION
Avatar of surturz
surturz

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial