3rd Year Paper - 1 Unit 4
3rd Year Paper - 1 Unit 4
A sequential file contains records organized by the order in which they were entered. The
order of the records is fixed.
After you place a record into a sequential file, you cannot shorten, lengthen, or delete the
record. However, you can update (REWRITE) a record if the length does not change. New
records are added at the end of the file.
If the order in which you keep records in a file is not important, sequential organization is a
good choice whether there are many records or only a few. Sequential output is also useful
for printing reports.
The SaveFileDialog control prompts the user to select a location for saving a file and allows
the user to specify the name of the file to save data. The SaveFileDialog control class inherits
from the abstract class FileDialog.
1
OpenFile
Opens the file with read/write permission.
2
Reset
Resets all dialog box options to their default values.
Example
In this example, let's save the text entered into a rich text box by the user using the save file
dialog box. Take the following steps −
Drag and drop a Label control, a RichTextBox control, a Button control and a
SaveFileDialog control on the form.
Set the Text property of the label and the button control to 'We appreciate your
comments' and 'Save Comments', respectively.
PictureBox Control
The Windows Forms PictureBox control is used to display images in bitmap, GIF,icon, or
JPEG formats.
You can set the Image property to the Image you want to display, either at design time or at run time.
You can programmatically change the image displayed in a picture box, which is particularly useful
when you use a single form to display different pieces of information.
The SizeMode property, which is set to values in the PictureBoxSizeMode enumeration, controls the
clipping and positioning of the image in the display area.
You can change the size of the display area at run time with the ClientSize property.
The following VB.Net program shows how to load a picture from a file and display it in streach
mode.
End Sub
End Class
MDI stands for Multiple Document Interface applications that allow users to work with
multiple documents by opening more than one document at a time. Whereas, a Single
Document Interface (SDI) application can manipulate only one document at a time.
The MDI applications act as the parent and child relationship in a form. A parent form is a
container that contains child forms, while child forms can be multiple to display different
modules in a parent form.
1. MidParent: The MidParent property is used to set a parent form to a child form.
2. ActiveMdiChild: The ActiveMdiChild property is used to get the reference of the current
child form.
3. IsMdiContainer: The IsMdiContainer property set a Boolean value to True that represents
the creation of a form as an MDI form.
4. LayoutMdi(): The LayoutMdi() method is used to arrange the child forms in the parent or
main form.
5. Controls: It is used to get the reference of control from the child form.
Let's create a program to display the multiple windows in the VB.NET Windows Forms.
Step 1: First, we have to open the Windows form and create the Menu bar with the use of
MenuStrip control, as shown below.
Step 2: After creating the Menu, add the Sub items into the Menu bar, as shown below.
Step 3: In the third step, we will create two Forms: The Child Form of the Main
Form or Parent Form.
Here, we have created the first Child Form with the name Form2.
Form2.vb
5. Button1.Text = "Submit"
6. Button1.BackColor = Color.SkyBlue
7. Button2.Text = "Cancel"
8. Button2.BackColor = Color.Red
9. End Sub
10. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Step 4: Now we write the programming code for the Main or Parent Form, and here is the
code for our Main Form.
MDI_form.vb
3. IsMdiContainer = True 'Set the Boolean value to true to create the form as an MDI form.
6. PictureBox1.Height = 550
7. PictureBox1.Width = 750
8. End Sub
les FeedbackFormToolStripMenuItem.Click
12. fm2.MdiParent = Me 'define the parent of form3, where Me represents the same form
NETToolStripMenuItem.Click
18. fm3.MdiParent = Me 'define the parent of form3, where Me represent the same form
19. fm3.Show() 'Display the form3
Output:
File Organization :
File organization refers to the way data is stored in a file. File organization is very
important because it determines the methods of access, efficiency, flexibility and
storage devices to use. There are four methods of organizing files on a storage media.
This include:
sequential,
random,
serial and
indexed-sequential
Records are stored and accessed in a particular order sorted using a key field.
Retrieval requires searching sequentially through the entire file record by record to the
end.
Because the record in a file are sorted in a particular order, better file searching
methods like the binary search technique can be used to reduce the time used for
searching a file .
Since the records are sorted, it is possible to know in which half of the file a particular
record being searched is located, Hence this method repeatedly divides the set of
records in the file into two halves and searches only the half on which the records is
found.
For example, of the file has records with key fields 20, 30, 40, 50, 60 and the
computer is searching for a record with key field 50, it starts at 40 upwards in its
search, ignoring the first half of the set.
Advantages of sequential file organization
The sorting does not remove the need to access other records as the search looks for
particular records.
Sequential records cannot support modern technologies that require fast access to
stored records.
The requirement that all records be of the same size is sometimes difficult to enforce.
It is simple
It is cheap
It is cumbersome to access because you have to access all proceeding records before
retrieving the one being searched.
Wastage of space on medium in form of inter-record gap.
It cannot support modern high speed requirements for quick record access.
Almost similar to sequential method only that, an index is used to enable the
computer to locate individual records on the storage media. For example, on a
magnetic drum, records are stored sequential on the tracks. However, each record is
assigned an index that can be used to access it directly.
Random Access Files
Random files are record-based files with an internal structure that supports "direct access" by record
number. This means that your program can read from or write to a specific record in a random access
file, say the 50th record, without reading through the previous 49 records. Compare that to reading or
writing a sequential file, where to get to a specific record, you must read through all preceding
records.
The difference between random access and sequential access can be likened to accessing music on
a CD versus a cassette tape. To get to song number 6, you can tell your CD player to go directly to
track 6, whereas on a cassette tape, you must fast-forward through the first 5 songs to get to song
number 6.
1. Open Statement
2. Get Statement
3. Put Statement
1) If you only want to read from the random access file, use:
2) and if you only want to write to the random access file, use:
3) and if you want to both read from and write to the random access file (for example, you want to
access a
particular record and then update one or more of its fields), use:
Open filename For Random Access Read Write As #filenumber Len = reclength
All VB.NET
Dialog box inherits the CommonDialog class and overrides the RunDialog() method of the base class
to create the OpenFileDialog box, PrintDialogbox, Color, and Font Dialog box. The RunDialog()
method is automatically called in a Windows
form when the dialog box calls its ShowDialog() method.
There are following functions of the ShowDialog() method that can be called at run time in the
Windows Form.
Abort: The Abort Dialog box is used when a user clicks on the Abort button to return the
DialogResult.Abort value.
Ignore: The Ignore Dialog box is used when a user clicks on the Ignore button to return the
DialogResult.Ignore.
None: It is used to return nothing when the user clicks on the None button, and the dialog box
is continued running.
OK: When the user clicks the OK button of the Dialog box, it returns a DialogResult.OK,
Cancel: When a user clicks on the Cancel button of the Dialog Box, it returns
DialogResult.Cancel,
Yes: When a user clicks the Yes button of the dialog box, it returns DialogResult.Yes.
Retry: When a user clicks on the Dialog Box Retry button, it returns a DialogResult.Retry,
No: When a user clicks on the No button of the Dialog box, it returns DialogResult.No,
There are the commonly used dialog box controls in the VB.NET Windows Form.
1. Color Dialog Box: It is used to display the color dialog box that allows the user to select a
color from the predefined colors or specify the custom colors.
2. Font DialogBox: It is used to create a Font dialog box that allows the user to select the font,
font size, color, and style to be applied to the current text selection.
3. OpenFile Dialog Box: It is used to create a prompt box that allows the users to select a file to
open and allows the selection of multiple files.
4. Print Dialog Box: It is used to create a print dialog box that allows the user to print
documents by selecting the printer and setting of the page printed through the Windows
application.
Let's create a simple program to display the dialog box in the VB.NET Windows Forms.
Dialog.vb
Output: