Writing query to search through a structure
Writing query to search through a structure
Writing query to search through a structure
Writing query to search through a structure
Writing query to search through a structure
Writing query to search through a structure Writing query to search through a structure Writing query to search through a structure Writing query to search through a structure Writing query to search through a structure Writing query to search through a structure Writing query to search through a structure Writing query to search through a structure
Writing query to search through a structure Writing query to search through a structure
Writing query to search through a structure
Go Back  Xtreme Visual Basic Talk > > > Writing query to search through a structure


Reply
 
Thread Tools Display Modes
  #1  
Old 11-28-2012, 02:36 PM
Raleigh Raleigh is offline
Newcomer
 
Join Date: Nov 2012
Posts: 1
Default 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.

structure:
Code:
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
        WriteRecordToFile(video1)
    End Sub
this is my output so far...
Code:
   Sub WriteRecordToFile(ByRef video As VideoData)
        Dim outFile As StreamWriter

        outFile = File.AppendText(strFILENAME)

        outFile.WriteLine(video.name)
        outFile.WriteLine(video.yearProduced)
        outFile.WriteLine(video.runningTime)
        outFile.WriteLine(video.rating)
        outFile.Close()
        ClearForm()
    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
Code:
 Private Sub mnuSearchClick_Click(sender As System.Object, e As System.EventArgs) Handles mnuSearchClick.Click
        InputBox("Enter video name:", "Search")
    End Sub
Reply With Quote
  #2  
Old 04-11-2014, 04:51 AM
JustinCase2 JustinCase2 is offline
Junior Contributor
 
Join Date: Apr 2006
Posts: 324
Default Something like this?

Code:
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
                li.Add(s)
            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
Reply With Quote
  #3  
Old 04-11-2014, 09:25 AM
Gruff's Avatar
GruffWriting query to search through a structure Gruff is offline
Bald Mountain Survivor

Retired Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA - deceased
Posts: 6,440
Default

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.

SELECT * FROM Videos
WHERE Name = 'Rio Bravo'
AND Year BETWEEN 1969 and 1972
AND Rating > 3
__________________
Burn the land and boil the sea
You can't take the sky from me


~T
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Writing query to search through a structure
Writing query to search through a structure
Writing query to search through a structure Writing query to search through a structure
Writing query to search through a structure
Writing query to search through a structure
Writing query to search through a structure Writing query to search through a structure Writing query to search through a structure Writing query to search through a structure Writing query to search through a structure Writing query to search through a structure Writing query to search through a structure
Writing query to search through a structure
Writing query to search through a structure
 
Writing query to search through a structure
Writing query to search through a structure
 
-->