Xtreme Visual Basic Talk

Xtreme Visual Basic Talk (http://www.xtremevbtalk.com/)
-   .NET File I/O and Registry (http://www.xtremevbtalk.com/-net-file-i-o-and-registry/)
-   -   Writing query to search through a structure (http://www.xtremevbtalk.com/-net-file-i-o-and-registry/325170-writing-query-search-structure.html)

Raleigh 11-28-2012 02:36 PM

Writing query to search through a structure
Hey everyone, I am looking for some help with some basic coding.
I am new at VB and I am having trouble writing a sub procedure that is capable of searching through my structure.

Any help would be appreciated, below is my code so far.


Imports System.IO

Public Class Form1
    Const strFILENAME As String = "Videos.txt"
    Structure VideoData
        Dim name As String
        Dim yearProduced As String
        Dim runningTime As String
        Dim rating As String
    End Structure

    Private Sub mnuFileSaveRecord_Click(sender As System.Object, e As System.EventArgs) Handles mnuFileSaveRecord.Click
        Dim video1 As VideoData

        With video1
            .name = CStr(txtName.Text)
            .yearProduced = CStr(txtYear.Text)
            .runningTime = CStr(txtTime.Text)
            .rating = CStr(txtRating.Text)
        End With
    End Sub

this is my output so far...

  Sub WriteRecordToFile(ByRef video As VideoData)
        Dim outFile As StreamWriter

        outFile = File.AppendText(strFILENAME)

    End Sub

So how would I go about writing a searching sub process? I would also like to be able to inform the user if the txt file hasnt been created yet.
I made an input box through a menu command, but that's as far as I can get

All I have so far is an input box

Private Sub mnuSearchClick_Click(sender As System.Object, e As System.EventArgs) Handles mnuSearchClick.Click
        InputBox("Enter video name:", "Search")
    End Sub

JustinCase2 04-11-2014 04:51 AM

Something like this?

Private Sub mnuSearchClick_Click(sender As System.Object, e As System.EventArgs) Handles mnuSearchClick.Click
        dim searchString as string = InputBox("Enter video name:", "Search")
        Dim searchFile As New StreamReader(strFILENAME)
        Dim s As String
        Dim li As New List(Of String)
        While searchFile.EndOfStream = False
            s = searchFile.ReadLine
            If s.Contains(searchString) Then
            End If
        End While
        Select Case li.Count
            Case 0
                ' No hits
            Case 1
                ' single hit
            Case Else
                ' Multiple hits, display choice to user
        End Select
end sub

Gruff 04-11-2014 09:25 AM

If you want to search by multiple fields (Name, Year, Rating, Etc...) then you should really be using a true database not a text file.

Year and Rating would be true numbers not strings.
You could search by simple database queries.

WHERE Name = 'Rio Bravo'
AND Year BETWEEN 1969 and 1972
AND Rating > 3

All times are GMT -6. The time now is 11:37 AM.

Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
Search Engine Optimisation provided by DragonByte SEO v2.0.15 (Lite) - vBulletin Mods & Addons Copyright © 2018 DragonByte Technologies Ltd.
All site content is protected by the Digital Millenium Act of 1998. Copyright©2001-2011 MAS Media Inc. and Extreme Visual Basic Forum. All rights reserved.
You may not copy or reproduce any portion of this site without written consent.