Solved

Create Run Time controls

Posted on 2003-11-19
3
335 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
ID: 9777252
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
ID: 9777367
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
ID: 9777410
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

773 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