R
rebelscum0000
Dear All,
I have a few questions can someone please help me?
Thanks in Advance
Regards,
Antonio Macias
A) Do I must Dim all the variables I have in my code without
exceptions?
B) What FreeFile() does?
C) How to delete a file trough VBA, without using FSO?
*I read in a post:
"I've only ever found one case where FSO
could do something that I couldn't do using VBA and/or API calls (the
ability to get the LastUpdated date for a folder)"
D) Can someone explain to me what each line of these IF Then condition
does
If Left(VSFLRT, Len(VDAS)) = VDAS Then
*If This = That is True Then what?
*Do nothing?
*Must do something?
*Is this a correct way of testing for a certain string?
'Exclusion code
If Left(VSFLRT, Len(VDAS)) = VDAS Then
ElseIf Left(VSFLRT, Len(VMSO)) = VMSO Then
ElseIf Left(VSFLRT, Len(VPRF)) = VPRF Then
ElseIf Left(VSFLRT, Len(VWIN)) = VWIN Then
Else
'Write it out
Print #VOUF, VSFLRT
End If
End If
This is my entire code
Sub Reading_TxtFile_R()
Dim VOTP As String 'OriginTxtPath
Dim VDTP As String 'DestinationTxtPath
Dim VRTP As String 'RenameTxtPath
Dim VTXN As String 'TxtName
Dim VINF As Integer 'InFile
Dim VOUF As Integer 'outFile
Dim VRET As String 'ReadText
Dim VSFL As String 'SearchFolderLine
Dim VDAS As String 'Documents and Settings
Dim VMSO As String 'MSOCache
Dim VPRF As String 'Program Files
Dim VWIN As String 'WINDOWS
Dim VMYC As Integer 'MyCounter
Dim VSFLR As String 'SearchFolderLineReplace
Dim VSFLRT As String 'SearchFolderLineReplaceTrim
VTXN = "LastSearch"
VSFL = "Search Folder"
VDAS = "C:\Documents and Settings"
VMSO = "C:\MSOCache"
VPRF = "C:\Program Files"
VWIN = "C:\WINDOWS"
VMYC = 0
VOTP = "C:\Program Files\Fineware\hound4\Searches\" & VTXN & ".txt"
VDTP = CurrentDb().Name
VDTP = Left$(VDTP, _
Len(VDTP) - Len(Dir$(VDTP))) & _
(VTXN & ".txt")
'Obtain legal handles
VINF = FreeFile()
Open VOTP For Input As #VINF
VOUF = FreeFile()
Open VDTP For Output As #VOUF
Do Until EOF(VINF) 'Loop until end of file.
Line Input #VINF, VRET 'Read line into variable.
'Then you can read it line by line:
'Do something with the line.
If Left(VRET, Len(VSFL)) = VSFL Then
'Counter
VMYC = VMYC + 1
'Replace
VSFLR = Replace(VRET, VSFL & _
" " & VMYC & ":", "", , , vbTextCompare)
VSFLRT = Trim(VSFLR)
'Exclusion code
If Left(VSFLRT, Len(VDAS)) = VDAS Then
ElseIf Left(VSFLRT, Len(VMSO)) = VMSO Then
ElseIf Left(VSFLRT, Len(VPRF)) = VPRF Then
ElseIf Left(VSFLRT, Len(VWIN)) = VWIN Then
Else
'Write it out
Print #VOUF, VSFLRT
End If
End If
Loop
'Tidy up
Close #VINF
Close #VOUF
I have a few questions can someone please help me?
Thanks in Advance
Regards,
Antonio Macias
A) Do I must Dim all the variables I have in my code without
exceptions?
B) What FreeFile() does?
C) How to delete a file trough VBA, without using FSO?
*I read in a post:
"I've only ever found one case where FSO
could do something that I couldn't do using VBA and/or API calls (the
ability to get the LastUpdated date for a folder)"
D) Can someone explain to me what each line of these IF Then condition
does
If Left(VSFLRT, Len(VDAS)) = VDAS Then
*If This = That is True Then what?
*Do nothing?
*Must do something?
*Is this a correct way of testing for a certain string?
'Exclusion code
If Left(VSFLRT, Len(VDAS)) = VDAS Then
ElseIf Left(VSFLRT, Len(VMSO)) = VMSO Then
ElseIf Left(VSFLRT, Len(VPRF)) = VPRF Then
ElseIf Left(VSFLRT, Len(VWIN)) = VWIN Then
Else
'Write it out
Print #VOUF, VSFLRT
End If
End If
This is my entire code
Sub Reading_TxtFile_R()
Dim VOTP As String 'OriginTxtPath
Dim VDTP As String 'DestinationTxtPath
Dim VRTP As String 'RenameTxtPath
Dim VTXN As String 'TxtName
Dim VINF As Integer 'InFile
Dim VOUF As Integer 'outFile
Dim VRET As String 'ReadText
Dim VSFL As String 'SearchFolderLine
Dim VDAS As String 'Documents and Settings
Dim VMSO As String 'MSOCache
Dim VPRF As String 'Program Files
Dim VWIN As String 'WINDOWS
Dim VMYC As Integer 'MyCounter
Dim VSFLR As String 'SearchFolderLineReplace
Dim VSFLRT As String 'SearchFolderLineReplaceTrim
VTXN = "LastSearch"
VSFL = "Search Folder"
VDAS = "C:\Documents and Settings"
VMSO = "C:\MSOCache"
VPRF = "C:\Program Files"
VWIN = "C:\WINDOWS"
VMYC = 0
VOTP = "C:\Program Files\Fineware\hound4\Searches\" & VTXN & ".txt"
VDTP = CurrentDb().Name
VDTP = Left$(VDTP, _
Len(VDTP) - Len(Dir$(VDTP))) & _
(VTXN & ".txt")
'Obtain legal handles
VINF = FreeFile()
Open VOTP For Input As #VINF
VOUF = FreeFile()
Open VDTP For Output As #VOUF
Do Until EOF(VINF) 'Loop until end of file.
Line Input #VINF, VRET 'Read line into variable.
'Then you can read it line by line:
'Do something with the line.
If Left(VRET, Len(VSFL)) = VSFL Then
'Counter
VMYC = VMYC + 1
'Replace
VSFLR = Replace(VRET, VSFL & _
" " & VMYC & ":", "", , , vbTextCompare)
VSFLRT = Trim(VSFLR)
'Exclusion code
If Left(VSFLRT, Len(VDAS)) = VDAS Then
ElseIf Left(VSFLRT, Len(VMSO)) = VMSO Then
ElseIf Left(VSFLRT, Len(VPRF)) = VPRF Then
ElseIf Left(VSFLRT, Len(VWIN)) = VWIN Then
Else
'Write it out
Print #VOUF, VSFLRT
End If
End If
Loop
'Tidy up
Close #VINF
Close #VOUF