Hello,

I have a function that checks to see if an image file exists on the harddrive:

VB Code:
  1. Private Function DoesExist(ByVal strName As String) As Boolean
  2.     On Error GoTo Errorhandler ' goto error handler if file doesn't exist
  3.     Dim sFile As Long
  4.     sFile = FreeFile() 'get a free file #
  5.     Open strName For Input As sFile
  6.     Close sFile
  7.     DoesExist = True 'return if file was opened
  8.     Exit Function
  9. Errorhandler:
  10.     DoesExist = False 'return false if error occured - meaning file was NOT found
  11. End Function

Here is the function I'm trying to write so that if the file does exist, then create the same one but add (1), (2), etc. to the end of the file right before the .bmp extension.

The label boxes (which is already populated) is used in naming this image file.

VB Code:
  1. Private Function SaveSixPack2()
  2.    
  3.     If DoesExist("C:\SixPackImages\" & Generator.lblSixCR.Caption & "-" & "SixPack" & ".bmp") = False Then
  4.         SavePicture Picture13.Picture, ("C:\SixPackImages\" & Generator.lblSixCR.Caption & "-" & "SixPack" & ".bmp")
  5.     End If
  6.     If DoesExist("C:\SixPackImages\" & Generator.lblSixCR.Caption & "-" & "SixPack" & ".bmp") = False Then
  7.         Exit Function
  8.     Else
  9.         SavePicture Picture13.Picture, ("C:\SixPackImages\" & Generator.lblSixCR.Caption & "-" & "SixPack" & "(" & "1" & ")" & ".bmp")
  10.     End If
  11.     If DoesExist("C:\SixPackImages\" & Generator.lblSixCR.Caption & "-" & "SixPack" & "(" & "1" & ")" & ".bmp" & "C:\SixPackImages\" & Generator.lblSixCR.Caption & "-" & "SixPack" & ".bmp") = False Then
  12.         Exit Function
  13.     Else
  14.         SavePicture Picture13.Picture, ("C:\SixPackImages\" & Generator.lblSixCR.Caption & "-" & "SixPack" & "(" & "2" & ")" & ".bmp")
  15.     End If
  16. End Function

So my problem is: the first two "If DoesExists" work but the last one doesn't for some reason..... any suggestions?


Thanks!'

Chris