Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 150,090 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,808 people online right now. Registration is fast and FREE... Join Now!




String.Split and changing the contents

 
Reply to this topicStart new topic

String.Split and changing the contents

IHeessels
4 Jun, 2008 - 11:21 AM
Post #1

New D.I.C Head
*

Joined: 18 Mar, 2008
Posts: 10


My Contributions
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)



User is offlineProfile CardPM
+Quote Post

AdmSteck
RE: String.Split And Changing The Contents
4 Jun, 2008 - 12:01 PM
Post #2

D.I.C Head
**

Joined: 26 Nov, 2005
Posts: 57


My Contributions
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.)
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 12:01AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month