IN progress...
Note: Add Standard Loop objects (x/y)
'Creating a FileSystemObject
Public FSO As New FileSystemObject
Sub CreateFile()
Dim TxtStr As TextStream
Dim FileName As String
Dim FileContent As String
Dim File As File
Dim sMyString As String
Dim aSplitMeA As Variant, aSplitMeB As Variant
'FileName = "C:\TestDirectory\File.txt" 'File to be created
FileName = Application.GetOpenFilename("Text Files (*.txt),*.txt", , "Select Text Data File")
'Creating a file and writing content to it
'FileContent = InputBox("Enter the File Content")
'If Len(FileContent) > 0 Then
' Set TxtStr = FSO.CreateTextFile(FileName, True, True)
' TxtStr.Write FileContent
' TxtStr.Close
'End If
' Reading from the file that we have just created
If FSO.FileExists(FileName) Then
Set File = FSO.GetFile(FileName)
Set TxtStr = File.OpenAsTextStream(ForReading, TristateUseDefault)
sMyString = TxtStr.readall
'MsgBox Left(sMyString, 25) & Chr(13) & Right(sMyString, , 25)
TxtStr.Close
End If
'Start processing the file string
'Show the starting length of the string
Debug.Print "Full String: " & Len(sMyString)
'Show the # of [(] in the string
Debug.Print "Char [(] Count: " & Len(sMyString) - Len(Replace(sMyString, "(", "", , , vbTextCompare))
'Show the # of [LineFeeds] in the string
Debug.Print "Char [Line Feeds] Count: " & Len(sMyString) - Len(Replace(sMyString, Chr(10), "", , , vbTextCompare))
'Remove the line Feeds:
sMyString = Replace(sMyString, Chr(10), "", , , vbTextCompare)
'Show the new count
Debug.Print "REVISED --- Full String: " & Len(sMyString)
'=================stop here - untested - need to create delimiters
'Change the 1st Attributes value to match the rest
sMyString = Replace(sMyString, "array ( '", ", '", , , vbTextCompare)
'Add a Split for all the Attributes
sMyString = Replace(sMyString, ", '", ", |'", , , vbTextCompare)
'Change all [Space x 4] to [^]
sMyString = Replace(sMyString, "array ( 0", "array(^0", , , vbTextCompare)
'Change all [Space x 3] to [|]
'sMyString = Replace(sMyString, " ", "|", , , vbTextCompare)
aSplitMeA = Split(sMyString, "|")
For x = LBound(aSplitMeA) To UBound(aSplitMeA)
DoEvents
aSplitMeB = Split(aSplitMeA(x), ",", , vbTextCompare)
GoTo gMemoryCleanup
For y = LBound(aSplitMeB) To UBound(aSplitMeB)
Debug.Print Left(aSplitMeB(y), 30)
Next y
Next x
' Finally Deleting the File
'File.Delete (True)
gMemoryCleanup:
Erase aSplitMeA: Erase aSplitMeB
End Sub
'Creating a FileSystemObject
Public FSO As New FileSystemObject
Sub CreateFile()
Dim TxtStr As TextStream
Dim FileName As String
Dim FileContent As String
Dim File As File
Dim sMyString As String
Dim aSplitMeA As Variant, aSplitMeB As Variant
'FileName = "C:\TestDirectory\File.txt" 'File to be created
FileName = Application.GetOpenFilename("Text Files (*.txt),*.txt", , "Select Text Data File")
'Creating a file and writing content to it
'FileContent = InputBox("Enter the File Content")
'If Len(FileContent) > 0 Then
' Set TxtStr = FSO.CreateTextFile(FileName, True, True)
' TxtStr.Write FileContent
' TxtStr.Close
'End If
' Reading from the file that we have just created
If FSO.FileExists(FileName) Then
Set File = FSO.GetFile(FileName)
Set TxtStr = File.OpenAsTextStream(ForReading, TristateUseDefault)
sMyString = TxtStr.readall
'MsgBox Left(sMyString, 25) & Chr(13) & Right(sMyString, , 25)
TxtStr.Close
End If
'Start processing the file string
'Show the starting length of the string
Debug.Print "Full String: " & Len(sMyString)
'Show the # of [(] in the string
Debug.Print "Char [(] Count: " & Len(sMyString) - Len(Replace(sMyString, "(", "", , , vbTextCompare))
'Show the # of [LineFeeds] in the string
Debug.Print "Char [Line Feeds] Count: " & Len(sMyString) - Len(Replace(sMyString, Chr(10), "", , , vbTextCompare))
'Remove the line Feeds:
sMyString = Replace(sMyString, Chr(10), "", , , vbTextCompare)
'Show the new count
Debug.Print "REVISED --- Full String: " & Len(sMyString)
'=================stop here - untested - need to create delimiters
'Change the 1st Attributes value to match the rest
sMyString = Replace(sMyString, "array ( '", ", '", , , vbTextCompare)
'Add a Split for all the Attributes
sMyString = Replace(sMyString, ", '", ", |'", , , vbTextCompare)
'Change all [Space x 4] to [^]
sMyString = Replace(sMyString, "array ( 0", "array(^0", , , vbTextCompare)
'Change all [Space x 3] to [|]
'sMyString = Replace(sMyString, " ", "|", , , vbTextCompare)
aSplitMeA = Split(sMyString, "|")
For x = LBound(aSplitMeA) To UBound(aSplitMeA)
DoEvents
aSplitMeB = Split(aSplitMeA(x), ",", , vbTextCompare)
GoTo gMemoryCleanup
For y = LBound(aSplitMeB) To UBound(aSplitMeB)
Debug.Print Left(aSplitMeB(y), 30)
Next y
Next x
' Finally Deleting the File
'File.Delete (True)
gMemoryCleanup:
Erase aSplitMeA: Erase aSplitMeB
End Sub
Function TestSubArray(sMyText As String, iStartPos As Long)
Dim iNext As Long, iOpen As Long, iClose As Long
iNext = 0
TestSubArray = 0
iOpen = InStr(iStartPos + 1, sMyText, "(", vbTextCompare)
iClose = InStr(iStartPos + 1, sMyText, ")", vbTextCompare)
'Test to make sure the character [(] was found, if it was, return the next occurence
If iOpen > 0 Then TestSubArray = iOpen
'Test to make sure the character [)] was found, if it was, return the next occurence (over-rides the current value is set during iOpen
If iClose > 0 And iClose < iOpen Then TestSubArray = iClose
End Function
Dim iNext As Long, iOpen As Long, iClose As Long
iNext = 0
TestSubArray = 0
iOpen = InStr(iStartPos + 1, sMyText, "(", vbTextCompare)
iClose = InStr(iStartPos + 1, sMyText, ")", vbTextCompare)
'Test to make sure the character [(] was found, if it was, return the next occurence
If iOpen > 0 Then TestSubArray = iOpen
'Test to make sure the character [)] was found, if it was, return the next occurence (over-rides the current value is set during iOpen
If iClose > 0 And iClose < iOpen Then TestSubArray = iClose
End Function