Solved

Create Run Time controls

Posted on 2003-11-19
3
334 Views
Last Modified: 2010-05-01
I'm developing a project in visual basic 6.
I want to create a form with author information like name, qualification, article etc.
I have created one frame in a form and in this frame I placed labels and textboxes for entering author information.
like the following

Name    Qualification     Article
textbox   textbox           textbox

I don't know how many author entries are there for a record.
so I want to add one command 'Add' next to the frame, to add the next textboxes for entering the  next author's values and so on.

like

Name    Qualification     Article
textbox   textbox           textbox
textbox   textbox           textbox
Name    Qualification     Article
textbox   textbox           textbox
:
:
:


and when the list grows out of the given  frame size then I want to add one vertical scroll  bar so that user can scroll up and down to see the textboxes and can fill up the values.

How this is possible in visual basic.
anyone have any idea

thanks in advance

SS
0
Comment
Question by:ssonia27
3 Comments
 
LVL 3

Expert Comment

by:NBrownoh
Comment Utility
to show you how  to create things at runtime, i did this with a command button named command1, they have to have an index, so this starts at 1:
    Load Command1(Command1.Count + 1)
    TMany = Command1.Count
    Command1(TMany).Top = Command1(TMany - 1).Top + Command1(TMany - 1).Height + 120
    Command1(TMany).Visible = True

but that in a button and click away.

then to check if its gone out of the screen there, just do somethin like:
if yourlasttextbox.height + yourlasttextbox.top >= yourform.height then
  scrollbar1.visible = true
end if

change the names as recquired.
0
 
LVL 19

Accepted Solution

by:
Rimvis earned 125 total points
Comment Utility
NBrownoh is basicaly right. You need to create control array. First memberof array must be allready placed at design time, others can be added at run time

Save following code as Form1.frm and include it in your project, it includes crolling code to:


VERSION 5.00
Begin VB.Form Form1
   Caption         =   "Form1"
   ClientHeight    =   3540
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   3675
   LinkTopic       =   "Form1"
   ScaleHeight     =   3540
   ScaleWidth      =   3675
   StartUpPosition =   3  'Windows Default
   Begin VB.PictureBox picBoxes
      BorderStyle     =   0  'None
      Height          =   2895
      Left            =   240
      ScaleHeight     =   2895
      ScaleWidth      =   3255
      TabIndex        =   4
      Top             =   480
      Width           =   3255
      Begin VB.VScrollBar vscBoxes
         Height          =   2895
         Left            =   2880
         Max             =   0
         TabIndex        =   8
         Top             =   0
         Visible         =   0   'False
         Width           =   255
      End
      Begin VB.TextBox txtName
         Height          =   285
         Index           =   0
         Left            =   0
         TabIndex        =   7
         Text            =   "0"
         Top             =   0
         Width           =   735
      End
      Begin VB.TextBox txtQualification
         Height          =   285
         Index           =   0
         Left            =   840
         TabIndex        =   6
         Top             =   0
         Width           =   975
      End
      Begin VB.TextBox txtArticle
         Height          =   285
         Index           =   0
         Left            =   1920
         TabIndex        =   5
         Top             =   0
         Width           =   855
      End
   End
   Begin VB.CommandButton cmdAdd
      Caption         =   "Add"
      Height          =   255
      Left            =   3000
      TabIndex        =   3
      Top             =   120
      Width           =   495
   End
   Begin VB.Label Label3
      Caption         =   "Article"
      Height          =   255
      Left            =   2160
      TabIndex        =   2
      Top             =   120
      Width           =   1095
   End
   Begin VB.Label Label2
      Caption         =   "Qualification"
      Height          =   255
      Left            =   1080
      TabIndex        =   1
      Top             =   120
      Width           =   1215
   End
   Begin VB.Label Label1
      Caption         =   "Name"
      Height          =   255
      Left            =   240
      TabIndex        =   0
      Top             =   120
      Width           =   1335
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private iItems As Integer

Private Sub cmdAdd_Click()
    iItems = iItems + 1
    Load txtName(iItems)
    txtName(iItems).Top = txtName(iItems - 1).Top + txtName(iItems - 1).Height + 80
    txtName(iItems).Visible = True
    Load txtQualification(iItems)
    txtQualification(iItems).Top = txtQualification(iItems - 1).Top + txtQualification(iItems - 1).Height + 80
    txtQualification(iItems).Visible = True
    Load txtArticle(iItems)
    txtArticle(iItems).Top = txtArticle(iItems - 1).Top + txtArticle(iItems - 1).Height + 80
    txtArticle(iItems).Visible = True
   
    txtName(iItems) = iItems
   
    If txtName(iItems).Top + txtName(iItems).Height > picBoxes.Height Then
        vscBoxes.Visible = True
        vscBoxes.Max = vscBoxes.Max + 1
    End If
   
   
End Sub

Private Sub vscBoxes_Change()
    Dim i As Integer
    For i = 0 To iItems
        txtName(i).Top = (txtName(0).Height + 80) * (i - vscBoxes.Value)
        txtQualification(i).Top = txtName(i).Top
        txtArticle(i).Top = txtName(i).Top
    Next i
End Sub
0
 

Author Comment

by:ssonia27
Comment Utility
thanks Rimvis It seems that my porblem will be solved by this code
i'll go through it and then tell you.
thanks NBrownoh,  is also right and telling the same idea for addign runtime controls

thanks

SS
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

728 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

9 Experts available now in Live!

Get 1:1 Help Now