[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

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

Utilization of a text file as control

Hi,

I want to use a text file as a control file and using the following layout:
    Report:dbt
    dtBack:-10
    dtForward:30
    Template:template.doc
    Resources:Brown Jim,Smith Tommy

Currently, I use the following code to import the Resources from above but there are in a signle file with no lable (example: Brown Jim,Smith Tommy).  I need the Resources to be added to an Array.

Private Sub OpenControlFile(FNData As String)
'module opens text file and places values into array

  Dim fs As Object
  Dim ts As Object
  Dim f As Object
  Dim strLine As String
 
  Set fs = CreateObject("Scripting.FileSystemObject")
  Set f = fs.GetFile(FNData)
  Set ts = f.OpenAsTextStream()
 
    Do
      strLine = ts.ReadLine
      MyArray = Split(strLine, ",")
     
    Loop While Not ts.AtEndOfStream
    ts.Close
    ArraySize = UBound(MyArray)
End Sub

Thanks!
0
eciabattari
Asked:
eciabattari
1 Solution
 
MELeBlancCommented:
If I am understanding what you are wanting correctly...

The following code will put all of the resources into a single array called arrResources

Dim arrResources() As String
Dim intNext As Integer

Private Sub OpenControlFile(FNData As String)
'module opens text file and places values into array

  Dim fs As Object
  Dim ts As Object
  Dim f As Object
  Dim strLine As String
 
  Set fs = CreateObject("Scripting.FileSystemObject")
  Set f = fs.GetFile(FNData)
  Set ts = f.OpenAsTextStream()
 
    Do
      strLine = ts.ReadLine
      AddResources(strLine)
     
    Loop While Not ts.AtEndOfStream
    ts.Close

End Sub

Private Sub AddResources(strPassedLine As String)

    Dim MyArray() As String
    Dim idx As Integer
   
    MyArray = Split(strPassedLine, ",")
   
    For idx = 0 To UBound(MyArray)
        intNext = intNext + 1
        ReDim Preserve arrResources(intNext)
        arrResources(intNext) = Trim(MyArray(idx))
    Next idx
     
End Sub


-M
0
 
eciabattariAuthor Commented:
just want I needed, thanks!
0

Featured Post

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!

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