TEXT FILE FUNDAMENTALS in .NET framework

Generation QR Code JIS X 0510 in .NET framework TEXT FILE FUNDAMENTALS

EXAMPLE 9.2 TEXT FILE FUNDAMENTALS
Decode Denso QR Bar Code In Visual Studio .NET
Using Barcode Control SDK for Visual Studio .NET Control to generate, create, read, scan barcode image in .NET applications.
QR Generator In .NET Framework
Using Barcode printer for .NET Control to generate, create Denso QR Bar Code image in VS .NET applications.
In this example we present a Visual Basic project that will read data from a sequential file, write the data to a new sequential file, and/or print out the data. In developing this project we will make use the Open, Save As and Print common dialog boxes discussed in Sec. 9.1. Let us begin with the preliminary control layout shown in Fig. 9.7. Note that the form includes a menu labeled File, a label, a combo box, and a common dialog control. The individual menu items, Open, SaveAs, Print and Exit, are shown in Fig. 9.8.
QR Code JIS X 0510 Recognizer In Visual Studio .NET
Using Barcode decoder for .NET framework Control to read, scan read, scan image in .NET applications.
Bar Code Printer In Visual Studio .NET
Using Barcode drawer for .NET framework Control to generate, create barcode image in .NET framework applications.
Fig. 9.7
Scanning Bar Code In VS .NET
Using Barcode reader for Visual Studio .NET Control to read, scan read, scan image in .NET applications.
QR-Code Creator In Visual C#.NET
Using Barcode generator for .NET Control to generate, create QR image in .NET applications.
Fig. 9.8
Paint QR Code 2d Barcode In Visual Studio .NET
Using Barcode printer for ASP.NET Control to generate, create QR image in ASP.NET applications.
Quick Response Code Drawer In Visual Basic .NET
Using Barcode maker for Visual Studio .NET Control to generate, create Denso QR Bar Code image in Visual Studio .NET applications.
DATA FILES
Encode Code 128 Code Set C In Visual Studio .NET
Using Barcode generator for .NET Control to generate, create Code 128 Code Set A image in .NET applications.
Generating Barcode In .NET
Using Barcode printer for .NET Control to generate, create barcode image in .NET applications.
[CHAP. 9
Data Matrix 2d Barcode Drawer In VS .NET
Using Barcode encoder for .NET Control to generate, create Data Matrix ECC200 image in .NET framework applications.
Code-27 Generator In .NET Framework
Using Barcode printer for .NET Control to generate, create Rationalized Codabar image in VS .NET applications.
The entries in the menu editor, used to generate the File menu, are shown below (see Chap. 5). Caption
Recognize Bar Code In Visual Studio .NET
Using Barcode scanner for .NET Control to read, scan read, scan image in .NET applications.
GS1-128 Creator In Java
Using Barcode generation for Eclipse BIRT Control to generate, create GS1 128 image in BIRT applications.
File ....&Open ........&Save As ........&Print ........&Exit
Bar Code Creator In None
Using Barcode generation for Font Control to generate, create barcode image in Font applications.
Encode Bar Code In VB.NET
Using Barcode drawer for Visual Studio .NET Control to generate, create barcode image in .NET applications.
Name
Create GTIN - 128 In Java
Using Barcode generator for Android Control to generate, create EAN / UCC - 14 image in Android applications.
Barcode Decoder In C#.NET
Using Barcode decoder for .NET Control to read, scan read, scan image in .NET framework applications.
mnuFile mnuOpen mnuSep1 mnuSaveAs mnuSep2 mnuPrint mnuSep3 mnuExit
Making UCC.EAN - 128 In VS .NET
Using Barcode encoder for Reporting Service Control to generate, create UCC.EAN - 128 image in Reporting Service applications.
Universal Product Code Version A Encoder In Java
Using Barcode printer for Android Control to generate, create GS1 - 12 image in Android applications.
Recall that each menu item is associated with event procedure. Here is the complete list of event procedures.
Private Sub Form_Load() Form1.Caption = "Text File 1" Label1.Caption = "Text File Fundamentals" Label1.FontSize = 12 Label1.Alignment = 2 'Center Combo1.Text = "" mnuSaveAs.Enabled = False mnuPrint.Enabled = False End Sub Private Sub mnuOpen_Click() Dim OldFile As String, Item As String Dim i As Integer CommonDialog1.CancelError = True 'activate error detection On Error GoTo CancelButton 'error trap for Cancel button CommonDialog1.Filter = "Text files (*.txt)|*.txt" CommonDialog1.ShowOpen OldFile = CommonDialog1.FileName Open OldFile For Input As #1 i = 0 Do Until EOF(1) Input #1, Item Combo1.List(i) = Item Combo1.Tag = i 'tag the number of file entries i = i + 1 Loop Combo1.Text = "Contents" Combo1.Locked = True 'prevent user changes to combo box entries mnuSaveAs.Enabled = True mnuPrint.Enabled = True Close #1 CancelButton: Exit Sub End Sub
CHAP. 9]
DATA FILES
Private Sub mnuSaveAs_Click() Dim NewFile As String Dim i As Integer, n As Integer CommonDialog1.CancelError = True 'activate error detection On Error GoTo CancelButton 'error trap for Cancel button CommonDialog1.Filter = "Text files (*.txt)|*.txt" CommonDialog1.ShowSave NewFile = CommonDialog1.FileName Open NewFile For Output As #2 n = Val(Combo1.Tag) For i = 0 To n Print #2, Combo1.List(i) Next i Close #2 CancelButton: Exit Sub End Sub Private Sub mnuPrint_Click() Dim i As Integer, n As Integer CommonDialog1.CancelError = True On Error GoTo CancelButton CommonDialog1.ShowPrinter n = Val(Combo1.Tag) For i = 0 To n Printer.Print Combo1.List(i) Next i Printer.EndDoc CancelButton: Exit Sub End Sub Private Sub mnuExit_Click() End End Sub 'activate error detection 'error trap for Cancel button
The Form_Load procedure is straightforward. Note, however, that we initially generate an empty heading for the combo box (Combo1.Text = ""), and that we initially disable the SaveAs and Print menu items. These menu items will be enabled during program execution, once an input file has been opened. In contrast, the mnuOpen_Click procedure requires considerable explanation, mostly because of the statements associated with the Open common dialog box. The commands
CommonDialog1.CancelError = True On Error GoTo CancelButton
activate error trapping, so that an error trap can be initiated if the user clicks on the Cancel button within the Open dialog box. The actual error trap, shown at the bottom of the procedure, simply causes the program to exit the mnuOpen_Click procedure if the Cancel button is selected. The next statement,
CommonDialog1.Filter = "Text files (*.txt)|*.txt"
restricts the list of available files to those with the .txt extension, as in Fig. 9.4. There are many other variations of this statement, including one that causes all available files within the current folder to be displayed; namely,
DATA FILES
[CHAP. 9
CommonDialog1.Filter = "All files (*.*)|*.*"
We then generate the Open dialog box, assign a filename to the variable OldFile, and then open the file as an input text file on channel #1. We then enter a loop that reads data items from the input file via the Input #n statement, until an end-of-file condition has been detected. The EOF library function is used to detect the end-of-file condition. The statement
Copyright © OnBarcode.com . All rights reserved.