I have to write a program that allows a user to input DVD info such as DVD Name, Year produced, Running Time, and Rating.
The user then clicks a menu item "New" to save that info to a file.
Then the next time the user inputs new DVD info it has to append the new data to the same file. (I got this far and everything is working writing and appending data)
Next the year has to be able to search by DVD Video name and it has to print the info in the text boxes on the form, if not found then a messagebox should say not found. When I use the sub procedure that I have created to search the record it always comes back as record not found although the record in in the file.
Here is my entire code so far can someone please help...
Option Strict On
Imports System.IO
Public Class Form1
'Class level variables
'Document filename
Dim strFilename As String = String.Empty
'to notify us when data has changed in the text box
Dim blnIsChanged As Boolean = False
Structure videoData
Dim strVideoName As String
Dim strYearProduced As String
Dim strRunningTime As String
Dim strRating As String
End Structure
Sub SaveNewData()
'Save the current document under the name stored in documentName
Dim videoRecord As videoData
Dim inputRecord As StreamWriter
videoRecord.strVideoName = txtVideoName.Text
videoRecord.strYearProduced = txtYearProduced.Text
videoRecord.strRunningTime = txtRunningTime.Text
videoRecord.strRating = txtRating.Text
inputRecord = File.CreateText(strFilename)
inputRecord.WriteLine("Video Name: " & (videoRecord.strVideoName))
inputRecord.WriteLine("Year Produced: " & (videoRecord.strYearProduced))
inputRecord.WriteLine("Runing Time: " & videoRecord.strRunningTime)
inputRecord.WriteLine("Rating:" & videoRecord.strRating)
inputRecord.Close()
'update blnIschange variable
blnIsChanged = False
End Sub
Sub appendRecord()
Dim appendFile As videoData
Dim outputdata As StreamWriter
appendFile.strVideoName = txtVideoName.Text
appendFile.strYearProduced = txtYearProduced.Text
appendFile.strRunningTime = txtRunningTime.Text
appendFile.strRating = txtRating.Text
outputdata = File.AppendText(strFilename)
outputdata.WriteLine("Video Name: " & (appendFile.strVideoName))
outputdata.WriteLine("Year Produced: " & (appendFile.strYearProduced))
outputdata.WriteLine("Runing Time: " & appendFile.strRunningTime)
outputdata.WriteLine("Rating:" & appendFile.strRating)
outputdata.Close()
'update blnIschange variable
blnIsChanged = False
End Sub
Sub SearchRecord()
Dim strVideoName As String
Dim strYearProduced As String
Dim strRunningTime As String
Dim strRating As String
Dim intCount As Integer
Dim inputRecord As StreamReader
Dim strInput As String
Dim blnFound As Boolean
strInput = InputBox("Enter Name")
If File.Exists(strFilename) Then
inputRecord = File.OpenText(strFilename)
blnFound = True
Do While inputRecord.Peek = -1
strInput = inputRecord.ReadLine()
For intCount = 1 To 20
'Read records from the file
strVideoName = inputRecord.ReadLine()
strYearProduced = inputRecord.ReadLine()
strRunningTime = txtRunningTime.Text
strRating = txtRating.Text
'Display the data in the text box using vbTab.
txtVideoName.Text = strVideoName
txtYearProduced.Text = strYearProduced
Next intCount
Loop
Else
blnFound = False
MessageBox.Show("Record not found")
End If
End Sub
Private Sub txtVideoName_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtVideoName.TextChanged
'update the isChanged variable that the text has changed
blnIsChanged = True
End Sub
Private Sub mnuFileNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFileNew.Click
If sfdSaveFile.ShowDialog = Windows.Forms.DialogResult.OK Then
strFilename = sfdSaveFile.FileName
SaveNewData()
End If
End Sub
Private Sub mnuSearchName_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuSearchName.Click
SearchRecord()
End Sub
Private Sub mnuFileAppendExist_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFileAppendExist.Click
If ofdOpenFile.ShowDialog() = Windows.Forms.DialogResult.OK Then
strFilename = ofdOpenFile.FileName
End If
appendRecord()
End Sub
End Class
This post has been edited by Martyr2: 29 November 2010 - 10:22 PM
Reason for edit:: Please use code tags in the future, thanks!

New Topic/Question
Reply




MultiQuote







|