Results 1 to 4 of 4

Thread: Errors msg that are not errors

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 1999
    Location
    Skudeneshavn, Norway
    Posts
    38
    Hi

    Could someon take a look at my code for renaming files
    for the source of a Listbox.
    -------------------------------------------------------
    Private Sub Command1_Click()
    On Error GoTo Correction

    Dim Oldname
    Dim Newname

    For i = 0 To List1.ListCount
    Oldname = Dir1.Path & "\" & File1.List(i)
    Newname = Dir1.Path & "\" & List1.List(i)
    Name Oldname As Newname
    Next i

    File1.Refresh

    Exit Sub
    Correction:
    MsgBox ("File alredy exits, or file in use"), _
    vbCritical, "File Protection!!"

    Exit Sub
    error:
    MsgBox ("The amount of titles do not mach the number of files to be renamed"), _
    vbCritical, "Hello, Wake Up"

    End Sub
    ---------------------------------------------------------

    I get an error message "File alredy exits, or file in use"
    but still the files are renamed.

    Any clues?

    Hope you can help

    Best regards,

    Chris Davidsen

    Christian Davidsen

    If you go to sleep with an itchy
    ass, you wake up with smelly fingers.

  2. #2

    Thread Starter
    Member
    Join Date
    Jan 1999
    Location
    Skudeneshavn, Norway
    Posts
    38

    there is more

    And if I remove the first msgbox I
    get the message

    --------------------------
    Run Time Error '75

    path/file access error
    --------------------------

    and when I click Debug

    the line from my code
    "Name Oldname As Newname"
    is yellowed out.

    but still all files are being renamed.

    Now that's the rest of my problem

    Chris
    Christian Davidsen

    If you go to sleep with an itchy
    ass, you wake up with smelly fingers.

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    Well, I'm not sure what your problem is but there are several problems with your code that you should correct in any case.

    1. Always define variables with a type, so instead of
    Dim Oldname
    Dim Newname

    you should do

    Dim Oldname as String
    Dim Newname as String

    otherwise your variables are created as variants and not only are they larger and slower, but they don't always behave in the same fashion as specifically typed variables.

    2. The way you have your "error" routine written, ANY error you get will result in the same error message. One way to improve it would be add the following routine in your program
    Code:
    Public Sub DisplayError(sRoutine As String)
    '***************************************************************************
    'Purpose: Common error display routine
    'Inputs:  None
    'Outputs: None
    '***************************************************************************
    
        MsgBox "Error #" & str(Err.Number) & " was generated by " & Err.Source & " in routine " & sRoutine & "." & vbCrLf & vbCrLf & Err.Description, _
                     vbExclamation, , Err.HelpFile, Err.HelpContext
    
    End Sub
    and then change your correction: routine to

    correction:

    DisplayError "Command1_Click"

  4. #4

    Thread Starter
    Member
    Join Date
    Jan 1999
    Location
    Skudeneshavn, Norway
    Posts
    38

    Hi again

    If you want I can send you the project
    and you might get the problem.

    Chris
    Christian Davidsen

    If you go to sleep with an itchy
    ass, you wake up with smelly fingers.

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