Vb6 ch.6-3 cci

Uploaded on


More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads


Total Views
On Slideshare
From Embeds
Number of Embeds



Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

    No notes for slide


  • 1. VISUAL BASIC 6 – 3 CUBE COMPUTER INSTITUTE (3CCI) Chapter 6 Multiple FormsAdding Form to a ProjectSteps for adding a form to a project: 1. Select Project Menu from VB6 Menu bar. 2. Choose Add Form. 3. Select Form from the Add Form Dialog Box.--------------------------------------------------------------------------------------------------------------------------------------The Hide and Show MethodsDisplay a form with a Show method and conceal a form with the Hide Method.Show Method General form - FormName.Show [Style] The optional style determines whether the form will display modeless or modal. The values for Style can be 0-modeless and 1-modal, default is 0. You can also use VB intrinsic constants; vbModal and vbModeless. When the form is displayed as modal, the user must respond to the form in some way. No other code can execute until the modal form has been responded to and hidden or unloaded. If the form is displayed as modeless, the user may switch to another form.Examples frmMain.Show 1 frmMain.Show vbModal frmMain.Show vbModeless frmMain.ShowHide Method General Form – FormName.Hide Hide method is used to remove a form from the screen.Example – frmMain.Hide---------------------------------------------------------------------------------------------------------------------------Form_Load and Form_ActivateThe first time a form is displayed in a project, VB generates two events—a Form_Load andForm_Activate.The Form_Load event calls the form module into memory. 1
  • 2. VISUAL BASIC 6 – 3 CUBE COMPUTER INSTITUTE (3CCI)The Form_Activate event occurs after the Form_Load event, just as control is passed to theForm. Each time the form is shown the Form_Activate event occurs and not the Form_Loadevent.---------------------------------------------------------------------------------------------------------------------------Me KeywordThe current form can be referred by using the special Keyword Me.Me acts like a variable and refers to the current active form.Use Me in place of Form name when coding form statements and methods. Example: Unload Me Me.Hide---------------------------------------------------------------------------------------------------------------------------Load and Unload StatementsLoad – When you show a form, the Load is done automatically. The only time you will code a Load statement is when you want to load a form but not display.General Form – Load FormNameExample: Load frmLogInUnload –To remove a form from the screen, hide it unload it. Hiding a form removes it from the screen, but the form still remains in the memory. If you do not need the form for further execution, the best way is to unload the form.General form – Unload FormNameExample: Unload frmLogin---------------------------------------------------------------------------------------------------------------------------Example of SHOW/ HIDE and LOAD /UNLOADStandard Code ModuleA Standard Code Module is a basic procedure with the extension .bas which is added to theproject.Standard code module does not contain Form Window. It only contain a Code window. Astandard code module has general declaration section and procedure just like form module. 2
  • 3. VISUAL BASIC 6 – 3 CUBE COMPUTER INSTITUTE (3CCI)They can contain global (available to the whole application) or module-level declarations ofvariables, constants, types, external procedures, and global procedures.Standard Code Module is visible to all procedures in the module but not to procedure inthe form module.Adding a Standard Code Module to ProjectSteps for adding a Standard Code Module to a project: 1. Select Project Menu from VB6 Menu bar. 2. Choose Add Module. 3. Select Module from the Add Module Dialog Box.---------------------------------------------------------------------------------------------------------------------------Global/ Public VariablesIf you want variables and constants to be accessible to more than one form in the project, theymust be global variables. To declare global variables, use the Public statement in place of theDim statement.General form – Public Identifier [As Datatype] Public Const Identifier [As Datatype] = Value A public variable or constant has a prefix of g.Static VariablesStatic variables retain their value for the life of the project, rather than being initialized for eachcall to a procedure. If you need to retain the value in a variable for multiple calls to a procedure,such as a running total, declare it as Static.General form – Static Identifier [As DataType] Static statements can appear only in procedures; Static statements never appear in the GeneralDeclarations section of a module. Static variables do not require a scope prefix, since all staticvariables are local.---------------------------------------------------------------------------------------------------------------------------Setting the Startup FormBy default, the first form in your application is designated as the startup form. When yourapplication starts running, this form is displayed.If you want a different form to display when your application starts, you must change thestartup form.To change the startup form 1. From the Project menu, choose Project Properties. 2. Choose the General tab. 3. In the Startup Object list box, select the form you want as the new startup form. 4. Choose OK.--------------------------------------------------------------------------------------------------------------------------- 3
  • 4. VISUAL BASIC 6 – 3 CUBE COMPUTER INSTITUTE (3CCI)Starting Without a Startup Form : SUB MAIN()Sometimes you might want your application to start without any form initially loaded.For example, you might want to execute code that loads a data file and then displays one ofseveral different forms depending on what is in the data file.You can do this by creating a Sub procedure called Main in a standard module, as in thefollowing example: Sub Main() frmSplash.Show vbModeless Load frmMain End SubThis procedure must be a Sub procedure, and it cannot be in a form module.To set the Sub Main procedure as the startup object, from the Project menu, choose ProjectProperties, select the General tab, and select Sub Main from the Startup Object box.---------------------------------------------------------------------------------------------------------------------------Displaying a Splash Screen on StartupIf you need to execute a lengthy procedure on startup, such as loading a large amount of datafrom a database or loading several large bitmaps, you might want to display a splash screen onstartup.A splash screen is a form, usually displaying information such as the name of the application,copyright information, and a simple bitmap. The screen that is displayed when you start VisualBasic is a splash screen.To display a splash screen, use a Sub Main procedure as your startup object and use the Showmethod to display the form: Private Sub Main() Show the splash screen. frmSplash.Show Add your startup procedures here. … Show the main form and unload the splash screen. frmMain.Show Unload frmSplash End SubThe splash screen occupies the users attention while your startup routines are executing, givingthe illusion that the application is loading faster. When the startup routines are completed, youcan load your first form and unload the splash screen.Adding a Splash Screen to ProjectSteps for Adding a Splash Screen to Project: 1. Select Project Menu from VB6 Menu bar. 2. Choose Add Form. 3. Select Splash Screen from the Add Form Dialog Box. 4
  • 5. VISUAL BASIC 6 – 3 CUBE COMPUTER INSTITUTE (3CCI)---------------------------------------------------------------------------------------------------------------------------Displaying a About BoxAdding an About Box to ProjectSteps for Adding a About Box to Project: 1. Select Project Menu from VB6 Menu bar. 2. Choose Add Form. 3. Select About Box from the Add Form Dialog Box.About Box contains the Application Title, Version, and App Description placeholders withinformation specific to your application. 5