Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Sequence Files (VB6)

    Not sure if this is possible but here goes:

    My application is designed to import images and promt the user for A JobNo & RegistrationNumber via 2 input boxes.

    An image named "Med-4555.jpg" on import would be named "12345-KY52OLG-Med-4555.jpg"

    12345 is JobNo
    KY52OLG is RegistrationNumber

    One of our external programs will not recgognise long file names so I have to look at another way of saving the image without fear of duplication.
    My thoughts are as follows:

    1/One input box for JobNo
    2/ Rename the image file "Med-4555.jpg"

    Here's where the tricky bit comes in.

    Can the files be saved in sequence, ie 01.jpg 02.jpg 03.jpg etc, if so I could rewrite the code to save the file as 12345-01.jpg 12345-02.jpg.

    Of course the coding would have to look in the folder if these files already existed and take the next sequencing number, ie 12345-03.jpg so as not to conflict with duplicates.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Sequence Files (VB6)

    See if the following function helps:

    Function GetNextName(JobNo) As String
    Dim strPath As String
    Dim strFile As String
    Dim intMax As Integer
    Dim intPos As Integer
    Dim intSeq As Integer

    intMax = 0
    strPath = "C:Images" ' * substitute correct path here! *
    strFile = Dir(strPath & JobNo & "-??.doc")
    Do Until strFile = ""
    intPos = InStr(strFile, ".")
    If intPos > 0 Then
    intSeq = Val(Mid(strFile, intPos - 2, 2))
    If intSeq > intMax Then
    intMax = intSeq
    End If
    End If
    strFile = Dir
    Loop

    GetNextName = JobNo & "-" & Format(intMax + 1, "00") & ".doc"
    End Function

    Use this function to assign the next available file name for a given JobNo. Say that 12345-01.jpg and 12345-03.jpg already exist, then GetNextName(12345) will return 12345-04.jpg (like AutoNumber, the function won't attempt to reuse gaps in the sequence.)

  3. #3
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Sequence Files (VB6)

    Hans
    I encountered a pc problem yesterday which using system restore to the start of the month has fixed my connection.
    Anyway.

    I scoured thru your code example and had to manipulate it to suit my needs.
    Not able to log on to Woody's since your reply was posted, I had to sort the code un aided and think I have done it.
    The modified code works but would be greatful if you would just read thru and see if I have left any underlying mistakes or problems:
    Thanks.

    <pre>Private Sub cmdExport_Click()
    Dim JN As String 'Job Number
    Dim FN As String 'FileName
    Dim N As Integer 'Number
    Dim DP As String 'Default Path
    Dim intMax As Integer 'Maximum File No
    Dim intPos As Integer 'Position ??
    Dim intSeq As Integer 'Sequence
    Dim FF As String 'Final File
    '================================================= ========
    'Check if list contains any selections
    On Error Resume Next
    If lstImages.ListCount = 0 Then
    MsgBox "No Images To Select", , "Information"
    Exit Sub
    End If
    If lstImages.SelCount = 0 Then
    MsgBox "No Images Selected", , "Information"
    Exit Sub
    End If
    '================================================= ========
    ' Declare Input box, Set Max to Zero
    intMax = 0
    JN = InputBox("Job Number", "")
    '================================================= ========
    'Ensure Job No is entered
    If JN = "" Then
    MsgBox "You Have Missed a Job No Or A Registration No" & vbCrLf & _
    "Please Try Again", , "Information": Exit Sub
    End If
    '================================================= =========
    'Do the stuff
    For N = 0 To lstImages.ListCount - 1
    If lstImages.Selected(N) Then
    DP = "L:MMPDFImage"
    FN = Dir(DP & JN & "-??.jpg")
    Do Until FN = ""

    intPos = InStr(FN, ".")
    If intPos > 0 Then
    intSeq = Val(Mid(FN, intPos - 2, 2))
    If intSeq > intMax Then
    intMax = intSeq
    End If
    End If
    FN = Dir
    Loop
    FF = JN & "-" & Format(intMax + 1, "00") & ".jpg"
    FileCopy lstImages.List(N), DP & FF
    End If
    Next N
    '================================================= ========
    'Tell user files have been exported
    MsgBox "Images Exported", , "Information"
    ClearList
    Unload Me
    End Sub</pre>


  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Sequence Files (VB6)

    Dave,

    I'm glad you got it to work by yourself. The code looks good, but it could be a bit more efficient. You don't really need to determine the maximum sequence number each time in the loop. Instead, you can determine it before starting the loop, then increase it for each file copied.

    ' Determine maximum sequence number used up to now
    intMax = 0
    DP = "L:MMPDFImage"
    FN = Dir(DP & JN & "-??.jpg")
    Do Until FN = ""
    intPos = InStr(FN, ".")
    If intPos > 0 Then
    intSeq = Val(Mid(FN, intPos - 2, 2))
    If intSeq > intMax Then
    intMax = intSeq
    End If
    End If
    FN = Dir
    Loop
    ' Now loop through the items of the list box
    For N = 0 To lstImages.ListCount - 1
    If lstImages.Selected(N) Then
    ' Increase the sequence number for the next file
    intMax = intMax + 1
    FF = JN & "-" & Format(intMax, "00") & ".jpg"
    FileCopy lstImages.List(N), DP & FF
    End If
    Next N

  5. #5
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Sequence Files (VB6)

    Hans
    Brilliant & much quicker too.

    I was hoping to add a couple of lines for the user to "Kill" the files from the source once exported.

    Would that be

    <pre>Private Function ClearCard()
    Kill lstImages.List(N)
    </pre>


    But I see this isn't right because the list only holds the filename.
    I could Dim a source ie

    <pre>Dim strSource as String
    strSource = "E:" </pre>

    But it could cause problems if the source wasn't E: ?

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Sequence Files (VB6)

    I suppose that you set the location of the source files (used to populate the list box) somewhere in your code; you should be able to use that when deleting the files.

    You can use the Name instruction to move a file instead of copying it: replace

    FileCopy lstImages.List(N), DP & FF

    by

    Name lstImages.List(N) As DP & FF

    Using the Name instruction (not to be confused with the Name property of many objects) with a different path for the target renames the source *and* moves it to the specified folder.

  7. #7
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Sequence Files (VB6)

    Hans

    "Move" ??

    Yes I could do this but if the user wanted the images still on the card for some other reason, then they would be amiss when they weren't there.

    I am using the Common Dialog to populate the list elsewere in the code, so I think It would be better for me to start there, writing another function "and" giving the user the option to kill or not.

    Thanks for the help, I'll see what I can come up with.

  8. #8
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Sequence Files (VB6)

    Hans
    Here, I am very close:
    If I put the bold text code immediately after the filecopy command, the user is prompted for each file to delete.

    The code where it is now, prompts the user only once, but doesn't delete anything ??
    Can you see where it should go so only to prompt once ?


    <pre>Private Sub cmdExport_Click()
    Dim JN As String 'Job Number
    Dim FN As String 'FileName
    Dim N As Integer 'Number
    Dim DP As String 'Default Path
    Dim intMax As Integer 'Maximum File No
    Dim intPos As Integer 'Position ??
    Dim intSeq As Integer 'Sequence
    Dim FF As String 'Final File
    Dim fso As FileSystemObject
    '================================================= ========
    'Check if list contains any selections
    On Error Resume Next
    If lstImages.ListCount = 0 Then
    MsgBox "No Images To Select", , "Information"
    Exit Sub
    End If
    If lstImages.SelCount = 0 Then
    MsgBox "No Images Selected", , "Information"
    Exit Sub
    End If
    '================================================= ========
    ' Declare Input box, Set Max to Zero
    'intMax = 0
    JN = InputBox("Job Number", "")
    '================================================= ========
    'Ensure Job No is entered
    If JN = "" Then
    MsgBox "You Have Missed a Job No Or A Registration No" & vbCrLf & _
    "Please Try Again", , "Information": Exit Sub
    End If
    '================================================= =========
    'Do the stuff
    ' Determine maximum sequence number used up to now
    intMax = 0
    DP = "L:MMPDFImage"
    FN = Dir(DP & JN & "-??.jpg")
    Do Until FN = ""
    intPos = InStr(FN, ".")
    If intPos > 0 Then
    intSeq = Val(Mid(FN, intPos - 2, 2))
    If intSeq > intMax Then
    intMax = intSeq
    End If
    End If
    FN = Dir
    Loop
    ' Now loop through the items of the list box
    For N = 0 To lstImages.ListCount - 1
    If lstImages.Selected(N) Then
    ' Increase the sequence number for the next file
    intMax = intMax + 1
    FF = JN & "-" & Format(intMax, "00") & ".jpg"
    FileCopy lstImages.List(N), DP & FF

    End If
    Next N

    '================================================= ========
    'Tell user files have been exported
    MsgBox "Images Exported", , "Information"
    If MsgBox("The Image Will Be Removed From Source." & _
    " Are You Sure?", vbYesNo + vbQuestion) = vbYes Then
    Set fso = New FileSystemObject
    fso.DeleteFile lstImages.Selected(N), True
    lstImages.Refresh
    End If

    ClearList
    Unload Me
    End Sub</pre>


  9. #9
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Sequence Files (VB6)

    Try this:

    <pre>Private Sub cmdExport_Click()
    Dim JN As String 'Job Number
    Dim FN As String 'FileName
    Dim N As Integer 'Number
    Dim DP As String 'Default Path
    Dim intMax As Integer 'Maximum File No
    Dim intPos As Integer 'Position ??
    Dim intSeq As Integer 'Sequence
    Dim FF As String 'Final File
    Dim fso As FileSystemObject
    '================================================= ========
    'Check if list contains any selections
    On Error Resume Next
    If lstImages.ListCount = 0 Then
    MsgBox "No Images To Select", , "Information"
    Exit Sub
    End If
    If lstImages.SelCount = 0 Then
    MsgBox "No Images Selected", , "Information"
    Exit Sub
    End If
    '================================================= ========
    ' Declare Input box, Set Max to Zero
    'intMax = 0
    JN = InputBox("Job Number", "")
    '================================================= ========
    'Ensure Job No is entered
    If JN = "" Then
    MsgBox "You Have Missed a Job No Or A Registration No" & vbCrLf & _
    "Please Try Again", , "Information": Exit Sub
    End If
    '================================================= =========
    'Do the stuff
    ' Determine maximum sequence number used up to now
    intMax = 0
    DP = "L:MMPDFImage"
    FN = Dir(DP & JN & "-??.jpg")
    Do Until FN = ""
    intPos = InStr(FN, ".")
    If intPos > 0 Then
    intSeq = Val(Mid(FN, intPos - 2, 2))
    If intSeq > intMax Then
    intMax = intSeq
    End If
    End If
    FN = Dir
    Loop
    ' Now loop through the items of the list box
    For N = 0 To lstImages.ListCount - 1
    If lstImages.Selected(N) Then
    ' Increase the sequence number for the next file
    intMax = intMax + 1
    FF = JN & "-" & Format(intMax, "00") & ".jpg"
    FileCopy lstImages.List(N), DP & FF

    End If
    Next N

    '================================================= ========
    'Tell user files have been exported
    MsgBox "Images Exported", , "Information"
    If MsgBox("The Image Will Be Removed From Source." & _
    " Are You Sure?", vbYesNo + vbQuestion) = vbYes Then
    Set fso = New FileSystemObject
    For N = 0 To lstImages.ListCount - 1
    fso.DeleteFile lstImages.Selected(N), True
    lstImages.Refresh
    Next N
    End If
    ClearList
    Unload Me
    End Sub
    </pre>

    Legare Coleman

  10. #10
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Sequence Files (VB6)

    Thanks Legare for your help.

    Unfortunately, the source files still exist and have not been deleted ?
    I've remmed out the Clearlist & Unload functions, it doesn't make any difference.

  11. #11
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Sequence Files (VB6)

    Remove the line "On Error Resume Next" or make it into a comment. Having that line in your code means that all errors are ignored silently, so you'll never find out why the attempt to delete files fails. When you run the code without the "On Error Resume Next", you'll probably get an error message, and a chance to see where it has occurred.

  12. #12
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Sequence Files (VB6)

    Error 53 File not found.

    If I debug.print, the file shows in the Immediate window ?

    I'll step thru and see what happens.
    I have a feeling, it may be the path "L:HomeS962RUX" which is causing the error.

  13. #13
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Sequence Files (VB6)

    <P ID="edit" class=small>(Edited by D Willett on 29-Jan-04 11:04. See under break line.)</P>Got it:

    Change fso.DeleteFile lstImages.Selected(N), True

    to

    fso.DeleteFile lstImages.List(N)
    ==============================================
    No I haven't, I spoke too soon.:

    With this line: fso.DeleteFile lstImages.List(N)
    Every file is deleted from the list whether selected or not.

    If I edit the line to read : fso.DeleteFile lstImages.Selected(N)
    I get the 53 error ?

  14. #14
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Sequence Files (VB6)

    Try

    If lstImages.Selected(N) Then
    fso.DeleteFile lstImages.List(N)
    End If

    The Selected property is a boolean (True/False) value, it is not a file name. You use it to determine whether a list item is selected by the user.

  15. #15
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Sequence Files (VB6)

    Hans
    Thanks again,, tested and ok.
    I did find a slightly different way which seemed to work also, but have changed to you version:

    Dim DF as String ' File to Delete

    For N = 0 To LstImages.ListCount - 1
    If LstImages.Selected(N) Then
    DF = LstImages.List(N)
    fso.DeleteFile LstImages.List(N)
    End If
    Next N

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •