VB.NET School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

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

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




Stream write row from a listview problem

 

Stream write row from a listview problem

sharpy

8 Jan, 2009 - 03:17 AM
Post #1

D.I.C Regular
Group Icon

Joined: 2 Jun, 2007
Posts: 273



Thanked: 11 times
Dream Kudos: 275
My Contributions
Hi All

I have a small problem with this code. I am adding information to my listview from multiple textboxes. As I add the info I automatically update a text file with the code shown below. The problem I have is

When I add my first row the code will not write the data back to the text file, however if I add a second row the code is quite happy to write both rows of data back to the text file. I cannot for the life of me see what is wrong.



CODE
'Write tool info to text file
        Dim outputstream As StreamWriter = File.CreateText("C:\MFSProFiles\" & CObj(PartNoTextBox.Text) & ".tme")
        Dim s As Short
        Dim newstr(27) As String
        Dim I As Integer
        Dim Toolnum As String
        Dim process As String
        Dim Description As String
        Dim Feed As String
        Dim Speed As String
        Dim Time As String
        Dim Grade As String
        Dim tooldia As String
        Dim numteeth As String
        Dim FPT As String
        Dim CSS As String
        Dim Cuttype1 As String
        Dim Cutdescription1 As String
        Dim Cutlength1 As String
        Dim Numcuts1 As String
        Dim rapidlength1 As String
        Dim totalrapid As String
        Dim fourthindex1 As String
        Dim Numfourthindexes As String
        Dim fifthindex As String
        Dim Numfifthindexes1 As String
        Dim Startclearance As String
        Dim endclearance1 As String
        Dim drawingref1 As String
        Dim rapidtime As String
        Dim fourthtime As String
        Dim fifthtime As String
        Dim totaltooltime1 As String

        Dim ItemCount As Integer


        ItemCount = Me.ListView1.Items.Count
        For I = 0 To ItemCount - 1
            For s = 0 To 27
                newstr(s) = ListView1.Items.Item(I).SubItems(s).Text
            Next
            Toolnum = newstr(0)
            process = newstr(1)
            Description = newstr(2)
            Feed = newstr(3)
            Speed = newstr(4)
            Time = newstr(5)
            Grade = newstr(6)
            tooldia = newstr(7)
            numteeth = newstr(8)
            FPT = newstr(9)
            CSS = newstr(10)
            Cuttype1 = newstr(11)
            Cutdescription1 = newstr(12)
            Cutlength1 = newstr(13)
            Numcuts1 = newstr(14)
            rapidlength1 = newstr(15)
            totalrapid = newstr(16)
            fourthindex1 = newstr(17)
            Numfourthindexes = newstr(18)
            fifthindex = newstr(19)
            Numfifthindexes1 = newstr(20)
            Startclearance = newstr(21)
            endclearance1 = newstr(22)
            drawingref1 = newstr(23)
            rapidtime = newstr(24)
            fourthtime = newstr(25)
            fifthtime = newstr(26)
            totaltooltime1 = newstr(27)


            outputstream.WriteLine(Toolnum & "," & process & "," & Description _
            & "," & Feed & "," & Speed & "," & Time & "," & Grade & "," & tooldia & "," _
            & numteeth & "," & FPT & "," & CSS & "," & Cuttype1 & "," _
            & Cutdescription1 & "," & Cutlength1 & "," & Numcuts1 & "," & rapidlength1 _
            & "," & totalrapid & "," & fourthindex1 & "," & Numfourthindexes & "," _
            & fifthindex & "," & Numfifthindexes1 & "," & Startclearance & "," _
            & endclearance1 & "," & drawingref1 & "," & rapidtime & "," & fourthtime & "," & fifthtime _
            & "," & totaltooltime1)
        Next I
        outputstream.Close()



Can anybody see what the problem is

Thanks in advance

User is offlineProfile CardPM
+Quote Post


dklingman

RE: Stream Write Row From A Listview Problem

8 Jan, 2009 - 05:04 AM
Post #2

D.I.C Regular
Group Icon

Joined: 23 Dec, 2008
Posts: 254



Thanked: 31 times
My Contributions
my first question is when does the code actually get called? the other question that i have and you probably have already done this, but i'm still going to ask. have you stepped through the code line by line?
User is offlineProfile CardPM
+Quote Post

sharpy

RE: Stream Write Row From A Listview Problem

8 Jan, 2009 - 08:24 AM
Post #3

D.I.C Regular
Group Icon

Joined: 2 Jun, 2007
Posts: 273



Thanked: 11 times
Dream Kudos: 275
My Contributions
QUOTE(dklingman @ 8 Jan, 2009 - 01:04 PM) *

my first question is when does the code actually get called? the other question that i have and you probably have already done this, but i'm still going to ask. have you stepped through the code line by line?


Hi dklingman

Thanks for the response I have now found the problem and corrected it.

CODE
'If ListView1.Items.Count = 1 Then
                'Return
                'End If


                'Write data to text file
                writedata()


Basically the code in my first post is in a private sub called writedata() as I use this code in several places. For some reason I had a conditional statement before the call for the writedata sub. I had been looking for the problem in the private sub and not where the sub was being called. Thanks for the making me look through my code again and spotting the obvious. I really cannot remember why I put that piece of code there as it has no use. I must have been trying something and forgot to delete it.

Best regards

Sharpy biggrin.gif

User is offlineProfile CardPM
+Quote Post

dklingman

RE: Stream Write Row From A Listview Problem

8 Jan, 2009 - 08:41 AM
Post #4

D.I.C Regular
Group Icon

Joined: 23 Dec, 2008
Posts: 254



Thanked: 31 times
My Contributions
sure no problem. that's why i always ask about stepping through the code from beginning to end even if it takes a little while. i'd be willing to bet that 90% of the time when i do that i find my mistakes.

This post has been edited by dklingman: 8 Jan, 2009 - 08:42 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 05:04AM

Live VB.NET Help!

Be Social

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

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month