Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create/ Update text file

Status
Not open for further replies.

xitu

Technical User
Oct 1, 2003
55
US
I want to create a text file using VBA. If I select a folder, the VBA code will write all folders, filenames to a text file (text.txt)
The codes below write the text.txt but for some reason, the first line shows OK and the rest are in special characters. Does anyone have any ideas?

Thanks,
XT

'========================================================
Dim fs
Dim a
Const ForReading = 1, ForWriting = 2, ForAppending = 8

Set fs = CreateObject("Scripting.FileSystemObject")
If (fs.FileExists("c:\text.txt")) = False Then
Set a = fs.CreateTextFile("c:\text.txt", ForWriting, True)
a.WriteLine (strName)
Else
Set a = fs.OpenTextFile("c:\text.txt", ForAppending, True)
a.WriteLine (strName)
End If
'a.Close
Set a = Nothing
Set fs = Nothing
'========================================================
 
Why is the a.Close commented out ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
PH,

I tried to comment a.close to test and forgot to remove it. Comment or uncomment a.close does not make any changes (I still get the special characters)

Thanks,
XT
 
Hi,

What's in strName?

If strName is "" then all you'll get is CRLF characters.

:)

Skip,

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Skip,

strName is not ""

strName = pGxObj.FullName (ArcGIS objects)

Thanks,
Jeffrey
 
What is a typical value of

pGxObj.FullName (ArcGIS objects)?

Skip,

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Here's my code

Sub callLoop()

Dim pGxObj As IGxObject
Dim pGxApp As IGxApplication
Set pGxApp = Application
Set pGxObj = pGxApp.SelectedObject
Call LoopFolders(pGxObj)
MsgBox "A log file has been created in c:\01_BrokenLinks.txt", vbOKOnly
End Sub


Sub LoopFolders(pGxObj As IGxObject)

Dim pGxApp As IGxApplication
Dim pGxSel As IGxSelection
Dim pGxObjectCont As IGxObjectContainer
Dim pEnumGxObj As IEnumGxObject

If Not TypeOf pGxObj Is IGxFolder Then
MsgBox "You have selected a file. Please select a Folder to search", vbExclamation
MsgBox ("This file is in " & pGxObj.FullName)
Exit Sub
Else
Set pGxObjectCont = pGxObj
'Check to see if there are children
Set pEnumGxObj = pGxObjectCont.Children
If pEnumGxObj Is Nothing Then
MsgBox "Nothing was found in the " & pGxObj.FullName & " Folder", vbInformation
Exit Sub
Else
Dim intCount As Integer

Set pGxObj = pEnumGxObj.Next
Do While Not pGxObj Is Nothing
Dim strName As String
strName = pGxObj.FullName

Dim fs
Dim a
Const ForReading = 1, ForWriting = 2, ForAppending = 8

Set fs = CreateObject("Scripting.FileSystemObject")
If (fs.FileExists("c:\01_BrokenLinks.txt")) = False Then
Set a = fs.CreateTextFile("c:\01_BrokenLinks.txt", ForWriting, True)
a.WriteLine (strName) '
Else
Set a = fs.OpenTextFile("c:\01_BrokenLinks.txt", ForAppending, True)
a.WriteLine (strName)
End If
a.Close

Set a = Nothing
Set fs = Nothing


If TypeOf pGxObj Is IGxFolder Then
Call LoopFolders(pGxObj)
ElseIf TypeOf pGxObj Is IGxLayer Then

' check for broken links here.



End If

Set pGxObj = pEnumGxObj.Next
intCount = intCount + 1
Loop

End If
End If
End Sub

 
I don't particularly care to see you code.

I asked for a typical value.

Why not try to put a break and examine strName?

Skip,

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top