1 2 Translate the following algorithm into Visual Basic cod
Solution
1) Answer for first question
Dim MyFile As String = \"TestFile.txt\"    \' Defining fileName
 Dim outData As StreamWriter = New StreamWriter(MyFile)   \' Declaring Stream Writer
 Dim myData As StreamReader = New StreamReader(MyFile) \' Declaring Stream Reader
 Dim strName As String \' Defining strName
 Dim intData(x) As String \'Array of Strings with length of x
 Dim intCount As Integer \'Defining intCount
2) Answer for second question
Dim strName As String \' Defining strName as String
 strName = InputBox(\"Enter strName\", \"Sample Program\", \"\") \' Reading input
 Dim objWriter As New System.IO.StreamWriter( FILE_NAME, True ) \' Opening file in appending mode
3) Answer for third question
\' Creating a Class
Imports System
 Imports System.IO
 Imports System.Text
Public Class FileReading \' CREATING CLASS
Public Shared Sub Main()               \' Method name
 Dim MyFile As String = \"TestFile.txt\"       \' File name
    Dim strName As String
 Dim intData As String
 Dim intCount As Integer
If File.Exists(MyFile) Then \'Checking given file is existed or not
Dim myData As StreamReader = New StreamReader(MyFile)  
    strName = objStreamReader.ReadLine
    intCount = 0
     Do While Not strName Is Nothing \' Iterating through the text
 intData &= strName \' adding text to intData
 intCount += 1       \' Counting the lines
       strName = objStreamReader.ReadLine \' Reading input
 Loop
 myData.close()       \' closing strean reader
   
 Else
         MsgBox(\"File is not found!\")       \' If file is not found
 End If
End Sub
 End Module

