Results 1 to 3 of 3

Thread: vb code(dir)

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Posts
    99

    Post 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

  2. #2
    PowerPoster
    Join Date
    Aug 2001
    Location
    new jersey
    Posts
    2,904
    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.

  3. #3
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357
    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:
    1. inti = Dir("C:\Documents and Settings\Cesar\Desktop\in\*.*")
    2.     asum = Mid$(inti, 15, 8)
    3.    
    4.     CES = Dir("C:\Documents and settings\Cesar\Desktop\rejected\*.*")
    5.    
    6.     Do While CES <> ""
    7.         ASUM1 = Mid$(CES, 15, 8)
    8.        
    9.         If asum = ASUM1 Then
    10.             T = T + 1
    11.             FileCopy "C:\Documents and Settings\Cesar\Desktop\rejected\" & CES, _
    12.                 "C:\Documents and Settings\Cesar\Desktop\out\" & CES
    13.         End If
    14.        
    15.         CES = Dir
    16.     Loop
    17.    
    18.     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
  •  



Click Here to Expand Forum to Full Width