|
-
Apr 8th, 2003, 11:40 AM
#1
Thread Starter
Lively Member
vb code(dir)
I have two files that i have to use DIR , THE PROBLEM is when
i go to read the other record in the file "in" the job freeze
HOW I GET THE SECOND RECORD IN THE FILE "IN"
help me please
inti = Dir("C:\Documents and Settings\Cesar\Desktop\in\*.*")
'If sw = 1 Then Let inti = wstempin
Let asum = Mid$(inti, 15, 8)
CES = Dir("C:\Documents and settings\Cesar\Desktop\rejected\*.*")
rtn1:
Let ASUM1 = Mid$(CES, 15, 8)
If CES = "" Then
GoTo PREFIN
ElseIf asum = ASUM1 Then
Let T = T + 1
FileCopy "C:\Documents and Settings\Cesar\Desktop\rejected\" & CES, "C:\Documents and Settings\Cesar\Desktop\out\" & CES
CES = Dir
GoTo rtn1
Else
CES = Dir
GoTo rtn1
End If
PREFIN:
Print T
-
Apr 8th, 2003, 11:47 AM
#2
PowerPoster
this is the THIRD time in a couple of days that you have posted this exact same question either here or on another forum. Please stop it. Particularly since you have already been answered in one of the previous posts.
-
Apr 8th, 2003, 11:49 AM
#3
Frenzied Member
AAAAGGGGHHHH! Don't use Gotos! That leads to horrible spaghetti code!!!! There are all kinds of structures you can use to get away from Goto statements. Here is one way to re-write your code without using Goto:
VB Code:
inti = Dir("C:\Documents and Settings\Cesar\Desktop\in\*.*")
asum = Mid$(inti, 15, 8)
CES = Dir("C:\Documents and settings\Cesar\Desktop\rejected\*.*")
Do While CES <> ""
ASUM1 = Mid$(CES, 15, 8)
If asum = ASUM1 Then
T = T + 1
FileCopy "C:\Documents and Settings\Cesar\Desktop\rejected\" & CES, _
"C:\Documents and Settings\Cesar\Desktop\out\" & CES
End If
CES = Dir
Loop
Print T
Also, subsequent calls to Dir without a path always use the last path passed to Dir, so you can't expect to call Dir again on your "in" folder after you call Dir using your "rejected" folder.
Think about using the FileSystemObject for looping through multiple directories at the same time and comparing files, or saving filenames into an array for the first directory, then looping through the second directory and compare file names.
Last edited by seaweed; Apr 8th, 2003 at 11:58 AM.
~seaweed
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|