• We just launched and are currently in beta. Join us as we build and grow the community.

Creating a Management Solution in Visual Basic #3 Filtering Records #1 Design and Filtering Function

Horizzon

Crash Log Analyst
H Rep
0
0
0
Rep
0
H Vouches
0
0
0
Vouches
0
Posts
87
Likes
99
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 300 XP
Introduction:
This tutorial is going to be on how to create a record management solution in Visual Basic.

This Tutorial:
Since this is a multi-part tutorial series, this tutorial is going to be on creating the first part of the filter records GUI.

What Will Filtering Do?
The filtering within the program will allow the user to filter through the entire file of results and perform additional changes to any single record or a group of records based off the filtering criteria.

The filtering GUI will allow the user to search by a single piece of information, a group of pieces of information, or index numbers.

To create the GUI, go to Project > Add Windows Form... > select Windows Form, name it filterGUI and click OK.

The Design:
Before we can create any code for the filtering GUI, we need to create the design for the GUI. The GUI will contain;
Textbox - named filterText - to allow the user to enter search criteria.
Button - named filterButton, text set to "Fitler" - to allow the user to begin the filtering/searching process.
Listbox - named filterList - to list each of the records returned from the filtering/searching process.
Button - named delButton, text set to "Delete" - deletes the selected records.
Button - named modifyButton, text set to "Modify" - lets the user modify that specific record.
Button - named copyButton, text set to "Copy" - lets the user copy the selected record(s) to their clipboard.

The Filtering Function:
We won't be making any of the actual buttons within the design work in this tutorial so instead we are going to create a function which will be used once one or more of the buttons have been pressed, the filtering function.

This function will take a string of information to filter the results through, and an option list of records - if there are no parsed records, we will start from fresh from the management file.

  1. Imports System.IO

  2. Public

    Class filterGUI
  3. Private

    Function

    filterRecords(ByVal

    filter As

    String

    , Optional

    ByVal

    records As

    List(Of String

    ) = Nothing

    )
  4. Dim

    recs As

    List(Of String

    ) = New

    List(Of String

    )
  5. If

    (Not

    records Is

    Nothing

    ) Then
  6. For

    Each

    s As

    String

    In

    records
  7. recs.Add(s)
  8. Next
  9. Else
  10. 'Get from file
  11. Using sr As

    New

    StreamReader(Form1.filePath)
  12. While

    (sr.Peek <> -1)
  13. recs.Add(sr.ReadLine())
  14. End

    While
  15. End

    Using
  16. End

    If
  17. If

    (recs.Count > 0) Then
  18. Dim

    retRecords As

    List(Of String

    ) = New

    List(Of String

    )
  19. For

    Each

    record As

    String

    In

    recs
  20. If

    (record.Contains(filter)) Then

    retRecords.Add(record)
  21. Next
  22. Return retRecords
  23. Else

    : MsgBox("No records found!"

    )
  24. End

    If
  25. Return ""
  26. End

    Function
  27. End

    Class

This function gets all the available records (either from the parameter records or from the management file if no records are parsed to the records parameter), then iterates through them adding each one that contains the filtering string (from the arguments/parameters of the function, 'filter') to a new list of strings. It then returns the list of strings which all contain the filtering string. If an error occurs or no filtered records are found, a blank string is returned 'Return ""'

 

452,292

324,360

324,368

Top