Results 1 to 2 of 2

Thread: Saving new image files

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2003
    Posts
    89

    Saving new image files

    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

  2. #2
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246
    Try replacing the last one with this:

    VB Code:
    1. If Not DoesExist("C:\SixPackImages\" & Generator.lblSixCR.Caption & "-" & "SixPack" & "(" & "1" & ")" & ".bmp" & "C:\SixPackImages\" & Generator.lblSixCR.Caption & "-" & "SixPack" & ".bmp") = False Then
    2.         SavePicture Picture13.Picture, ("C:\SixPackImages\" & Generator.lblSixCR.Caption & "-" & "SixPack" & "(" & "2" & ")" & ".bmp")
    3.     End If


    Phreak

    Visual Studio 6, Visual Studio.NET 2005, MASM

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