Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 293
  • Last Modified:

Visual Studio 2005 Application hanging with Not Responding on Run

Hi Everyone,

Visual STudio 2005 application is hanging and giving me "Not Responding" on the form at top.  Please see coding where the error shows.  The computer is not even getting to my code to do anything.

See attached
ErrorDocument--5-.pdf
0
jjc9809
Asked:
jjc9809
  • 16
  • 15
1 Solution
 
Daniel ReynoldsSoftware Applications Developer / IntegratorCommented:
Are you incrementing Counter as you go thru your loop? I couldn't tell from your code if you were or not.
0
 
Jacques Bourgeois (James Burger)Commented:
An Application Not Responding is often due to an endless loop.

0
 
Jacques Bourgeois (James Burger)Commented:
Finishing the previous one that was sent by mistake.

An application Not Responding is often due to an endless loop.

A StackOverflow is often due to a recursion that goes to deep.

Your code does not begin when you think it does. Something called your method. And I am quite sure that this something is calling your method (CreateJV) repetitively.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
jjc9809Author Commented:
The program is writing out data to a text file for the mainframe.  There are no field names changing with use of a counter to increment such as TextFile1 to TextFile2 and so on using TextFile  & I.
It just loops and puts contents in an array list.  I am having problems with getting the application to run.  yesterday, it ran fine with gong to Line 85.  Today it hangs up at Line 85 and I get Not Responding error on the top of the Data Entry Form and the Stack Trace Error you see.  It is never getting to code to do anything.  It hans at the Dim SW as New StreamWriter("JVFILE,TXT")

jjc9809
0
 
Jacques Bourgeois (James Burger)Commented:
Look at the loop that calls CreateJV. This is probably the source of your problem.
0
 
jjc9809Author Commented:
The CreateJV() subroutine is called only once in the program when the Button Click Event Button WriteOut JV is selected.  CreateJV() is not being called multiple times.  This application has always worked with no problems several years now since 2006.  So there is no issue with the CreateJV() subroutine.

I feel it is a software issue with VS 2005 with the Windows 7.  This same programs works on my computer at home on Visual Stduio 2005 Stanadard Edition and the 20101 Visual Studio Professional Edition with no issues.  All records write out.  The issue is hapeening only at work.  I also have other rpograms in Office doing the same thing "Not Responding" especially Excel and Word.

jjc9809
0
 
Jacques Bourgeois (James Burger)Commented:
If you get a StackOverflow on opening a StreamWriter and the application does not loop, then the error reported is not the right one. This happens from time to time :-)

I would put a breakpoint (in the development environment) or a MessageBox (on the compiled application) on the problem line to make sure that it is really called only once and that the problem happens at that point.

When you say that it works at home, do you also have Windows 7? If no, then it could be a security issue. Windows 7 has more restrictions than XP when dealing with the file system. What is the directory you are trying to write in?

Does this happens on any Windows 7 computer or only one? If only one, and if you also have problems with Office, then the problem is not in your application, but something on the computer is holding up processor time.

When you say that it work at home and not at work, does it mean when you compile at home vs when you compile at work, or do you mean when the application is already compiled and you run it in the 2 different environmens.
0
 
jjc9809Author Commented:
Hi

I have Windows 7 Ultimate at home and at work I have Windows 7 Professional.  This problem has not been happening until this year.  With Windows XP Professional I did not have any issues with the application .  It ran fine until this year.  I run the compiled version from work which I copied to a 8gb Flash Drive and then I open on my laptop at home with Visual Studio 2005 Standard Version and run.  I get no errors.  Also, I converted a copy of the compiled application from work and converted to Visual Studio 2010 professional on my home computer and it runs with no issues up to 87 lines which is the last line code I put in.  At work the same program hangs up even in Visla Studio 2010 Professional on my work computer.  At work we have not completely changed over to Visual STudio 2010.  They want us to use Visual Studio 2005 Professional for the time being.

I do not know what is happening.

0
 
jjc9809Author Commented:
Hi,

I have attached some parts of the application.  I can't send the whole application becuase it is 85.7 mb

I am showing some of what is taking place.  The application creates a text file which is sent to the mainframe with a bat file.  The maimframe writes out the JCL on the fly and send the data to another place for prcessing.  CreatePUT and Perform Put subroutines does this.

JV-APPLICATION.doc
0
 
Jacques Bourgeois (James Burger)Commented:
Something new in your .doc document:

All lines of code run until it gets to NEXT

How many loops does it do before it gives you the problem?

What is the value of Contents.Count() when you start the loop : For Counter = 0 To Contents.Count() - 1?

That is a lot of concatenations to do inside of a loop.

The counter might use the stack. You do a lot of concatenations in the loop which might also use the stack. I do not know the exact internal working of those, but doing a lot of things in a loop that ends up with a StackOverflow surely point to something of that kind. This might lead up to a StackOverflow.

If there is more data at work than there is at home, then you can end up with a problem at work that you do not have at home. If there is more data to treat than in the past, you might have a scalability issue where the extra amount of data breaks an application that used to work in the past.

Both for performance issues and ressource issues, when you do a lot of concatenations is is recommended to use a System.Text.StringBuilder object. This might solve your problem.

And where is the real issue. In the pdf of your first post, the error was on initializing the StreamWriter.
In the doc file you have that comment that everything works up to NEXT.
There is a contradiction there, because the StreamWriter comes long before the NEXT.

And what is the StreamWriter doing there anyway. It is declared and closed, but not used in between. Is this the real code or is it an edited version? Edited versions have the bad habit of always leaving the source of the problem in the parts that are edited out.
0
 
jjc9809Author Commented:
Hi,

Oh, I see this comment, " All lines of code run until it gets to NEXT"  I mean when the application runs correctly and does not stop at the SW part like it is doing now. No the application is not running at all correctly now and even getting to Next.   We have run this application since 2006 on the network with no issues.  Of course we were using Windows XP.  Right now, the computer is never getting to Next, because it is dying at the SW part,  You are not even having your first loop occur to write out even the first line now.

We may have to open the application in Windows XP Mode and see if it hangs up there.  If it does not hangup we will know then it is maybe a Windows 7 issue.  A colleague of miond mentioned this to me.  



0
 
Jacques Bourgeois (James Burger)Commented:
Windows 7 issues of this type are often dependant on the directory. A lot of stuff what was readily accessible in Windows XP now needs to be moved in the User folder since Vista. The directory in which the file is created might be your problem. However, it should not give you a StackOverflow.
0
 
jjc9809Author Commented:
I have attached a sample of writeout to textfile with concatenations.  I will have 100 lines that can writeout.

