QUOTE(IHeessels @ 4 Jun, 2008 - 12:21 PM)

Hi all,
I need to make a little order program. So I have an Order form and the user can click the listbox to choose an item. With a numeric up/down control they can enter the amount. When the order button is pressed, the order should save to a text file, with the right amount entered. I need to split the string from the listbox and the fourth item of the line should be changed to the amount set in the up/down control.
The lines in the Listbox are four items (article number;article;price;amount)
The saving works fine, but the fourth item in the order.txt remains 0. Below part of the relevant code, hope someone can help me out and tell me what's wrong.
CODE
FileOpen(1, "c:\orders.txt", OpenMode.Output)
Dim item(3) As String
Dim LineOfText As String = ListBox1.SelectedItem.ToString()
If ListBox1.SelectedItem > "" Then
item = LineOfText.Split(";")
NumericUpDown1.Value = item(3)
PrintLine(1, LineOfText & vbCrLf)
End If
FileClose(1)
If I'm reading your code correctly, then I see a few problems. I would re-write the code as follows:
CODE
FileOpen(1, "c:\orders.txt", OpenMode.Output)
Dim item(3) As String
If ListBox1.SelectedItem > "" Then
item = LineOfText.Split(";")
item(3) = NumericUpDown1.Value.ToString()
PrintLine(1, item.ToString() & vbCrLf)
End If
FileClose(1)
You need to switch the assignment of the numeric up down so that it's value is assigned to the 'item' array and not vice versa. You also need to change the printline statement to use the array with the new value instead of the LineOfText variable that was created before appending the quantity. Also, you may not need the 'vbCrLf' in the printline statement since it probably already appends the appropriate line feed at the end, unless you want an empty line between orders. (Please note that I did not test this code and you may need to format the 'item' array to suit your needs.)