0% found this document useful (0 votes)
9 views8 pages

Visual Programming 5 Marks

The document outlines various aspects of Visual Basic (VB) programming, including steps for creating a new project, string functions, static arrays, common controls, dialog boxes, file system objects, and menu creation. It also discusses properties of command buttons, toolbox tools, built-in functions, error trapping methods, and the use of common dialog boxes. Additionally, it covers controls like ComboBox, MDI forms, OLE drag and drop, and provides examples for better understanding.

Uploaded by

calistaugin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views8 pages

Visual Programming 5 Marks

The document outlines various aspects of Visual Basic (VB) programming, including steps for creating a new project, string functions, static arrays, common controls, dialog boxes, file system objects, and menu creation. It also discusses properties of command buttons, toolbox tools, built-in functions, error trapping methods, and the use of common dialog boxes. Additionally, it covers controls like ComboBox, MDI forms, OLE drag and drop, and provides examples for better understanding.

Uploaded by

calistaugin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

1.

Write the steps to create a new project in VB:

1. Open Visual Basic or Visual Studio.


2. Click on File > New Project.
3. Select the project type, e.g., Windows Forms Application.
4. Give a project name and choose the location to save.
5. Click OK.
6. The project opens with a blank form where you can start designing your application.

2. Explain the string function in VB:

String functions in VB are used to manipulate text. Common functions include:

• Len(string) – Returns the length of a string.


• Mid(string, start, length) – Extracts a substring.
• LCase(string) / UCase(string) – Converts to lowercase/uppercase.
• Trim(string) – Removes leading and trailing spaces.
• InStr(string1, string2) – Returns position of substring.

These help in formatting, searching, and modifying string data.

3. Give a short note on static Array:

A static array in VB is an array whose size is fixed at the time of declaration and cannot be changed during
program execution.

Example:

Dim numbers(4) As Integer ' Declares an array of 5 integers (0 to 4)

Static arrays are simple and efficient for storing a known quantity of items.

4. Discuss common controls:

Common controls are standard user interface elements provided in the VB toolbox. Examples include:

• Label – Displays static text.


• TextBox – Allows user input.
• Button – Executes code on click.
• ComboBox – Drop-down list with optional text input.
• ListBox – Displays a list of items.
• CheckBox/RadioButton – For selections.

These controls help build interactive and functional user interfaces.

5. Write a note on: Dialog Boxes

Dialog Boxes are special windows used to communicate with the user. Types include:
• MessageBox – Displays messages and gets a response (e.g., OK, Cancel).
• InputBox – Accepts input from the user.
• Common Dialog Box – Used for tasks like file opening, saving, and printing (e.g.,
OpenFileDialog, SaveFileDialog).

They enhance user interaction by providing prompts or choices.

6. Write short notes on: File System Objects

File System Objects (FSO) provide a way to access and manipulate the file system using VB. It allows you
to:

• Create, delete, or move files and folders.


• Read from or write to text files.
• Get file properties (e.g., size, date created).

Example usage:

Dim fso As Object


Set fso = CreateObject("Scripting.FileSystemObject")

FSO makes file handling operations easier and more structured.

7. Explain the procedures in creating menus:

To create menus in VB:

1. Open the Form Designer.


2. Select the MenuStrip control from the Toolbox and drag it onto the form.
3. Click on the MenuStrip to start entering menu items (e.g., File, Edit).
4. Under each menu item, add sub-items (e.g., File → Open, Save).
5. Write code in the Click event of each menu item to define its behavior.
8.Discuss on various properties of a Command Button:

A Command Button in VB (e.g., Button1) has several properties that define its appearance and behavior:

• Name – The identifier used in code (e.g., btnSubmit).


• Text / Caption – The text displayed on the button.
• Enabled – Enables or disables the button (True or False).
• Visible – Controls whether the button is visible.
• BackColor / ForeColor – Background and text color of the button.
• Font – Sets the font style, size, and type.
• Size / Width / Height – Controls the dimensions of the button.
• Location / Top / Left – Controls the position of the button on the form.

9. Explain the various tools in a Toolbox:

The Toolbox in VB contains controls used for designing user interfaces. Common tools include:

• Label – Displays static text.


• TextBox – Allows user to input text.
• Button (Command Button) – Executes code when clicked.
• CheckBox – Allows multiple selections.
• RadioButton – Allows single selection in a group.
• ComboBox – Drop-down list with optional typing.
• ListBox – Displays a list of items.
• PictureBox – Displays images.
• Timer – Executes code at timed intervals.
• MenuStrip – Allows menu creation.
• ProgressBar – Shows progress visually.

10. Describe the various Built-in functions with examples:

VB provides many built-in functions:

• String Functions:
o Len("Hello") → returns 5.
o UCase("hello") → returns "HELLO".
• Math Functions:
o Abs(-10) → returns 10.
o Sqr(16) → returns 4.
• Date Functions:
o Now() → returns the current date and time.
o DateAdd("d", 7, Now()) → adds 7 days to the current date.
• Conversion Functions:
o CInt("123") → converts string to integer.
o CStr(456) → converts number to string.

11. Explain how to add and remove controls in a Control Array:


Control Arrays allow multiple controls of the same type (e.g., buttons) to share the same event handler.

To Add a Control:

1. Place a control on the form.


2. Copy and paste the same control.
3. VB will ask if you want to create a control array – click Yes.
4. Each control will have an Index property (e.g., Command1(0), Command1(1)).

To Remove a Control:

• Select the control from the form.


• Press Delete or right-click and choose Delete.
• Make sure at least one control remains in the array if you're keeping it.

12. Describe the method used for error trapping:

