Hi guys,im new to programming I have to deliver this project where I have a lisbox that loads a textfile, with the price of the Items
Dim parts As String() = Strings.Split(Item, "€__")
here is the image for easier understanding (https://i.stack.imgur.com/IVXeG.png)
When i press the button discount, it opens a panel with a listbox and loads the same textfile as the listbox with the total above. I want to select the items from the listbox discount to send to the listbox total as a free item so (**-**Item, "€__") as a negative value so it can subtract from the 7,25 bill
From here you can see all my code
<pre>
Imports System.IO
Public Class Form1
Dim Total
Public Sub BtnConta_Click(sender As Object, e As EventArgs) Handles BtnConta.Click
Dim filePath As String = "C:\Mesa1.txt"
Using writer As New System.IO.StreamWriter(filePath)
For Each item As Object In ListBoxConsumo.Items
writer.WriteLine(item.ToString())
Next
End Using
MessageBox.Show("ListBox items saved to file.")
Dim quoteArray As String() = File.ReadAllLines("C:\Mesa1.txt")
For Each Item As String In quoteArray
Dim parts As String() = Strings.Split(Item, "€__")
Dim number As Decimal
If Decimal.TryParse(parts(0), number) Then
End If
Total = (Total + number)
Next
TxtBoxTotal.Text = Total
End Sub
Private Sub BtnDesconto_Click(sender As Object, e As EventArgs) Handles BtnDesconto.Click
PanelDesconto.Show()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
ListBoxConsumo.Items.Add("1,45€__Pão")
End Sub
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim filePath As String = "C:\Mesa1.txt"
If File.Exists(filePath) Then
Dim lines() As String = File.ReadAllLines("C:\Mesa1.txt")
ListBoxConsumo.Items.Clear()
For Each line As String In lines
ListBoxConsumo.Items.Add(line)
Next
End If
End Sub
Private Sub Button14_Click(sender As Object, e As EventArgs) Handles Button14.Click
PanelDescontar.Hide()
End Sub
Private Sub BtnDescontar_Click(sender As Object, e As EventArgs) Handles BtnDescontar.Click
Dim filePath As String = "C:\Mesa1.txt"
If File.Exists(filePath) Then
Dim lines() As String = File.ReadAllLines("C:\Mesa1.txt")
ListBoxFinal.Items.Clear()
For Each line As String In lines
ListBoxFinal.Items.Add(line)
Next
End If
PanelDescontar.Show()
End Sub
Private Sub BtnApagar_Click(sender As Object, e As EventArgs) Handles BtnApagar.Click
For Each selectedItem As Object In ListBoxFinal.SelectedItems
ListBoxConsumo.Items.Add(selectedItem)
Next
End Sub
End Class
What I have tried:
I tried another way of giving a discount using a % to discount to the total, didnt go very well.