Select Case JVFORMA.Type28.Text
                Case "01"
                    Select Case JVFORMA.VProv28.Text
                        Case "V"

                            Call sw.WriteLine("L JV  002 " & JVFORM.Batch.Text & "JV  002 " & _
                JVFORM.JVNumber.Text & "   " & JVFORMA.Type28.Text & _
                JVFORMA.Fund28.Text & JVFORMA.Agency28.Text & "                " & JVFORMA.BS28.Text & _
                Sline21 & JVFORMA.VProv28.Text & JVFORMA.Vend28.Text & sLine30 & JVFORMA.Desc28.Text & "                      " & TTDebitTextBox1 & _
                Microsoft.VisualBasic.Right("00000000000000" & TTCreditTextBox1, 14) & SLine57 & SLine57)
                        Case Else

                            Call sw.WriteLine("L JV  002 " & JVFORM.Batch.Text & "JV  002 " & _
                JVFORM.JVNumber.Text & "   " & JVFORMA.Type28.Text & _
                JVFORMA.Fund28.Text & JVFORMA.Agency28.Text & "                " & JVFORMA.BS28.Text & _
                sLine31 & sLine31 & sLine31 & TTDebitTextBox1 & _
                Microsoft.VisualBasic.Right("00000000000000" & TTCreditTextBox1, 14) & SLine57 & SLine57)
                    End Select
            End Select



            Select Case JVFORMA.Type28.Text
                Case "02"
                    Select Case JVFORMA.VProv28.Text
                        Case "V"

                            Call sw.WriteLine("L JV  002 " & JVFORM.Batch.Text & "JV  002 " & _
                JVFORM.JVNumber.Text & "   " & JVFORMA.Type28.Text & _
                JVFORMA.Fund28.Text & JVFORMA.Agency28.Text & "                " & JVFORMA.BS28.Text & _
                Sline21 & JVFORMA.VProv28.Text & JVFORMA.Vend28.Text & sLine30 & JVFORMA.Desc28.Text & "                      " & TTDebitTextBox1 & _
                Microsoft.VisualBasic.Right("00000000000000" & TTCreditTextBox1, 14) & SLine57 & SLine57)
                        Case Else

                            Call sw.WriteLine("L JV  002 " & JVFORM.Batch.Text & "JV  002 " & _
                JVFORM.JVNumber.Text & "   " & JVFORMA.Type28.Text & _
                JVFORMA.Fund28.Text & JVFORMA.Agency28.Text & "                " & JVFORMA.BS28.Text & _
                sLine31 & sLine31 & sLine31 & TTDebitTextBox1 & _
                Microsoft.VisualBasic.Right("00000000000000" & TTCreditTextBox1, 14) & SLine57 & SLine57)
                    End Select
            End Select


            'WRITEOUT LINE 1------------------------------------------------------------JVFORMA.Type 03


            Select Case JVFORMA.Type28.Text
                Case "03"
                    Select Case JVFORMA.VProv28.Text
                        Case "V"

                            Call sw.WriteLine("L JV  002 " & JVFORM.Batch.Text & "JV  002 " & _
                JVFORM.JVNumber.Text & "   " & JVFORMA.Type28.Text & _
                JVFORMA.Fund28.Text & JVFORMA.Agency28.Text & "                " & JVFORMA.BS28.Text & _
                Sline21 & JVFORMA.VProv28.Text & JVFORMA.Vend28.Text & sLine30 & JVFORMA.Desc28.Text & "                      " & TTDebitTextBox1 & _
                Microsoft.VisualBasic.Right("00000000000000" & TTCreditTextBox1, 14) & SLine57 & SLine57)
                        Case Else

                            Call sw.WriteLine("L JV  002 " & JVFORM.Batch.Text & "JV  002 " & _
                JVFORM.JVNumber.Text & "   " & JVFORMA.Type28.Text & _
                JVFORMA.Fund28.Text & JVFORMA.Agency28.Text & "                " & JVFORMA.BS28.Text & _
                sLine31 & sLine31 & sLine31 & TTDebitTextBox1 & _
                Microsoft.VisualBasic.Right("00000000000000" & TTCreditTextBox1, 14) & SLine57 & SLine57)
                    End Select
            End Select


            'WRITEOUT LINE 1------------------------------------------------------------ JVFORMA.Type 31


            Select Case JVFORMA.Type28.Text
                Case "31"
                    Select Case JVFORMA.VProv28.Text
                        Case "V"
                            Select Case JVFORMA.Sub28.Text
                                Case " "


                                    Call sw.WriteLine("L JV  002 " & JVFORM.Batch.Text & "JV  002 " & _
                        JVFORM.JVNumber.Text & "   " & JVFORMA.Type28.Text & _
                        JVFORMA.Fund28.Text & JVFORMA.Agency28.Text & "      " & "    " & _
                        JVFORMA.Obj28.Text & "  " & "    " & _
                        Sline21 & JVFORMA.VProv28.Text & JVFORMA.Vend28.Text & sLine30 & JVFORMA.Desc28.Text & "                      " & _
                        TTDebitTextBox1 & _
                        Microsoft.VisualBasic.Right("00000000000000" & TTCreditTextBox1, 14) & "   " & "      " & "     " & SLine50 & SLine50)
                                Case Else

                                    Call sw.WriteLine("L JV  002 " & JVFORM.Batch.Text & "JV  002 " & _
                        JVFORM.JVNumber.Text & "   " & JVFORMA.Type28.Text & _
                        JVFORMA.Fund28.Text & JVFORMA.Agency28.Text & "      " & "    " & _
                        JVFORMA.Obj28.Text & JVFORMA.Sub28.Text & "    " & _
                        Sline21 & JVFORMA.VProv28.Text & JVFORMA.Vend28.Text & sLine30 & JVFORMA.Desc28.Text & "                      " & _
                        TTDebitTextBox1 & _
                        Microsoft.VisualBasic.Right("00000000000000" & TTCreditTextBox1, 14) & "   " & "      " & "     " & SLine50 & SLine50)
                            End Select
                    End Select
            End Select

            'WRITEOUT LINE 1------------------------------------------------------------JVFORMA.Type 31


            Select Case JVFORMA.Type28.Text
                Case "31"
                    Select Case JVFORMA.VProv28.Text
                        Case " "
                            Select Case JVFORMA.Sub28.Text
                                Case " "


                                    Call sw.WriteLine("L JV  002 " & JVFORM.Batch.Text & "JV  002 " & _
                                JVFORM.JVNumber.Text & "   " & JVFORMA.Type28.Text & _
                                JVFORMA.Fund28.Text & JVFORMA.Agency28.Text & "      " & "    " & _
                                JVFORMA.Obj28.Text & "  " & "    " & _
                                sLine31 & sLine31 & sLine31 & _
                                TTDebitTextBox1 & _
                                Microsoft.VisualBasic.Right("00000000000000" & TTCreditTextBox1, 14) & "   " & "      " & "     " & SLine50 & SLine50)

                                Case Else

                                    Call sw.WriteLine("L JV  002 " & JVFORM.Batch.Text & "JV  002 " & _
                                                   JVFORM.JVNumber.Text & "   " & JVFORMA.Type28.Text & _
                                                   JVFORMA.Fund28.Text & JVFORMA.Agency28.Text & "      " & "    " & _
                                                   JVFORMA.Obj28.Text & JVFORMA.Sub28.Text & "    " & _
                                                   Sline21 & JVFORMA.VProv28.Text & JVFORMA.Vend28.Text & sLine30 & JVFORMA.Desc28.Text & "                      " & _
                                                   TTDebitTextBox1 & _
                                                   Microsoft.VisualBasic.Right("00000000000000" & TTCreditTextBox1, 14) & "   " & "      " & "     " & SLine50 & SLine50)
                            End Select
                    End Select
            End Select

            'WRITEOUT LINE 1------------------------------------------------------------JVFORMA.Type 22


            Select Case JVFORMA.Type28.Text
                Case "22"
                    Select Case JVFORMA.VProv28.Text
                        Case "V"
                            Call sw.WriteLine("L JV  002 " & JVFORM.Batch.Text & "JV  002 " & _
                                            JVFORM.JVNumber.Text & "   " & JVFORMA.Type28.Text & _
                                            JVFORMA.Fund28.Text & JVFORMA.Agency28.Text & "      " & JVFORMA.Act28.Text & _
                                            JVFORMA.Obj28.Text & JVFORMA.Sub28.Text & "    " & _
                                            Sline21 & JVFORMA.VProv28.Text & JVFORMA.Vend28.Text & sLine30 & JVFORMA.Desc28.Text & "                      " & _
                                            TTDebitTextBox1 & _
                                            Microsoft.VisualBasic.Right("00000000000000" & TTCreditTextBox1, 14) & JVFORMA.Apr28.Text & "      " & "     " & SLine50 & SLine50)

                        Case Else
                            Call sw.WriteLine("L JV  002 " & JVFORM.Batch.Text & "JV  002 " & _
                                            JVFORM.JVNumber.Text & "   " & JVFORMA.Type28.Text & _
                                            JVFORMA.Fund28.Text & JVFORMA.Agency28.Text & "      " & JVFORMA.Act28.Text & _
                                            JVFORMA.Obj28.Text & JVFORMA.Sub28.Text & "    " & _
                                            sLine31 & sLine31 & sLine31 & _
                                            TTDebitTextBox1 & _
                                            Microsoft.VisualBasic.Right("00000000000000" & TTCreditTextBox1, 14) & JVFORMA.Apr28.Text & "      " & "     " & SLine50 & SLine50)

                    End Select
            End Select

            'WRITEOUT LINE 1------------------------------------------------------------JVFORMA.Type 28



            Select Case JVFORMA.Type28.Text
                Case "23"
                    Select Case JVFORMA.VProv28.Text
                        Case "V"
                            Call sw.WriteLine("L JV  002 " & JVFORM.Batch.Text & "JV  002 " & _
                                            JVFORM.JVNumber.Text & "   " & JVFORMA.Type28.Text & _
                                            JVFORMA.Fund28.Text & JVFORMA.Agency28.Text & "      " & JVFORMA.Act28.Text & _
                                            JVFORMA.Obj28.Text & JVFORMA.Sub28.Text & "    " & _
                                            Sline21 & JVFORMA.VProv28.Text & JVFORMA.Vend28.Text & sLine30 & JVFORMA.Desc28.Text & "                      " & _
                                            TTDebitTextBox1 & _
                                            Microsoft.VisualBasic.Right("00000000000000" & TTCreditTextBox1, 14) & JVFORMA.Apr28.Text & "      " & "     " & SLine50 & SLine50)

                        Case Else
                            Call sw.WriteLine("L JV  002 " & JVFORM.Batch.Text & "JV  002 " & _
                                            JVFORM.JVNumber.Text & "   " & JVFORMA.Type28.Text & _
                                            JVFORMA.Fund28.Text & JVFORMA.Agency28.Text & "      " & JVFORMA.Act28.Text & _
                                            JVFORMA.Obj28.Text & JVFORMA.Sub28.Text & "    " & _
                                            sLine31 & sLine31 & sLine31 & _
                                            TTDebitTextBox1 & _
                                            Microsoft.VisualBasic.Right("00000000000000" & TTCreditTextBox1, 14) & JVFORMA.Apr28.Text & "      " & "     " & SLine50 & SLine50)

                    End Select
            End Select


            'WRITEOUT LINE 1------------------------------------------------------------JVFORMA.Type 28




            Select Case JVFORMA.Type28.Text
                Case "24"
                    Select Case JVFORMA.VProv28.Text
                        Case "V"
                            Call sw.WriteLine("L JV  002 " & JVFORM.Batch.Text & "JV  002 " & _
                                            JVFORM.JVNumber.Text & "   " & JVFORMA.Type28.Text & _
                                            JVFORMA.Fund28.Text & JVFORMA.Agency28.Text & "      " & JVFORMA.Act28.Text & _
                                            JVFORMA.Obj28.Text & JVFORMA.Sub28.Text & "    " & _
                                            Sline21 & JVFORMA.VProv28.Text & JVFORMA.Vend28.Text & sLine30 & JVFORMA.Desc28.Text & "                      " & _
                                            TTDebitTextBox1 & _
                                            Microsoft.VisualBasic.Right("00000000000000" & TTCreditTextBox1, 14) & JVFORMA.Apr28.Text & "      " & "     " & SLine50 & SLine50)

                        Case Else
                            Call sw.WriteLine("L JV  002 " & JVFORM.Batch.Text & "JV  002 " & _
                                            JVFORM.JVNumber.Text & "   " & JVFORMA.Type28.Text & _
                                            JVFORMA.Fund28.Text & JVFORMA.Agency28.Text & "      " & JVFORMA.Act28.Text & _
                                            JVFORMA.Obj28.Text & JVFORMA.Sub28.Text & "    " & _
                                            sLine31 & sLine31 & sLine31 & _
                                            TTDebitTextBox1 & _
                                            Microsoft.VisualBasic.Right("00000000000000" & TTCreditTextBox1, 14) & JVFORMA.Apr28.Text & "      " & "     " & SLine50 & SLine50)

                    End Select
            End Select




            Select Case JVFORMA.Type29.Text
                Case "01"
                    Select Case JVFORMA.VProv29.Text
                        Case "V"

                            Call sw.WriteLine("L JV  002 " & JVFORM.Batch.Text & "JV  002 " & _
                JVFORM.JVNumber.Text & "   " & JVFORMA.Type29.Text & _
                JVFORMA.Fund29.Text & JVFORMA.Agency29.Text & "                " & JVFORMA.BS29.Text & _
                Sline21 & JVFORMA.VProv29.Text & JVFORMA.Vend29.Text & sLine30 & JVFORMA.Desc29.Text & "                      " & UUDebitTextBox1 & _
                Microsoft.VisualBasic.Right("00000000000000" & UUCreditTextBox1, 14) & SLine57 & SLine57)
                        Case Else

                            Call sw.WriteLine("L JV  002 " & JVFORM.Batch.Text & "JV  002 " & _
                JVFORM.JVNumber.Text & "   " & JVFORMA.Type29.Text & _
                JVFORMA.Fund29.Text & JVFORMA.Agency29.Text & "                " & JVFORMA.BS29.Text & _
                sLine31 & sLine31 & sLine31 & UUDebitTextBox1 & _
                Microsoft.VisualBasic.Right("00000000000000" & UUCreditTextBox1, 14) & SLine57 & SLine57)
                    End Select
            End Select



            Select Case JVFORMA.Type29.Text
                Case "02"
                    Select Case JVFORMA.VProv29.Text
                        Case "V"

                            Call sw.WriteLine("L JV  002 " & JVFORM.Batch.Text & "JV  002 " & _
                JVFORM.JVNumber.Text & "   " & JVFORMA.Type29.Text & _
                JVFORMA.Fund29.Text & JVFORMA.Agency29.Text & "                " & JVFORMA.BS29.Text & _
                Sline21 & JVFORMA.VProv29.Text & JVFORMA.Vend29.Text & sLine30 & JVFORMA.Desc29.Text & "                      " & UUDebitTextBox1 & _
                Microsoft.VisualBasic.Right("00000000000000" & UUCreditTextBox1, 14) & SLine57 & SLine57)
                        Case Else

                            Call sw.WriteLine("L JV  002 " & JVFORM.Batch.Text & "JV  002 " & _
                JVFORM.JVNumber.Text & "   " & JVFORMA.Type29.Text & _
                JVFORMA.Fund29.Text & JVFORMA.Agency29.Text & "                " & JVFORMA.BS29.Text & _
                sLine31 & sLine31 & sLine31 & UUDebitTextBox1 & _
                Microsoft.VisualBasic.Right("00000000000000" & UUCreditTextBox1, 14) & SLine57 & SLine57)
                    End Select
            End Select


            'WRITEOUT LINE 1------------------------------------------------------------JVFORMA.Type 03


            Select Case JVFORMA.Type29.Text
                Case "03"
                    Select Case JVFORMA.VProv29.Text
                        Case "V"

                            Call sw.WriteLine("L JV  002 " & JVFORM.Batch.Text & "JV  002 " & _
                JVFORM.JVNumber.Text & "   " & JVFORMA.Type29.Text & _
                JVFORMA.Fund29.Text & JVFORMA.Agency29.Text & "                " & JVFORMA.BS29.Text & _
                Sline21 & JVFORMA.VProv29.Text & JVFORMA.Vend29.Text & sLine30 & JVFORMA.Desc29.Text & "                      " & UUDebitTextBox1 & _
                Microsoft.VisualBasic.Right("00000000000000" & UUCreditTextBox1, 14) & SLine57 & SLine57)
                        Case Else

                            Call sw.WriteLine("L JV  002 " & JVFORM.Batch.Text & "JV  002 " & _
                JVFORM.JVNumber.Text & "   " & JVFORMA.Type29.Text & _
                JVFORMA.Fund29.Text & JVFORMA.Agency29.Text & "                " & JVFORMA.BS29.Text & _
                sLine31 & sLine31 & sLine31 & UUDebitTextBox1 & _
                Microsoft.VisualBasic.Right("00000000000000" & UUCreditTextBox1, 14) & SLine57 & SLine57)
                    End Select
            End Select


            'WRITEOUT LINE 1------------------------------------------------------------ JVFORMA.Type 31


            Select Case JVFORMA.Type29.Text
                Case "31"
                    Select Case JVFORMA.VProv29.Text
                        Case "V"
                            Select Case JVFORMA.Sub29.Text
                                Case " "


                                    Call sw.WriteLine("L JV  002 " & JVFORM.Batch.Text & "JV  002 " & _
                        JVFORM.JVNumber.Text & "   " & JVFORMA.Type29.Text & _
                        JVFORMA.Fund29.Text & JVFORMA.Agency29.Text & "      " & "    " & _
                        JVFORMA.Obj29.Text & "  " & "    " & _
                        Sline21 & JVFORMA.VProv29.Text & JVFORMA.Vend29.Text & sLine30 & JVFORMA.Desc29.Text & "                      " & _
                        UUDebitTextBox1 & _
                        Microsoft.VisualBasic.Right("00000000000000" & UUCreditTextBox1, 14) & "   " & "      " & "     " & SLine50 & SLine50)
                                Case Else

                                    Call sw.WriteLine("L JV  002 " & JVFORM.Batch.Text & "JV  002 " & _
                        JVFORM.JVNumber.Text & "   " & JVFORMA.Type29.Text & _
                        JVFORMA.Fund29.Text & JVFORMA.Agency29.Text & "      " & "    " & _
                        JVFORMA.Obj29.Text & JVFORMA.Sub29.Text & "    " & _
                        Sline21 & JVFORMA.VProv29.Text & JVFORMA.Vend29.Text & sLine30 & JVFORMA.Desc29.Text & "                      " & _
                        UUDebitTextBox1 & _
                        Microsoft.VisualBasic.Right("00000000000000" & UUCreditTextBox1, 14) & "   " & "      " & "     " & SLine50 & SLine50)
                            End Select
                    End Select
            End Select

            'WRITEOUT LINE 1------------------------------------------------------------JVFORMA.Type 31


            Select Case JVFORMA.Type29.Text
                Case "31"
                    Select Case JVFORMA.VProv29.Text
                        Case " "
                            Select Case JVFORMA.Sub29.Text
                                Case " "


                                    Call sw.WriteLine("L JV  002 " & JVFORM.Batch.Text & "JV  002 " & _
                                JVFORM.JVNumber.Text & "   " & JVFORMA.Type29.Text & _
                                JVFORMA.Fund29.Text & JVFORMA.Agency29.Text & "      " & "    " & _
                                JVFORMA.Obj29.Text & "  " & "    " & _
                                sLine31 & sLine31 & sLine31 & _
                                UUDebitTextBox1 & _
                                Microsoft.VisualBasic.Right("00000000000000" & UUCreditTextBox1, 14) & "   " & "      " & "     " & SLine50 & SLine50)

                                Case Else

                                    Call sw.WriteLine("L JV  002 " & JVFORM.Batch.Text & "JV  002 " & _
                                                   JVFORM.JVNumber.Text & "   " & JVFORMA.Type29.Text & _
                                                   JVFORMA.Fund29.Text & JVFORMA.Agency29.Text & "      " & "    " & _
                                                   JVFORMA.Obj29.Text & JVFORMA.Sub29.Text & "    " & _
                                                   Sline21 & JVFORMA.VProv29.Text & JVFORMA.Vend29.Text & sLine30 & JVFORMA.Desc29.Text & "                      " & _
                                                   UUDebitTextBox1 & _
                                                   Microsoft.VisualBasic.Right("00000000000000" & UUCreditTextBox1, 14) & "   " & "      " & "     " & SLine50 & SLine50)
                            End Select
                    End Select
            End Select

            'WRITEOUT LINE 1------------------------------------------------------------JVFORMA.Type 22


            Select Case JVFORMA.Type29.Text
                Case "22"
                    Select Case JVFORMA.VProv29.Text
                        Case "V"
                            Call sw.WriteLine("L JV  002 " & JVFORM.Batch.Text & "JV  002 " & _
                                            JVFORM.JVNumber.Text & "   " & JVFORMA.Type29.Text & _
                                            JVFORMA.Fund29.Text & JVFORMA.Agency29.Text & "      " & JVFORMA.Act29.Text & _
                                            JVFORMA.Obj29.Text & JVFORMA.Sub29.Text & "    " & _
                                            Sline21 & JVFORMA.VProv29.Text & JVFORMA.Vend29.Text & sLine30 & JVFORMA.Desc29.Text & "                      " & _
                                            UUDebitTextBox1 & _
                                            Microsoft.VisualBasic.Right("00000000000000" & UUCreditTextBox1, 14) & JVFORMA.Apr29.Text & "      " & "     " & SLine50 & SLine50)

                        Case Else
                            Call sw.WriteLine("L JV  002 " & JVFORM.Batch.Text & "JV  002 " & _
                                            JVFORM.JVNumber.Text & "   " & JVFORMA.Type29.Text & _
                                            JVFORMA.Fund29.Text & JVFORMA.Agency29.Text & "      " & JVFORMA.Act29.Text & _
                                            JVFORMA.Obj29.Text & JVFORMA.Sub29.Text & "    " & _
                                            sLine31 & sLine31 & sLine31 & _
                                            UUDebitTextBox1 & _
                                            Microsoft.VisualBasic.Right("00000000000000" & UUCreditTextBox1, 14) & JVFORMA.Apr29.Text & "      " & "     " & SLine50 & SLine50)

                    End Select
            End Select

            'WRITEOUT LINE 1------------------------------------------------------------JVFORMA.Type 29



            Select Case JVFORMA.Type29.Text
                Case "23"
                    Select Case JVFORMA.VProv29.Text
                        Case "V"
                            Call sw.WriteLine("L JV  002 " & JVFORM.Batch.Text & "JV  002 " & _
                                            JVFORM.JVNumber.Text & "   " & JVFORMA.Type29.Text & _
                                            JVFORMA.Fund29.Text & JVFORMA.Agency29.Text & "      " & JVFORMA.Act29.Text & _
                                            JVFORMA.Obj29.Text & JVFORMA.Sub29.Text & "    " & _
                                            Sline21 & JVFORMA.VProv29.Text & JVFORMA.Vend29.Text & sLine30 & JVFORMA.Desc29.Text & "                      " & _
                                            UUDebitTextBox1 & _
                                            Microsoft.VisualBasic.Right("00000000000000" & UUCreditTextBox1, 14) & JVFORMA.Apr29.Text & "      " & "     " & SLine50 & SLine50)

                        Case Else
                            Call sw.WriteLine("L JV  002 " & JVFORM.Batch.Text & "JV  002 " & _
                                            JVFORM.JVNumber.Text & "   " & JVFORMA.Type29.Text & _
                                            JVFORMA.Fund29.Text & JVFORMA.Agency29.Text & "      " & JVFORMA.Act29.Text & _
                                            JVFORMA.Obj29.Text & JVFORMA.Sub29.Text & "    " & _
                                            sLine31 & sLine31 & sLine31 & _
                                            UUDebitTextBox1 & _
                                            Microsoft.VisualBasic.Right("00000000000000" & UUCreditTextBox1, 14) & JVFORMA.Apr29.Text & "      " & "     " & SLine50 & SLine50)

                    End Select
            End Select


            'WRITEOUT LINE 1------------------------------------------------------------JVFORMA.Type 29




            Select Case JVFORMA.Type29.Text
                Case "24"
                    Select Case JVFORMA.VProv29.Text
                        Case "V"
                            Call sw.WriteLine("L JV  002 " & JVFORM.Batch.Text & "JV  002 " & _
                                            JVFORM.JVNumber.Text & "   " & JVFORMA.Type29.Text & _
                                            JVFORMA.Fund29.Text & JVFORMA.Agency29.Text & "      " & JVFORMA.Act29.Text & _
                                            JVFORMA.Obj29.Text & JVFORMA.Sub29.Text & "    " & _
                                            Sline21 & JVFORMA.VProv29.Text & JVFORMA.Vend29.Text & sLine30 & JVFORMA.Desc29.Text & "                      " & _
                                            UUDebitTextBox1 & _
                                            Microsoft.VisualBasic.Right("00000000000000" & UUCreditTextBox1, 14) & JVFORMA.Apr29.Text & "      " & "     " & SLine50 & SLine50)

                        Case Else
                            Call sw.WriteLine("L JV  002 " & JVFORM.Batch.Text & "JV  002 " & _
                                            JVFORM.JVNumber.Text & "   " & JVFORMA.Type29.Text & _
                                            JVFORMA.Fund29.Text & JVFORMA.Agency29.Text & "      " & JVFORMA.Act29.Text & _
                                            JVFORMA.Obj29.Text & JVFORMA.Sub29.Text & "    " & _
                                            sLine31 & sLine31 & sLine31 & _
                                            UUDebitTextBox1 & _
                                            Microsoft.VisualBasic.Right("00000000000000" & UUCreditTextBox1, 14) & JVFORMA.Apr29.Text & "      " & "     " & SLine50 & SLine50)

                    End Select
            End Selectave attached a couple of lines to show what I am doing.  
0
 
Jacques Bourgeois (James Burger)Commented:
Lot of concatenations, and we do not see how the thing is called. If it is called in a loop, they a StackOverflow is possible.

Concatenations requires a lot of resources and have a great impact on performance. Very often, you can solve both those problems by using a StringBuilder object to perform the concatenations. Give it a look in the documentation.
0
 
jjc9809Author Commented:
How can one use the string builder class with the writeout code I have indicated?I looked at some samples on the internet, but being new to VB, I got lost.

Do you have any sample code I can look at?

I need to be able to concatenate faster with the writeout.  How dos one use the "&" and "+"  ?
0
 
Jacques Bourgeois (James Burger)Commented:
You use the Append method of the StringBuilder instead of operators, and at the end, call ToString to retrieve the resulting String.
Dim sb As New System.Text.StringBuilder
sb.Append("L JV  002 ")
sb.Append(JVFORM.Batch.Text)
sb.Append("JV  002 ")
sb.Append(JVFORM.JVNumber.Text)
'And so on
sw.WriteLine(sb.ToString)

Open in new window

Since you will probably be writing many lines, do not recreate the StringBuilder each time, because instanciating a StringBuilder takes some time. Reuse the same one:
sb.Clear
'Build the next String

Open in new window

0
 
jjc9809Author Commented:
Can you do the whole string inside the sb.Append and not have so many sb.Appends?

For example, sb.Append("L JV  002 " JVForm.Batch.Text "JV  002 " JVForm.JVNumber.Text)
0
 
jjc9809Author Commented:
Also, is the "&" necessary between the writeout part?  When I leave them out I get blue squigly lines.

jjc9809
0
 
Jacques Bourgeois (James Burger)Commented:
No, you need to use append for each piece you want to add to the StringBuilder.

It might look as if it would take more time than doing it with a concatenation, but it is not. Concatenations are inheretly slows because of the way Strings are manipulated in memory. Each string is an object, each & creates a new object, the result is another object, and the system must clean up after creating all those objects in memory.

The StringBuilder reserves one block of memory and works in that block, so there is only one big String to manipulate for the system.

I do not understand what you mean by "&" necessary between the writeout part? Could you show me the code where you do that and get the wigglies.
0
 
jjc9809Author Commented:
Select Case Type1.Text
                Case "01"
                    Select Case VProv1.Text
                        Case "V"

                            sb.Append("L JV  002 ")
                            sb.Append(Batch.Text)
                            sb.Append("JV  002 ")
                            sb.Append(JVNumber.Text)
                            sb.Append("   ")
                            sb.Append(Type1.Text)
                            sb.Append(Fund1.Text)
                            sb.Append(Agency1.Text)
                            sb.Append("                ")
                            sb.Append(BS1.Text)
                            sb.Append(Sline21)
                            sb.Append(VProv1.Text)
                            sb.Append(Vend1.Text)
                            sb.Append(sLine30)
                            sb.Append(Desc1.Text)
                            sb.Append("                      ")
                            sb.Append(SDebitTextBox1)
                            sb.Append(Microsoft.VisualBasic.Right("00000000000000" SCreditTextBox1, 14))               I get blue squigly line on this part
                            sb.Append(SLine57)
                            sb.Append(SLine57)
                            sw.WriteLine(sb.ToString)


How can I write the (Microsoft.VisualBasic.Right("00000000000000" SCreditTextBox1, 14)) to not have the blue squigly lines.

So you do not need the "&" at all.

jjc9809
0
 
Jacques Bourgeois (James Burger)Commented:
OK, I see your point.

You are passing a parameter to a function. You need the & in there since the String you pass is not added as such to the StringBuilder. You would need a second StringBuilder only for that concatenation, and StringBuilders are not efficient for only a few concatenations.

sb.Append(Microsoft.VisualBasic.Right("00000000000000" & SCreditTextBox1.Text, 14))
0
 
jjc9809Author Commented:
So, I need to change all of my lines of code and use the string builder class for them in order to help the performance problem and get rid of the stack trace.

I did it this way and the blue line goes away as you did it.

 Select Case Type85.Text
                Case "01" To "03"
                    Select Case VProv85.Text
                        Case "V"

                            sb.Append("L JV  002 ")
                            sb.Append(JVFORM.Batch.Text)
                            sb.Append("JV  002 ")
                            sb.Append(JVFORM.JVNumber.Text)
                            sb.Append("   ")
                            sb.Append(Type85.Text)
                            sb.Append(Fund85.Text)
                            sb.Append(Agency85.Text)
                            sb.Append("                ")
                            sb.Append(BS85.Text)
                            sb.Append(Sline21)
                            sb.Append(VProv85.Text)
                            sb.Append(Vend85.Text)
                            sb.Append(sLine30)
                            sb.Append(Desc85.Text)
                            sb.Append("                      ")
                            sb.Append(XKXKDebitTextBox1)
                            sb.Append(Microsoft.VisualBasic.Right("00000000000000" & XKXKCreditTextBox1, 14))
                            sb.Append(SLine57)
                            sb.Append(SLine57)
                            sw.WriteLine(sb.ToString)
                        Case Else

                           
                    End Select
            End Select


