PC Review


Reply
Thread Tools Rate Thread

adding a string of data to an array

 
 
R Tanner
Guest
Posts: n/a
 
      29th Sep 2008
Hi,

I am trying to cycle through a series of files in a folder and if the
filename does not meet my criteria, then I want to add the filename to
my array. This is my loop. How do I add the filename to my array?

Sub ParseTextFiles()

Dim MyFile As String
Dim FSO As FileSystemObject
Dim MyFolder As Object
Dim ObjFile As Object
Dim colFiles As Object
Dim MyParsedMessage() As String
Dim MyParsedDate As String



MyFile = "Z:\Drop Box\robin.tanner\FortexRejects"

Set FSO = CreateObject("Scripting.FileSystemObject")
Set MyFolder = FSO.GetFolder(MyFile)
Set colFiles = MyFolder.Files

For Each ObjFile In colFiles
MyParsedDate =
Application.WorksheetFunction.Substitute(Left(ObjFile.Name, 10), ".",
"/")
If Not IsDate(MyParsedDate) Then
MyParsedMessage(i) = ObjFile.Name
End If
Next

MsgBox MyParsedMessage(1:i)


End Sub
 
Reply With Quote
 
 
 
 
Jim Thomlinson
Guest
Posts: n/a
 
      29th Sep 2008
You need a dynamic array. This is untested but it sould be close. I
personally would have used a collection of file objects but to each his own...

Sub ParseTextFiles()

Dim MyFile As String
Dim FSO As FileSystemObject
Dim MyFolder As Object
Dim ObjFile As Object
Dim colFiles As Object
Dim MyParsedMessage() As String
Dim MyParsedDate As String
Dim lng as long

MyFile = "Z:\Drop Box\robin.tanner\FortexRejects"

Set FSO = CreateObject("Scripting.FileSystemObject")
Set MyFolder = FSO.GetFolder(MyFile)
Set colFiles = MyFolder.Files

For Each ObjFile In colFiles
MyParsedDate =
Application.WorksheetFunction.Substitute(Left(ObjFile.Name, 10), ".",
"/")
If Not IsDate(MyParsedDate) Then
Redim Preserve MyParsedMessage(lng)
MyParsedMessage(lng) = ObjFile.Name
lng = lng + 1
End If
Next

for lng = lbound(MyParsedMessage) to ubound(MyParsedMessage)
MsgBox MyParsedMessage(1:i)
next lng
End Sub

--
HTH...

Jim Thomlinson


"R Tanner" wrote:

> Hi,
>
> I am trying to cycle through a series of files in a folder and if the
> filename does not meet my criteria, then I want to add the filename to
> my array. This is my loop. How do I add the filename to my array?
>
> Sub ParseTextFiles()
>
> Dim MyFile As String
> Dim FSO As FileSystemObject
> Dim MyFolder As Object
> Dim ObjFile As Object
> Dim colFiles As Object
> Dim MyParsedMessage() As String
> Dim MyParsedDate As String
>
>
>
> MyFile = "Z:\Drop Box\robin.tanner\FortexRejects"
>
> Set FSO = CreateObject("Scripting.FileSystemObject")
> Set MyFolder = FSO.GetFolder(MyFile)
> Set colFiles = MyFolder.Files
>
> For Each ObjFile In colFiles
> MyParsedDate =
> Application.WorksheetFunction.Substitute(Left(ObjFile.Name, 10), ".",
> "/")
> If Not IsDate(MyParsedDate) Then
> MyParsedMessage(i) = ObjFile.Name
> End If
> Next
>
> MsgBox MyParsedMessage(1:i)
>
>
> End Sub
>

 
Reply With Quote
 
R Tanner
Guest
Posts: n/a
 
      29th Sep 2008
On Sep 29, 3:01*pm, Jim Thomlinson <James_Thomlin...@owfg-Re-Move-
This-.com> wrote:
> You need a dynamic array. This is untested but it sould be close. I
> personally would have used a collection of file objects but to each his own...
>
> Sub ParseTextFiles()
>
> Dim MyFile As String
> Dim FSO As FileSystemObject
> Dim MyFolder As Object
> Dim ObjFile As Object
> Dim colFiles As Object
> Dim MyParsedMessage() As String
> Dim MyParsedDate As String
> Dim lng as long
>
> MyFile = "Z:\Drop Box\robin.tanner\FortexRejects"
>
> Set FSO = CreateObject("Scripting.FileSystemObject")
> Set MyFolder = FSO.GetFolder(MyFile)
> Set colFiles = MyFolder.Files
>
> For Each ObjFile In colFiles
> * * MyParsedDate =
> Application.WorksheetFunction.Substitute(Left(ObjFile.Name, 10), ".",
> "/")
> * * If Not IsDate(MyParsedDate) Then
> * * * * Redim Preserve MyParsedMessage(lng)
> * * * * MyParsedMessage(lng) = ObjFile.Name
> * * * * lng = lng + 1
> * * End If
> Next
>
> for lng = lbound(MyParsedMessage) to ubound(MyParsedMessage)
> * MsgBox MyParsedMessage(1:i)
> next lng
> End Sub
>
> --
> HTH...
>
> Jim Thomlinson
>
>
>
> "R Tanner" wrote:
> > Hi,

>
> > I am trying to cycle through a series of files in a folder and if the
> > filename does not meet my criteria, then I want to add the filename to
> > my array. *This is my loop. *How do I add the filename to my array?

>
> > Sub ParseTextFiles()

>
> > Dim MyFile As String
> > Dim FSO As FileSystemObject
> > Dim MyFolder As Object
> > Dim ObjFile As Object
> > Dim colFiles As Object
> > Dim MyParsedMessage() As String
> > Dim MyParsedDate As String

>
> > MyFile = "Z:\Drop Box\robin.tanner\FortexRejects"

>
> > Set FSO = CreateObject("Scripting.FileSystemObject")
> > Set MyFolder = FSO.GetFolder(MyFile)
> > Set colFiles = MyFolder.Files

>
> > For Each ObjFile In colFiles
> > * * MyParsedDate =
> > Application.WorksheetFunction.Substitute(Left(ObjFile.Name, 10), ".",
> > "/")
> > * * If Not IsDate(MyParsedDate) Then
> > * * * * MyParsedMessage(i) = ObjFile.Name
> > * * End If
> > Next

>
> > MsgBox MyParsedMessage(1:i)

>
> > End Sub- Hide quoted text -

>
> - Show quoted text -


oh I am more than open to suggestions Jim. I am just using what I
know. Please, tell me why a collection of file objects would be
better in your opinion...

Thank you for the fix by the way.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
breaking up a String into an array of chars and adding to datatable Paulers Microsoft VB .NET 6 15th Jan 2007 02:31 AM
Adding a NULL to an array then adding array to a data table =?Utf-8?B?RmlkZGVsbTM3NDI=?= Microsoft ADO .NET 4 18th May 2006 07:18 PM
converting array of byte data type to string. shivaprasad@techie.com Microsoft C# .NET 5 8th Oct 2005 12:39 AM
How to Convert DataRow with Byte Array data to String? Paul W Microsoft ASP .NET 1 6th Aug 2004 07:55 PM
Cannot create an object of type 'System.String[]' from its string representation 'String[] Array' for the 'Options' property. Hessam Microsoft C# .NET 0 8th Aug 2003 09:45 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:51 AM.