Currently I am designing a inventory system, however jumping straight into vb.net was easier said than done. At the moment, all the information stored goes to two places, one being a master file that has all the information ever inputted, and the other being an individual file that is created and named based on the Tag number assigned. The current input fields are:

  1. Tag Number
  2. Data Installed
  3. Location/Office
  4. Type(Computer base unit, monitor, desk, file cabinet, ect)
  5. Notes
  6. Name of Owner

Once inputed the tag number (####.txt) is saved as an independent file with the information as well as the information being stored in the file inventory.txt. I want to be able to search for a certain item using a text box and a keyword, or whether or not it be a computer base unit, or Owners name or anything along those lines and after populating what you want to search for I want to be able to have all the data matching that search information be pulled up.

Another part of the project which may not be possible is a part to edit existing data in 2 ways. Upon submitting the edit I wish to be able to over write the information stored in inventory.txt and I want to add all new information to the independent file. The Tag number will never change but I do want to be able to add a new data, new office, new notes ect. Also doing that is it possible to change the file name, deleting the old one creating a file called ####decommissioned.txt if the computer or desk or anything is no longer being used.

Currently I have a search script that will bring all the information into a msg box, but I have a feeling that it is not the best way to do things. The code for that is:

Dim OpenAnswerFile As New OpenFileDialog
        Dim strFileName() As String 
        Dim tempStr As String = "" 
        If OpenAnswerFile.ShowDialog = DialogResult.OK Then 
            strFileName = IO.File.ReadAllLines(OpenAnswerFile.FileName) 
            For Each myLine In strFileName 
                tempStr &= myLine & vbNewLine 
            Next
            MsgBox(tempStr) 
        End If

Which is a code I found from codeorder. I would like to also be able to add a line break upon saving to make reading the code in the msgbox much easier.

If I am unclear on anything, which I assume I may be, please let me know and I will get back to you ASAP. What I am asking may not even be possible, but any help is much appreciated

Recommended Answers

All 11 Replies

Unless your system is going to have to handle millions of items I would suggest using a list and a custom structure to hold the data. Now you have access to searching, sorting, inserting, and deleting. The code to load and save the list is very straight forward. From here you have many options to display and edit your data.

An example of the custom structure might look like this:

Enum EquipmentType
    computer_base_unit
    monitor
    desk
    file_cabinet
    misc
End Enum
Public Class Item
    'The boolean is for active or decommisioned
    Dim Tag As New KeyValuePair(Of Integer, Boolean)
    Dim InstalledDate As New DateTime
    Dim Location As String
    Dim Equipment As EquipmentType
    Dim Owner As String
    Dim Notes As String
End Class

Your list could be declared like this:

Dim Items As New List(Of EquipmentItem)

When you save the data to the file if you put one item per line with an unusual delimiter("|") it simplifies your code a lot.

This also means only one file to deal with.

On the other hand, if you expect a huge amount of data, a database would probably be preferred.

How would I add a script to automatically populat the text box that controls the item name? I am wishing to make items have specific names according to what they are, like a computer base unit would be CBU-1000 then the next one would be CBU-1001, something like that. I want to make it so it auto populates if that is at all possible.

There are many options for that. It's hard to decide on a recommendation without seeing your code.

The code is pretty raw right now, most the UI is pretty much done abut most the code has to do with submitting the to files and that's about it, there is one search function which is displayed up in the original post. The real chunk is just deciding if text boxes and buttons are visible or if visibility is set to false, other wise the program is pretty much bare. I learned vb6 but vb12 is much much different.

How would I add a script to automatically populat the text box that controls the item name?

You have to deicde what is going to trigger filling the textbox with a value. Without seeing your data structure or methods for adding data, how it's done is really wide open.

Per say I wanted to fill the textbox upon choosing an item from the drop down list, how would the program be able to keep track of the last used number assuming the pattern would be CBU-1000, CBU-1001.... How would the program track what's next after closing?

You could use a class level Integer(MyInteger). Then after everytime you add a new item increment it by one. Handle the index changed event then something like this:

TextBox1.Text = ComboBox1.SelectedItem & "-" & MyInteger.ToString
MyInteger += 1

Would that work if the program is closed and reopened, would the number stay dynamic or would it always go back and start at 1000?

You could create an Application Setting. Or just read the highest one used when your program loads and set the integer from that.

So if I wanted to read the highest when bring them in would I just input them all and make a counter while the inputed file names are equal to a predetermined value? I am not fimilar with Application settings, I am sorry for all the questions, I've never formally learned VB.net just vb6 and they do not exactly go hand and hand.

Declare a class level variable for the max number and initialize it to 0. When you loop through the data, extract the number in the name and compare it to the max number, if it's more, then max number equals this one. If you loop through all your data you'll be left with the highest number assigned and you can go from there.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.