Showing posts with label Introduction to Visual Basic. Show all posts
Showing posts with label Introduction to Visual Basic. Show all posts

Tuesday, September 15, 2020

Creating Menus in VB

Menu bar is one of the foundation controls in any window based application.  The list of menus is a display in the menu bar.  The menu options are display when the individual menu is clicked.

The menu editor is used to create the menu on the form.

To display the menu editor:

Right click on the form and select the option Menu Editor from the menu displayed.

Menu Editor Dialogue Box:

 


 Allow you to create custom menu for your application and to define their properties.

Dialogue Box Options:

Caption:  Allow you to enter the menu or command name that you want to appears on your menu bar or in a menu.

Name: Allow you to enter a control name for the menu item. A control name is an identifier used only to access the menu item in code; it doesn't appear in a menu.

Shortcut:

 Allow you to select a shortcut key for each command. i.e.  the combination with Ctrl  key.

E.g.  Shortcut to save command is Ctrl+S 

Checked:

Allow you to have a check marks appear initially at the left of a menu item.  It is generally used to indicate whether a toggle option is turned on or off.

Enabled:

Allow you to select whether you want the menu item to respond to event, or clear if you want the item to be unavailable and appears dimmed.

Visible:

 Allow you to have the menu item appears on the menu.

Right arrow:

Moves the selected menu down one level each time you click it.  You can create up to four level of submenu.

Left Arrow:

Move the selected menu up one level each time you click it. You can create up to four level of submenu.

Down Arrow:

Move the selected menu item down one position within the same menu label each time you check it.

Menu List:

A list box that displays a hierarchical list of menu items. Submenu items are intended to indicate their hierarchical position or level.

Next:

 Moves selection to the next line

Insert:

 Insert a line in the list box above the currently selected line

 Delete:

Delete the currently selected line

Ok:

Closes the Menu Editor and applies all changes to the last for you selected.

Cancel:

Closes the Menu Editor and cancels all changes.

Step to create menus as a displayed on the following form:

 


  

  1. Right click on the form and select the option Menu Editor from the menu displayed
  2. Enter the caption and name of the main menu ‘Abcd’.
  3. Click on the next button.
  4. Enter the name and caption of the menu item ‘a’
  5. Since ‘a’  is a menu option and not the main menu,  it is to be preceded with dots hence click on the right arrow button(->) to place the dots ahead of it.
  6. Click on the Next button
  7. Enter the name and caption of the menu item  ’b’
  8. Click on the Next button
  9. Enter the name and caption for the item ‘x’.  Since ‘x’ is a submenu of the menu item ‘b’ and hence it is to be preceded with double the number of dots.  Click on the right arrow button(->)
  10.  Click on the Next button.
  11.  Enter the name and caption of menu ‘y’
  12. Click on next button.
  13. Enter the name and the caption of menu ‘c’
  14. To remove the additional dots head of the menu ‘c’ click on the left arrow button (<-).

Popup Menus:

A menu which is displayed, when the control click with the right mouse button is called as popup menu.

A popup menu is a floating menu that is display over a form, independent of the menu bar.  The items displayed on the popup menu depend on where the pointer was located when the right mouse button was pressed; therefore, popup menus are also called as context menus.

Syntax to display the popup menu is as follows:

object.popupMenu  menuname

Program to display the pop-up menu when the command is right  clicked.

Create a menu in the menu editor.  Set the visible property of the menu false in the menu editor

Use the popup menu method in the mouse down event of the control to display the menu  when the control is right  clicked.

Privates Sub Button1_ MouseDown( Button as integer,  Shift as integer,  X as Single , Y as Single)

If Button =2 Then

Popupmenu  abcd

End if

End sub



Tuesday, September 1, 2020

Modules in VB:

Form Module: The form that you can see on the screen is a representation of the properties that define its appearance and behavior of a component place on it.  For each form in an application there is a related form module that contains its code.

Each form module contains event procedure which is a section of the code where you place the instruction that will execute in response to specific event.  Form can contain controls.  For each control on the form there is a corresponding state of event procedure in the form module.  In addition to the event procedure, form module can contain the general procedure that is executed in response to a call from any event procedure.

To add a new form to the project, from the project menu select the option “Add Form”, selected type of the form and click on open button.

Standard Module:

This standard module can be used to declare the global data and the global methods which can be accessed anywhere in the project or an application.

Code that isn't related to a specific form control can be place in a different type of module, standard module (.BAS)

To add a standard module into the project, from the project menu select an option “Add Module”, and click on “open” button

Class Module:

A class module is used to create object that can be called from procedure within your application.  Where as a standard module contain only code, a class module contain both code and data.

The members in the class module can only be accessed through its object.  One class can be defining in one class module.

To add a new Class module to the project, from the project menu select the option “Add Class Module”, select the type of the class and click on open button.

By default, your project contains a single form module.  User can add additional form, class and standard module, as needed.


Saturday, August 29, 2020

Format, Math & Conversion Functions in Visual Basic:

Format Functions:

  Print format(“15/8/47”, “d/m/yy”) gives 15/8/47

  Print format(“15/8/47”, “dd/mm/yy”) gives 15/08/47 

  Print format(“15/8/47”, “ddd/dd/mmm/yy”) gives fri/15/aug/47 

  Print format(“15/8/47”, “dddd/dd/mmmm/yyyy”) gives Friday/15/August/2047 

  Print format(“Time”, “h:m:s am/pm”) gives Current time in 12 Hour format 

  Print format(“Time”, “hh:mm:ss am/pm”) gives Current time in 24 hours format

  Format(5459.4, ”##,##0.00”) gives “5,459.40”

  Format(334.9, ”##0.00”) gives “334.90”

  Format(“Hello”,”<”) gives “hello”

  —  Format(“Hello”,”>”) gives “HELLO” 


Conversion Functions:

Math Functions: