I have been given an assignment where a company requires an application that displays coffee usage information for the managers. I've been given sample data for last years monthly usage amounts in kilos which are: 400.5, 450, 475.5, 336.5, 457, 325, 220.5, 276, 300, 320.5, 400.5 and 415.

I need to create a form which will allow the user to enter and store monthly amounts in an appropriate data structure. The form also has to calculate the total usage for the 12 month period and average monthly usage. A further requirement is for the users to be able to display the monthly totals in ascending and descending order of the monthly usage amounts.

I am sort of a Visual Basic newbie and I would just like ideas on how I would meet these requirements. What to use to displays the results, etc.

Thanks

Dani AI

Generated

A practical, step-by-step approach for a beginner: build a simple WinForms form that stores monthly values in an in-memory collection (so you can test sorting and calculations quickly), then add a save/load feature later. was right to push storage options, and , starting with an in-memory collection keeps the UI and logic easier to understand before you learn files or databases.

Keep the UI minimal: a single input control (TextBox or NumericUpDown) plus an Add button, a DataGridView or ListBox to show the months and values, and buttons for Calculate, Sort Asc, Sort Desc, Save and Load. Validate every entry with Decimal.TryParse so bad input is rejected. Use Decimal for amounts so rounding is predictable.

A compact VB.NET pattern (conceptual) to illustrate validating, storing, computing and sorting:

Dim amounts As New List(Of Decimal)

' Add validated input
Dim val As Decimal
If Decimal.TryParse(txtValue.Text, val) Then
  amounts.Add(val)
  dataGridView.DataSource = Nothing
  dataGridView.DataSource = amounts.Select(Function(x) New With {.Value = x}).ToList()
End If

' Sum and average
Dim total As Decimal = 0D
For Each d In amounts
  total += d
Next
Dim average As Decimal = If(amounts.Count > 0, total / amounts.Count, 0D)

' Sort
amounts.Sort()        ' ascending
amounts.Reverse()     ' descending (after Sort)

When ready to persist data across sessions, start with a CSV text file (easy to read and debug) using File.WriteAllLines / File.ReadAllLines. If the application will grow, consider a lightweight database (SQLite). For the basics of arrays and file I/O in VB, see Microsofts documentation: and .

Troubleshooting tips: always guard against empty lists before dividing, handle culture decimal separators when parsing, and keep UI updates (binding) simple so the logic is easy to follow while learning.

Recommended Answers

All 3 Replies

Do you know anything about storing data in files and retrieving it?
...what about databases?

Either one would do well for your program.

Of course, if it does not need to store data for more than one "session", you could just store the data in arrays.

Do you know anything about storing data in files and retrieving it?
...what about databases?

Either one would do well for your program.

Of course, if it does not need to store data for more than one "session", you could just store the data in arrays.

No I don't know anything about storing data files and receiving them. I have heard classmates say they're using arrays but I don't know what they are!

...then it is time to study.
You will really need to know your storage options if you want to make data-centric applications. Study how arrays work firs, then more complex types.

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.