Solved

VB6 large frame with scroll bar

Posted on 2004-09-12
16
7,770 Views
Last Modified: 2009-02-03
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
0
Comment
Question by:inimicaljords
  • 4
  • 4
  • 4
  • +3
16 Comments
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 12041150
Try put your chekboxes controls into a picturebox instead..
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 12041158
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
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 12041162
0
 
LVL 19

Expert Comment

by:arif_eqbal
ID: 12041254
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.....

0
 
LVL 1

Expert Comment

by:surturz
ID: 12041294
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




0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 12044751
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
0
 
LVL 32

Expert Comment

by:Erick37
ID: 12044962
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.
0
 
LVL 1

Author Comment

by:inimicaljords
ID: 12050051
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?
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 32

Expert Comment

by:Erick37
ID: 12050117
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
0
 
LVL 1

Expert Comment

by:surturz
ID: 12050295
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
0
 
LVL 1

Expert Comment

by:surturz
ID: 12050324
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
0
 
LVL 1

Author Comment

by:inimicaljords
ID: 12050704
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.

0
 
LVL 1

Author Comment

by:inimicaljords
ID: 12050741
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
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 12050809
try like:

...
if list1.list(1) = "name of list" then
addfile
Else
deletefile
...
0
 
LVL 1

Author Comment

by:inimicaljords
ID: 12050914
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
0
 
LVL 1

Accepted Solution

by:
surturz earned 500 total points
ID: 12051470
I'd suggest you read the help file on the ListBox, as it seems you don't have much experience with it.

If you want to change an item in the list, use the "List" property. e.g. List1.List(99) = "Hello" will set the 100th item to "Hello"

Whether a particular checkbox is checked is determined by the "Selected" property.
e.g. If List1.Selected(99) = True then the 100th checkbox is checked (since we start counting at zero)

You can't put separate code for each checkbox, since it is actually one list control. You have to test every item in the list using a command button. Likewise, to clear the checks you need to go through every item as well.

I have written a short example below. It adds three items to the list. The user checks one or more and then clicks the command button. It changes the label to "Sent" for those that are checked.

Hope this helps,
-David

Create a new project, add a listbox called "List1" and set its Style property to "Checkbox", add a Command Button called "Command1". Then paste in the following code:

Sub Form_Load()
    List1.Clear 'Clears the list

    List1.AddItem "Send to David" 'put an item in the list
    List1.AddItem "Send to Jordan" 'put an item in the list
    List1.AddItem "Send to William" 'put an item in the list
End Sub

Private Sub Command1_Click()
   
    If List1.Selected(0) Then Call SendToDavid
    If List1.Selected(1) Then Call SendToJordan
    If List1.Selected(2) Then Call SendToWilliam
   
    Call ClearChecks
End Sub

Sub SendToDavid()
    List1.List(0) = "Sent"
End Sub

Sub SendToJordan()
    List1.List(1) = "Sent"
End Sub

Sub SendToWilliam()
    List1.List(2) = "Sent"
End Sub

Sub ClearChecks()
    Dim i&
    For i& = 0 To List1.ListCount - 1
        List1.Selected(i&) = False
    Next i&
End Sub
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now