Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Question on Subscripts in Visual Basic.Net

Posted on 2011-09-29
8
Medium Priority
?
314 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 40
ID: 36858847
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
ID: 36891421
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
ID: 36891961
Can you show us a screenshot of the form? Why are you not using a control like grid?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:jjc9809
ID: 36898126
I have created my lines using textboxes in a grid like format.  
Form-Layout.jpg
0
 
LVL 40
ID: 36898310
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
ID: 36954277
I am currently working on doing another way.
0
 
LVL 40
ID: 36932223
If the other way is a grid, then the question has been answered.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 36932698
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

722 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