Error trapping is used to handle runtime errors gracefully. The most common method is:

Using On Error statement:

On Error GoTo ErrorHandler


' Code that might cause an error
Exit Sub

ErrorHandler:
MsgBox "An error occurred: " & Err.Description

• Err.Number – Returns the error number.


• Err.Description – Describes the error.

Error trapping ensures the program doesn't crash and can provide a user-friendly message.

13. What is meant by Common Dialog Box? Explain:

A Common Dialog Box is a standard Windows interface used for common tasks like opening files, saving,
printing, or choosing colors.

VB uses the CommonDialog control (part of Microsoft Common Dialog Control) to create these
dialogs.

Examples:

• Open File Dialog:

CommonDialog1.ShowOpen

• Save File Dialog:

CommonDialog1.ShowSave

• Color Dialog:
CommonDialog1.ShowColor

These dialogs save development time and provide a familiar experience to users.

14. Explain the common methods of File System Objects:

File System Object (FSO) allows interaction with the file system.

Common FSO methods include:

• CreateTextFile(path, overwrite) – Creates a new text file.

fso.CreateTextFile("C:\test.txt", True)

• OpenTextFile(path, mode) – Opens a file for reading, writing, or appending.

Set file = fso.OpenTextFile("C:\test.txt", 1) '1 = Read

• CopyFile(source, destination) – Copies a file.

fso.CopyFile "C:\file1.txt", "D:\file1.txt"

• DeleteFile(path) – Deletes a file.


• FolderExists(path) / FileExists(path) – Checks if a folder or file exists.

These methods help manage files and folders efficiently in VB programs.


15.Explain common form properties:

Forms are the main containers for controls in VB. Here are common form properties:

• Name: Internal name used to reference the form (e.g., Form1).


• Caption / Text: Text displayed on the form’s title bar.
• BackColor: Background color of the form.
• BorderStyle: Defines the border style (e.g., FixedSingle, None).
• Enabled: Determines whether the form can receive user input.
• Visible: Controls whether the form is visible.
• StartUpPosition: Sets the form's starting position on screen.
• WindowState: Controls the form's state – Normal, Minimized, or Maximized.
• Height / Width / Top / Left: Dimensions and screen position.

16. Write short notes on Combo Box controls:

A ComboBox is a control that combines a TextBox and a ListBox. It lets users either type an entry or
choose one from the drop-down list.

Types:

• Simple – Always displays the list.


• Dropdown – Displays the list on clicking the arrow.
• Dropdown List – Allows only selection (no typing).

Common Properties:

• Items – Collection of items.


• SelectedIndex – Index of selected item.
• Text – Current text/value of the combo box.

Example:

ComboBox1.Items.Add("Apple")

17. Discuss about various Built-in functions with examples:

VB Built-in functions are pre-defined and help perform common tasks:

a. String Functions:

• Len("Hello") → 5
• UCase("abc") → "ABC"
• Mid("Visual Basic", 8, 5) → "Basic"

b. Math Functions:

• Sqr(25) → 5
• Rnd() → Returns a random number between 0 and 1.

c. Date Functions:
• Now() → Returns current date and time.
• DateDiff("d", "01-Jan-2024", "10-Jan-2024") →9

d. Conversion Functions:

• CInt("123") → Converts string to integer.


• CStr(456) → Converts number to string.

18. Explain about Dialog Boxes and MDI forms:

Dialog Boxes:
These are pop-up windows used for interaction with the user.

• Types:
o MessageBox – Displays messages.
o InputBox – Takes user input.
o Common Dialogs – For Open, Save, Print, etc.

Example:

MsgBox "File saved successfully!"

MDI Forms (Multiple Document Interface):

• Used to create applications with one parent form and multiple child forms.
• The child forms open within the main window (parent).

Steps:

• Set parent form’s IsMdiContainer property to True.


• Set child form's MdiParent property in code:

ChildForm.MdiParent = Me
ChildForm.Show()

19. Explain the steps to be followed to create a menu using menu editor:

Steps to create a menu:

1. Open your form in Design View.


2. Click on Tools > Menu Editor.
3. In the Menu Editor:
o Type the caption (what appears on form).
o Enter the name (used in code).
o Use “&” to assign shortcuts (e.g., &File = Alt+F).
4. Click the "Next" button to add submenus.
5. Use arrow keys in the Menu Editor to organize hierarchy.
6. Click OK to save and display the menu on the form.
7. Write code for each menu item’s Click event.
20. Explain about VB Controls with examples:

VB Controls are UI elements that allow user interaction. Some common ones:

• Label – Displays text.

Label1.Text = "Welcome"

• TextBox – Accepts user input.

Dim name As String = TextBox1.Text

• Button – Executes code on click.

Private Sub Button1_Click()


MsgBox("Clicked!")
End Sub

• CheckBox / RadioButton – For selecting options.


• ComboBox / ListBox – To show and select from a list.

Controls can be customized using their Properties, and made functional using Events.

21. Explain about OLE Drag and Drops with examples:

OLE Drag and Drop allows users to drag data (like text, files) from one control to another using Object
Linking and Embedding (OLE).

Steps:

1. Enable drag and drop:


o Set control’s OLEDragMode to 1 - Automatic.
o Set target control’s OLEDropMode to 1 - Manual.
2. Write code in OLEDragDrop event:

Private Sub Text2_OLEDragDrop(Data As DataObject, _


Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)

Text2.Text = Data.GetData(vbCFText)
End Sub

Example: Dragging text from Text1 and dropping it into Text2.

OLE Drag and Drop makes apps more interactive and user-friendly.

You might also like