Using Visual Studio The 10 names on the txt file Robert Smith John Adams Charles
ID: 658656 • Letter: U
Question
Using Visual Studio
The 10 names on the txt file
Robert Smith
John Adams
Charles Xavier
Clark Kent
Eric Clapton
Pat Benetar
Abraham Lincoln
Paul Revere
Jimi Hendrix
Angelina Jolie
Explanation / Answer
Program:
// this is vb program done in visual studio 2012 express
// create console application
Module Module1
Sub Main()
Dim key As String
Dim choice As String = "Y"
Dim i As Integer
Dim flag As Integer = 0
Dim names(20) As String
Dim fileReader As System.IO.StreamReader
Dim count As Integer = 0
fileReader =
My.Computer.FileSystem.OpenTextFileReader("C:\lab12data.txt")
Dim sLine As String
Do
sLine = fileReader.ReadLine()
If Not sLine Is Nothing Then
names(count) = sLine
count = count + 1
End If
Loop Until sLine Is Nothing
Do Until (StrComp(choice, "Y", CompareMethod.Text) = 0)
Console.WriteLine("What name do you want to search for:")
key = Console.ReadLine()
For i = 0 To 10
If (StrComp(names(i), key, CompareMethod.Text) = 0) Then
Console.WriteLine("The name " + key + " was found on the list")
flag = 1
Exit For
End If
Next
If flag = 0 Then
Console.WriteLine("The name " + key + " was not found on the list")
End If
Console.WriteLine("Do you want to search for other name:<Y/N>")
choice = Console.ReadLine()
Loop
End Sub
End Module
Output:
What name do you want to search for:
Paul Revere
The name Paul Revere was found on the list
Do you want to search for other name: <Y/N>
Y
What name do you want to search for:
Obama
The name Obama was found on the list
Do you want to search for other name: <Y/N>
N
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.