Hi guys, I'm having some problems with sum of array values and I hope you can help me out. I have a form from which there are multiple values added and saved to txt file. Than on button click, these values are read from txt file to array and shown in listbox2. Now there are date, some true/false value,...whats important to me that there are some, let's say "employees listed in the ListBox1. There's numeric up/down on the form.
Now what I want in my listbox2 is in first column the name of employee that was chosen in the Listbox1 and the number that was selected in the numeric up/down. Now in array the names of employees can repeat, I want the sum of all values that were chosen in numeric up/down for each employee. And at the end I need total sum of all the values from numeric up/down.
This is my code:
Imports System.IO Public Class Form1 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load ListBox1.Items.Add("Mercedes") ListBox1.Items.Add("Citroen") ListBox1.Items.Add("BMW") ListBox1.Items.Add("Opel") ListBox1.Items.Add("Renault") End Sub Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click Dim table1() Dim tablefull As Boolean If Not tablefull Then ReDim table1(0) tablefull = True Else ReDim Preserve table1(UBound(table1) + 1) End If Dim date_short As String date_short = Format(DateTimePicker1.Value, "dd/MM/yyyy") Dim placano As String If CheckBox1.Checked = True Then placano = "True" Else placano = "False" End If Dim work_done As Integer work_done = NumericUpDown1.Value Dim status As Integer If RadioButton1.Checked = True Then status = "1" ElseIf RadioButton2.Checked = True Then status = "2" ElseIf RadioButton3.Checked = True Then status = "3" End If Dim data1 As System.IO.StreamWriter data1 = New System.IO.StreamWriter("\data.txt", True) data1.Write(date_short & vbTab) data1.Write(placano & vbTab) data1.Write(ListBox1.SelectedIndex & vbTab) data1.Write(work_done & vbTab) data1.Write(status) data1.WriteLine() data1.Close() End Sub Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click Dim FileName As String = "\data.txt" Dim table1() As String = File.ReadAllLines(FileName) ListBox2.Items.Clear() For Each obj As Object In table1 ListBox2.Items.Add(obj) Next Dim RowCount = table1.GetUpperBound(0) - 1 Dim ColumnCount = table1.GetUpperBound(1) - 1 End Sub End Class
I hope I did explain well and that I didn't complicate 2 much.
I want also the results in the listbox2 to look "cosmetic" and add columt names, some stripes so separate rows, in the total sum of numeric up/down to write "Total:". Is this a thing of an array or does it need to be set in Listbox?
tnx a lot