Question

Visual Basic - I need to make a program to search a text file that is...

Visual Basic - I need to make a program to search a text file that is in the debug. Found from "IO.File.ReadAllLines".  When the word is typed into a textbox and button pressed, the program should show which line the word first appeared in the text through a message box or another feature. If it is not found, the program will open a message box. I don't have the full code, please assist

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//Form Interface

'Form1.vb

Imports System.IO
Public Class Form1
Dim reader As StreamReader

Private Sub btnSearch_Click(sender As Object, e As EventArgs) Handles btnSearch.Click
' Open file which is in debug folder
reader = My.Computer.FileSystem.OpenTextFileReader("C:\\Users\\naren\\source\\repos\\Search Word\\Search Word\\bin\\Debug\\input.txt")
Dim line As String
Dim word As String
Dim count As Integer
Dim found As Boolean
found = False
count = 0
' Read each line from file
While Not reader.EndOfStream
' update line counter
count = count + 1
line = reader.ReadLine()
word = TextBox1.Text
'Condition to check word
If line.Contains(word) Then
MsgBox("The word found in line " & count)
found = True
End If

End While
' if not found word
If Not found Then
MsgBox("The word is not found...")
End If

End Sub
End Class

//Output

//If you need any help regarding this solution ....... please leave a comment....... thanks

Add a comment
Know the answer?
Add Answer to:
Visual Basic - I need to make a program to search a text file that is...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • This is Visual Basic program, thank you for your help In this assignment, you'll start a...

    This is Visual Basic program, thank you for your help In this assignment, you'll start a new Windows Forms application. Assume we have the data shown below: Names_first={"jack","marjy","tom","luke","sam","al","joe","miky","lu"} Name_last={"jones","ety","fan","spence","amin",sid","bud","ant","ben"} Amounts={234.45,8293.1,943.25,27381.0,271.39,7436.12,2743.0,1639.95,2354.2} The above will allows us to emulate reading data from a file, which we will learn in the next unit. For now, we will assume the data above has been read from a file. We need to process this data in fast way. For that purpose, we need to: Declare...

  • In Python, do a basic encryption of a text file in the following manner. The program...

    In Python, do a basic encryption of a text file in the following manner. The program encrypt.py will read in the following text file and rearrange the lines in the file randomly and save the rearranged lines of txt to another file called encrypted.txt. It will also save another file called key.txt that will contain the index of the lines that were rearranged in the encrypted file, so for example if the 4th line from the original file is now...

  • (Python 3) Write a program that reads the contents of a text file. The program should...

    (Python 3) Write a program that reads the contents of a text file. The program should then create a dictionary in which the keys are individual words found in the file and the values are the number of times each word appears and a list that contains the line numbers in the file where the word (the key) is found. Then the program will create another text file. The file should contain an alphabetical listing of the words that are...

  • Basic C program Problem: In this assignment, you have to read a text file (in.txt) that...

    Basic C program Problem: In this assignment, you have to read a text file (in.txt) that contains a set of point coordinates (x,y). The first line of the file contains the number of points (N) and then each line of the file contains x and y values that are separated by space. The value of x and y are an integer. They can be both negative and positive numbers. You have to sort those points in x-axis major order and...

  • C++ not C please Lyric Search Write a program that asks the user for a file...

    C++ not C please Lyric Search Write a program that asks the user for a file name and a string to search for. The program should search the file for every occurrance of the string. When the string is found it should display the line that it iwas found on and report the total number of occurrances of the string at the end. Place a text file with your favorite song lyrics in it and use to to perform a...

  • Visual Basic Programming Step 1-2 not important, it's just file naming.

    Visual Basic Programming Step 1-2 not important, it's just file naming. 3. Form contains nine Labels, one TextBox, and three Button controls. You use labels to let user know what to enter and what will be displayed; TextBoxes to input a number between 1 and 99. Buttons to Calculate change. Clear Input and Exit program. See below Form Layout with Controls for more details 4. Declare variables to store the entered value in TextBox, and what will be displayed in...

  • Visual Basic Programming Step 1-2 not important, it's just file naming. 3. Form contains nine Labels,...

    Visual Basic Programming Step 1-2 not important, it's just file naming. 3. Form contains nine Labels, one TextBox, and three Button controls. You use labels to let user know what to enter and what will be displayed; TextBoxes to input a number between 1 and 99. Buttons to Calculate change. Clear Input and Exit program. See below Form Layout with Controls for more details 4. Declare variables to store the entered value in TextBox, and what will be displayed in...

  • This is binary search tree problem. The program reads the text file, and creates a binary...

    This is binary search tree problem. The program reads the text file, and creates a binary search tree based on the words in the file. I can create the tree but I also have to store 'the order of insertion' in each node.   For example, if text includes "the" 3 times and it is the 1st, 5th, and 9th word in the file, in binary search tree, one node should have string value "the" and array list{1, 5, 9}. How...

  • Need help!!! I need two programs that use one common database.. One program using a Visual...

    Need help!!! I need two programs that use one common database.. One program using a Visual Basic windows form using textboxes for data input (first name, last name, phone, email) and it should save the info into an SQL database when a save button is clicked. Second program using a C# windows form that has a drop down menu with all the names that have been saved into the database, when one name is clicked all their information should pop...

  • Write a program in Visual Basic, design a window with four text boxes and a command...

    Write a program in Visual Basic, design a window with four text boxes and a command button to do the following: 1- Upon implementation, the text of the first box shall contain () University of Thi-Qar The rest of the text boxes will be empty. -2 When you click on Command1 it distributes the three sections of text In the first box on the rest of the empty boxesس2 : A) أكتب برنامج بلغة فيجول بيسك وصمم نافذة تحتوي على...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT