Solved

Question on Subscripts in Visual Basic.Net

Posted on 2011-09-29
8
303 Views
Last Modified: 2012-06-27
I have the folloing Visual Basic Code that will write data out to a text File.

Private Sub CreateJV()

        'Fields are Dimensioned so they can be referenced in the program
        Dim Sline21 As String = "                     "
        Dim sLine30 As String = "                              "
        Dim sLine31 As String = "                               "
        Dim SLine34 As String = "                                  "
        Dim sLine35 As String = "                                   "
        Dim SLine40 As String = "                                        "
        Dim SLine25 As String = "                         "
        Dim SLine22 As String = "                      "
        Dim SLine14 As String = "              "
        Dim SLine57 As String = "                                                         "
        Dim SLine50 As String = "                                                  "
        Dim SLine36 As String = "                                    "
        Dim SCreditTextBox1 As String
        Dim SDebitTextBox1 As String
        Dim TCreditTextBox1 As String
        Dim TDebitTextBox1 As String
        Dim UDebitTextBox1 As String
        Dim UCreditTextBox1 As String
        Dim VDebitTextBox1 As String
        Dim VCreditTextBox1 As String
        Dim WDebitTextBox1 As String
        Dim WCreditTextBox1 As String
        Dim XDebitTextBox1 As String
        Dim XCreditTextBox1 As String
        Dim YDebitTextBox1 As String
        Dim YCreditTextBox1 As String
        Dim ZDebitTextBox1 As String
        Dim ZCreditTextBox1 As String
        Dim AADebitTextBox1 As String
        Dim AACreditTextBox1 As String
        Dim BBDebitTextBox1 As String
        Dim BBCreditTextBox1 As String
        Dim CCDebitTextBox1 As String
        Dim CCCreditTextBox1 As String
        Dim DDDebitTextBox1 As String
        Dim DDCreditTextBox1 As String
        Dim EEDebitTextBox1 As String
        Dim EECreditTextBox1 As String
        Dim FFDebitTextBox1 As String
        Dim FFCreditTextBox1 As String
        Dim GGDebitTextBox1 As String
        Dim GGCreditTextBox1 As String
        Dim HHDebitTextBox1 As String
        Dim HHCreditTextBox1 As String
        Dim IIDebitTextBox1 As String
        Dim IICreditTextBox1 As String
        Dim JJDebitTextBox1 As String
        Dim JJCreditTextBox1 As String
        Dim KKDebitTextBox1 As String
        Dim KKCreditTextBox1 As String
        Dim LLDebitTextBox1 As String
        Dim LLCreditTextBox1 As String
        Dim MMDebitTextBox1 As String
        Dim MMCreditTextBox1 As String
        Dim NNDebitTextBox1 As String
        Dim NNCreditTextBox1 As String
        Dim OODebitTextBox1 As String
        Dim OOCreditTextBox1 As String
        Dim PPDebitTextBox1 As String
        Dim PPCreditTextBox1 As String
        Dim QQDebitTextBox1 As String
        Dim QQCreditTextBox1 As String
        Dim RRDebitTextBox1 As String
        Dim RRCreditTextBox1 As String
        Dim SSDebitTextBox1 As String
        Dim SSCreditTextBox1 As String
        Dim TTDebitTextBox1 As String
        Dim TTCreditTextBox1 As String
        Dim UUDebitTextBox1 As String
        Dim UUCreditTextBox1 As String
        Dim VVDebitTextBox1 As String
        Dim VVCreditTextBox1 As String
        Dim WWDebitTextBox1 As String
        Dim WWCreditTextBox1 As String
        Dim XXDebitTextBox1 As String
        Dim XXCreditTextBox1 As String
        Dim YYDebitTextBox1 As String
        Dim YYCreditTextBox1 As String
        Dim ZZDebitTextBox1 As String
        Dim ZZCreditTextBox1 As String
        Dim AAADebitTextBox1 As String
        Dim AAACreditTextBox1 As String
        Dim BBBDebitTextBox1 As String
        Dim BBBCreditTextBox1 As String
        Dim CCCDebitTextBox1 As String
        Dim CCCCreditTextBox1 As String
        Dim DDDDebitTextBox1 As String
        Dim DDDCreditTextBox1 As String
        Dim EEEDebitTextBox1 As String
        Dim EEECreditTextBox1 As String
        Dim FFFDebitTextBox1 As String
        Dim FFFCreditTextBox1 As String
        Dim GGGDebitTextBox1 As String
        Dim GGGCreditTextBox1 As String
        Dim HHHDebitTextBox1 As String
        Dim HHHCreditTextBox1 As String
        Dim IIIDebitTextBox1 As String
        Dim IIICreditTextBox1 As String
        Dim JJJDebitTextBox1 As String
        Dim JJJCreditTextBox1 As String
        Dim KKKDebitTextBox1 As String
        Dim KKKCreditTextBox1 As String
        Dim LLLDebitTextBox1 As String
        Dim LLLCreditTextBox1 As String
        Dim MMMDebitTextBox1 As String
        Dim MMMCreditTextBox1 As String
        Dim NNNDebitTextBox1 As String
        Dim NNNCreditTextBox1 As String
        Dim OOODebitTextBox1 As String
        Dim OOOCreditTextBox1 As String
        Dim PPPDebitTextBox1 As String
        Dim PPPCreditTextBox1 As String
        Dim QQQDebitTextBox1 As String
        Dim QQQCreditTextBox1 As String
        Dim RRRDebitTextBox1 As String
        Dim RRRCreditTextBox1 As String
        Dim SSSDebitTextBox1 As String
        Dim SSSCreditTextBox1 As String
        Dim TTTDebitTextBox1 As String
        Dim TTTCreditTextBox1 As String
        Dim UUUDebitTextBox1 As String
        Dim UUUCreditTextBox1 As String
        Dim VVVDebitTextBox1 As String
        Dim VVVCreditTextBox1 As String
        Dim WWWDebitTextBox1 As String
        Dim WWWCreditTextBox1 As String
        Dim XXXDebitTextBox1 As String
        Dim XXXCreditTextBox1 As String
        Dim YYYDebitTextBox1 As String
        Dim YYYCreditTextBox1 As String
        Dim ZZZDebitTextBox1 As String
        Dim ZZZCreditTextBox1 As String
        Dim AAAADebitTextBox1 As String
        Dim AAAACreditTextBox1 As String
        Dim BBBBDebitTextBox1 As String
        Dim BBBBCreditTextBox1 As String
        Dim CCCCDebitTextBox1 As String
        Dim CCCCCreditTextBox1 As String
        Dim DDDDDebitTextBox1 As String
        Dim DDDDCreditTextBox1 As String
        Dim EEEEDebitTextBox1 As String
        Dim EEEECreditTextBox1 As String
        Dim FFFFDebitTextBox1 As String
        Dim FFFFCreditTextBox1 As String
        Dim GGGGDebitTextBox1 As String
        Dim GGGGCreditTextBox1 As String
        Dim HHHHDebitTextBox1 As String
        Dim HHHHCreditTextBox1 As String
        Dim IIIIDebitTextBox1 As String
        Dim IIIICreditTextBox1 As String
        Dim JJJJDebitTextBox1 As String
        Dim JJJJCreditTextBox1 As String
        Dim KKKKDebitTextBox1 As String
        Dim KKKKCreditTextBox1 As String
        Dim LLLLDebitTextBox1 As String
        Dim LLLLCreditTextBox1 As String
        Dim MMMMDebitTextBox1 As String
        Dim MMMMCreditTextBox1 As String
        Dim NNNNDebitTextBox1 As String
        Dim NNNNCreditTextBox1 As String
        Dim OOOODebitTextBox1 As String
        Dim OOOOCreditTextBox1 As String
        Dim PPPPDebitTextBox1 As String
        Dim PPPPCreditTextBox1 As String
        Dim QQQQDebitTextBox1 As String
        Dim QQQQCreditTextBox1 As String
        Dim RRRRDebitTextBox1 As String
        Dim RRRRCreditTextBox1 As String
        Dim SSSSDebitTextBox1 As String
        Dim SSSSCreditTextBox1 As String
        Dim TTTTDebitTextBox1 As String
        Dim TTTTCreditTextBox1 As String
        Dim DebitDocTotal As String
        Dim CreditDocTotal As String
        Dim Line As String
        Dim LineValues() As String
        Dim Contents As New ArrayList
        Dim Finished As Boolean = False

        LineValues = Split(Line, ",")
        Contents.Add(LineValues)


        Dim sw As New StreamWriter("JVFile.txt")
        Dim Counter As Integer
        For Counter = 0 To Contents.Count() - 1
            LineValues = CType(Contents(Counter), String())



THe problem is where to put a counter that will increment the data field names everytime.

Where can I put this code to do the For Next loop?


The code:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim tbLine, tbType, tbVProv, tbFund, tbAgency, tbBS, tbVend, tbDesc As TextBox
        For I As Integer = 1 To 1000
            tbLine = GetControlByName("Line" & I)
            tbType = GetControlByName("Type" & I)
            tbVProv = GetControlByName("VProv" & I)
            tbFund = GetControlByName("Fund" & I)
            tbAgency = GetControlByName("Agency" & I)
            tbBS = GetControlByName("BS" & I)
            tbVend = GetControlByName("Vend" & I)
            tbDesc = GetControlByName("Desc" & I)
            If Not IsNothing(tbLine) AndAlso Not IsNothing(tbType) AndAlso Not IsNothing(tbVProv) AndAlso Not IsNothing(tbFund) _
                AndAlso Not IsNothing(tbAgency) AndAlso Not IsNothing(tbBS) AndAlso Not IsNothing(tbVend) AndAlso Not IsNothing(tbDesc) Then
                If tbLine.Text = I Then
                    If tbType.Text = "01" And tbVProv.Text = "V" Then
                        Call sw.WriteLine("L JV  002 " & JVFORM.Batch.Text & "JV  002 " & _
                        JVFORM.JVNumber.Text & "   " & tbType.Text & _
                        tbFund.Text & tbAgency.Text & "                " & tbBS.Text & _
                        Sline21 & tbVProv.Text & tbVend.Text & sLine30 & tbDesc.Text & "                      " & TTTDebitTextBox1 & _
                        Microsoft.VisualBasic.Right("00000000000000" & TTTCreditTextBox1, 14) & SLine57 & SLine57)
                    End If
                End If
        Next I
    End Sub



I will have B Code for Type 01, 02, 03, 22, 23, 24, and 31.

I will write out to a text file, but the problem is placing the code inside a for next loop.

Can you place code for one for next inside another for next?


Also, how can I avoid the Object Instance error when the counter code runs fo the for next loop with the writeout Text File code above?

There is an object instance error tht appears here:


tbLine = GetControlByName("Line" & I)
            tbType = GetControlByName("Type" & I)
            tbVProv = GetControlByName("VProv" & I)
            tbFund = GetControlByName("Fund" & I)
            tbAgency = GetControlByName("Agency" & I)
            tbBS = GetControlByName("BS" & I)
            tbVend = GetControlByName("Vend" & I)
            tbDesc = GetControlByName("Desc" & I)


jjc9809
0
Comment
Question by:jjc9809
  • 3
  • 3
  • 2
8 Comments
 
LVL 40

Expert Comment

by:Jacques Bourgeois (James Burger)
Comment Utility
There are too many things that make no sense at first sight to start trying to understand what you want. Unless there is a small thing I do not see, there is no way to understand what is happening there. Just a small excerpt:

Dim Line As String
Dim LineValues() As String
Dim Contents As New ArrayList
Dim Finished As Boolean = False

LineValues = Split(Line, ",")
Contents.Add(LineValues)

What is the use of all those String variables at the beginning? They do not appear anywhere afterward.

What do you expect to get out of a Split of a String variable (Line) that has nothing in it?

What does CreateJV has to do in The code:?

What is an object instance error tht?

What is a B Code?

In all those lines, which one(s) do you see as a "data field names"?
0
 

Accepted Solution

by:
jjc9809 earned 0 total points
Comment Utility
This program writes out a text file to the mainframe based on data entered into forms.  The string variables represent data field names that hold data in the text file writeout.  I am trying to find a way to do this quicker by using a counter rather than having to write so much code in a lot of If Statements.

Let me explain:  The user enters Lines 1 through 20.  Line 1 for example has these textboxes on a form named:  Line1, Fund1, Agency1, Act1, BS1, Vprov1, Debit1, and Credit1.  The Debit1 and Credit1 are dollar amounts entered for the line.  Currently I have IF statements that check If Line1.text = "1" and VProv1.Text = "V" write out the lines this way in the desired positions.

Each form has twenty lines.  The first 1-20 lines are entered and left open.  The second form 21-40 lines are entered and left open.  There are enough forms for 100 lines or 5 forms currently that can be opened and data entered into them.

I need a way to have all of the text Lines written out using a few lines of code and have the data field names automatically increment.  This keeps me from having to name Line1.Text through Line100.Text manually in code.  Also the other fields should increment as well based ona counter.  When the computer reads that this is line six, the line should write out with what has been entered and put in Line six by the user.

I hope I am making sense.  I can't send the program becuase it its 85.7 megabytes currently which is quite large.

0
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
Can you show us a screenshot of the form? Why are you not using a control like grid?
0
 

Author Comment

by:jjc9809
Comment Utility
I have created my lines using textboxes in a grid like format.  
Form-Layout.jpg
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 40

Expert Comment

by:Jacques Bourgeois (James Burger)
Comment Utility
Why not use a grid as suggested by CodeCruiser? That would make things a lot easier. And "a lot" is a small word.

You can loop through rows or columns in a grid, so that a few lines of code can go through all the grid.

If everything is an individual control, starting to access each of them becomes a big job.
0
 

Author Closing Comment

by:jjc9809
Comment Utility
I am currently working on doing another way.
0
 
LVL 40

Expert Comment

by:Jacques Bourgeois (James Burger)
Comment Utility
If the other way is a grid, then the question has been answered.
0
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
The comment you choose is not the answer. Either paste the answer and accept it, accept another valid answer, or request deletion of this question.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

5 Experts available now in Live!

Get 1:1 Help Now