0% found this document useful (0 votes)
11 views11 pages

3rd Year Paper - 1 Unit 4

Uploaded by

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

3rd Year Paper - 1 Unit 4

Uploaded by

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

Paper -1 unit 4

Sequential and random files


What is sequential file? How Is data saved and analysed in sequential file?

A sequential file contains records organized by the order in which they were entered. The
order of the records is fixed.

Records in sequential files can be read or written only sequentially.

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.

Methods of the SaveFileDialog Control


The following are some of the commonly used methods of the SaveFileDialog control −

Sr.No. Method Name & Description

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.

Picture Box Vs Image Box in VB


picture box:
1) it act as container control
2) use of memory to store the picture
3) editing of picture is possible in picture box
4) having auto size property
5) not having stretch property
Image Control:
1) it is not act as container control
2) not use of memory to store the picture
3) editing of picture is not possible in picture box
4) Not having auto size property
5) Having stretch property
Main Difference:
The Image control is a lightweight control that has no device context (or hDC) or it's own. The Picturebox
does have a device context and hDC and is a true "window" from the point of view of the Windows
operating system (and can directly use "hWnd" parameter API calls).
Due to this difference, an Image control can display a gif file loaded into the picture property with a
transparent background, while a picturebox does not. The Picturebox, however, doesn't "flicker" when
moved at runtime like an Image control does. This difference also has implications for layering -- a
lighweight control (like the Image control) can only be z-ordered (layered) over another lighweight control
--but never over a true window like the Picturebox control. The Image control is also "lightweight" in
terms of it's memory footprint (versus the
Picturebox control which is "heavier" even without the extra memory backbuffer that is reserved with its
AutoRedraw property set to True) --although with the amount of memory available in most modern
computers, this doesn't usually make this much of a difference, but it might come into play with large
control arrays containing large graphics that would force paging out to virtual memory (which, in turn,
could effect the speed of game graphics).
An Image control has Stretch property, a Picturebox control does not.
Picturebox control has an AutoSize property, an Image control does not.
However code workarounds can substitute for these two missing properties in either/both.
Both controls use a StdPicture object to store graphics and so Picture.Render and LoadPicture/SavePicture
will work with both (but PaintPicture only works with the Picturebox control).

Image Box Picture Box

1) it is not act as 1) it act as container


container control control

2) not use of memory 2) use of memory to


to store the picture store the picture

3) editing of picture is 3) editing of picture is


not possible in picture possible in picture box
box
4) having auto size
4) Not having auto size property
property
5) Having stretch 5) not having stretch
property property

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.

There are five different PictureBoxSizeMode is available to PictureBox control.

 AutoSize - Sizes the picture box to the image.


 CenterImage - Centers the image in the picture box.
 Normal - Places the upper-left corner of the image at upper left in the picture box.
 StretchImage - Allows you to stretch the image in code.

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.

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


MyBase.Load
PictureBox1.Image = Image.FromFile("d:\testImage.jpg")
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage

End Sub

End Class

VB.NET MDI Form

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.

VB.NET has folowing rules for creating a form as an MDI 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

1. Public Class Form2

2. Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load

3. Me.Text = "Feedback form" ' Set the title of the form

4. Label1.Text = " Fill the Feedback form"

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

11. MsgBox(" Successfully submit the feedback form")

12. End Sub

13. Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

14. Me.Dispose() ' end the form2

15. End Sub

16. End Class

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

1. Public Class MDI_Form

2. Private Sub MDI_Form_Load(sender As Object, e As EventArgs) Handles MyBase.Load

3. IsMdiContainer = True 'Set the Boolean value to true to create the form as an MDI form.

4. Me.Text = "javatpoint.com" 'set the title of the form

5. PictureBox1.Image = Image.FromFile("C:\Users\AMIT YADAV\Desktop\jtp2.png")

6. PictureBox1.Height = 550

7. PictureBox1.Width = 750

8. End Sub

9. Private Sub FeedbackFormToolStripMenuItem_Click(sender As Object, e As EventArgs) Hand

les FeedbackFormToolStripMenuItem.Click

10. PictureBox1.Visible = False

11. Dim fm2 As New Form2

12. fm2.MdiParent = Me 'define the parent of form3, where Me represents the same form

13. fm2.Show() 'Display the form3

14. End Sub

15. Private Sub VBNETToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles VB

NETToolStripMenuItem.Click

16. PictureBox1.Visible = False

17. Dim fm3 As New Form3

18. fm3.MdiParent = Me 'define the parent of form3, where Me represent the same form
19. fm3.Show() 'Display the form3

20. End Sub

21. End Class

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

1. Sequential file organization

 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 makes it easy to access records.


 The binary chop technique can be used to reduce record search time by as much as
half the time taken.

Disadvantages 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.

2. Random or direct file organization

 Records are stored randomly but accessed directly.


 To access a file stored randomly, a record key is used to determine where a record is
stored on the storage media.
 Magnetic and optical disks allow data to be stored and accessed randomly.

Advantages of random file access

 Quick retrieval of records.


 The records can be of different sizes.

3. Serial file organization

 Records in a file are stored and accessed one after another.


 The records are not stored in any way on the storage medium this type of organization
is mainly used on magnetic tapes.

Advantages of serial file organization

 It is simple
 It is cheap

Disadvantages of serial file organization

 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.

4. Indexed-sequential file organization method

 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.

There are Three statement of Random Access Files :

1. Open Statement
2. Get Statement
3. Put Statement

The Open Statement for Random Access Files


The "full blown" syntax for the Open statement was given in the previous topic on binary files. The
syntax for the Open statement, as it pertains to random files, is as follows:

1) If you only want to read from the random access file, use:

Open filename For Random Access Read As #filenumber Len = reclength

2) and if you only want to write to the random access file, use:

Open filename For Random Access Write As #filenumber Len = reclength

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

VB.NET Dialog Box


A Dialog box is a temporary Window for an application that accepts user response through mouse or
keyboard to open a file, save a file, notifications, alert messages, color, print, openfile dialog box, etc.
It is also useful to create communication and interaction between the user and the application.
Furthermore, the dialog box appears in a form when the program needs to interact with users, such as
when an error occurs, an alert message, acknowledgment from the user or when the program requires
immediate action or whether the decision is to be saved based on the changes.

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

1. Public Class Dialog


2. Private Sub Dialog_Load(sender As Object, e As EventArgs) Handles MyBase.Load
3. Button1.Text = "Click Me" 'Set the name of button
4. Me.Text = "javatpoint.com" ' Set the title name for the Windows Form
5. Button1.BackColor = Color.Green ' Background color of the button
6. End Sub
7.
8. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
9. Dim result1 As DialogResult = MessageBox.Show("Is VB.NET programming language
easy to learn?",
10. "Important Question",
11. MessageBoxButtons.YesNo)
12. End Sub
13. End Class

Output:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy