0% found this document useful (0 votes)
51 views2 pages

File Handling Tasks

This document contains code to write data to a text file, read data from that text file, and search the text file for a specified number. The code includes a writer subroutine to write user-entered data to a file, a reader subroutine to read and display the data from the file, and a search subroutine to prompt the user for a number, search the file, and output whether the number was found and on which line.
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)
51 views2 pages

File Handling Tasks

This document contains code to write data to a text file, read data from that text file, and search the text file for a specified number. The code includes a writer subroutine to write user-entered data to a file, a reader subroutine to read and display the data from the file, and a search subroutine to prompt the user for a number, search the file, and output whether the number was found and on which line.
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/ 2

Imports System.

IO
Module Module1
Sub writer()
Dim filewriter As StreamWriter
Dim A(5), i As Integer

filewriter = File.CreateText("E:/BDC/Std.txt")
For i = 1 To 5
A(i) = Console.ReadLine
filewriter.WriteLine(A(i))
Next
filewriter.Close()
End Sub
Sub reader()
Dim filereader As StreamReader
Dim data As Integer
filereader = File.OpenText("E:/BDC/Std.txt")
While filereader.Peek <> -1
data = filereader.ReadLine()
Console.WriteLine(data)
End While
End Sub
Sub search()
Dim filereader As StreamReader
Dim data, searchNo, i As Integer
Dim found As Boolean = False
filereader = File.OpenText("E:/BDC/Std.txt")
Console.Write("Enter Search Number ")
searchNo = Console.ReadLine

While filereader.Peek <> -1


data = filereader.ReadLine()
If searchNo = data Then
found = True
Exit While
End If
i = i + 1
End While
If found = True Then
Console.WriteLine("Number found at line " &
i + 1)
Else
Console.WriteLine("number not found")
End If
End Sub

Sub Main()

' writer()
'reader()
search()

Console.ReadKey()

End Sub

End Module

You might also like