I also combined the 01, 02, and 03 in the case statement since all three write out the same way.

0
 
jjc9809Author Commented:
Also,

Where do I place the sb.clear in the coding?  Do I do after each sw.WriteLine(sb.ToString)?  If I do it here won't the writeout be all spaces?

Do I do at the end after each Next in the For Next Loop?  That way you have written your line out and you can clear the sb for the next build.

Sincerely,

jjc9809
0
 
Jacques Bourgeois (James Burger)Commented:
Hi.

Yes, after the WriteLine.

At that point, the data is in the file.

Clear completely empties the StringBuilder, which is the equivalent of a having a new StringBuilder, but is faster than calling New again. That means that you should not execute New again, otherwise you will lose some time each time that New is called.

From what you say in your last post, you are calling that routine in a loop. That would mean that you need to define the StringBuilder before entering the loop. You would then call Clear at the beginning of each loop to make sure that the StringBuilder is emptied before getting in the loop.
0
 
jjc9809Author Commented:
Hi,

Sb.Clear is not a part of the StringBuilder Class I am told.  What do I use instead?  When I place a "." after Sb I get a Blue squigly line.

jjc9809
0
 
Jacques Bourgeois (James Burger)Commented:
Sorry.

I just checked the documentation, and Clear appeared only in Framework 4, that is in Visual Studio 2010. I understand that you are in Visual Studio 2005, so Clear does not exists for you.

