1 2 Translate the following algorithm into Visual Basic cod

1 & 2
Translate the following algorithm into Visual Basic code Declare variables myData as a file stream reader outData as a file stream writer strName as the string variable that will store the text from the input MyFile as the name of the file intData as data from the file intCount as the total number of items on the file Input read strName from an InputBox open the file for append write the contents of strName on a separate line in the file close the file Processing If the file exists then open the file Do the following until you reach the end of the file read a data item into intData add 1 to intCount loop close the file else display \"File does not exist!\"

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

1 & 2 Translate the following algorithm into Visual Basic code Declare variables myData as a file stream reader outData as a file stream writer strName as t

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site