Use this instead. It replaces the content of the StringBuilder by an empty string, which is almost the same thing as Clear:
sb.Replace(sb.ToString, "")

Open in new window

0
 
jjc9809Author Commented:
Hi,

I checked on the internet and found this too.  Will this work?  Yours is probably better.

sb.length = 0
sb.capacity = 0



0
 
Jacques Bourgeois (James Burger)Commented:
Length should work, but since we do not know how Lenght works under the hood, I cannot tell wich is better between mine and Length.

Capacity is not a good option however, because you are telling the system that you want to set the number of characters to 0. This is definitively not what you want to do. Capacity is useful only when you work with data that is a fixed length and you know that length.
0
 
jjc9809Author Commented:
Hi,
Iam hoping that changing all the concatenating fields and using the string builder will correct the stack trace error I am encountering.  Today,the system did 85 lines, but I need for all 100 lines to writeout because the comptroller will accept 100 lines.  

Do you feel that the error should clear up after I use the string builder for all concatenations fo 100 lines?
So string builder needs to be used on all lines in order to have the application be faster.  Is this a correct assumption?
0
 
Jacques Bourgeois (James Burger)Commented:
I do think so, because as far as I know, the StringBuilder does not use the stack while concatenations do.

The only way to know for sure is to try it. That is part of the job of being a programmer.
0
 
jjc9809Author Commented:
Thanks so much for helping me.  I am trying to understand VB a little more.  I just got into VB just too late.  I am almost retired with going on 29 years in the accounting field.  I shoudl have stayed an accountant.

Again, Thanks agian for your help.  I am hoping the String Builder Class will get me through this.  I may have some more questions but with another question.

jjc9809
0
 
Jacques Bourgeois (James Burger)Commented:
If this is your first VB application, you are not going in easy. Learning to program nowadays is a lot harder than it was 10 or 15 years ago when the systems were simpler. Even by going the VB route, which might be the easiest, all that stuff is now geared more toward professionals than toward part time programmers.

I wish you good luck and might be there to help for future questions.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 16
  • 15
Tackle projects and never again get stuck behind a technical roadblock.
Join Now