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

    Double Loop (VB6)

    I'm trying to set a double loop.

    The first checks L:MMPDFImage for the next available filename.
    The second checks L:MMPDFArchive & JN & "" also, so as not to overwrite a filename.

    If an image is created, 12345-01.jpg, it is saved in L:MMPDFImage, then the user archives this image, it is saved in L:MMPDFImage12345.
    This means the Image folder doesn't have 12345-01.jpg in it anymore.
    If another image is created with the same JN (Inputbox) then it will take the name 12345-01.jpg again.
    When this image is archived, it overwrites the same filename in the Archive folder.
    I thought of doubling the loop as below, to check the Max -??.jpg of the same filename in each folder, then intMax would take the highest one plus 1.

    Loop two goes into a continuous loop ?

    <pre> Dim JN As String 'Job Number
    Dim FN As String 'FileName
    Dim AN As String 'Archive Name
    Dim N As Integer 'Number
    Dim DP As String 'Default Image Path
    Dim AP As String 'Archive 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</pre>




    <pre> intMax = 0

    DP = "L:MMPDFImage"
    AP = "L:MMPDFArchive" & JN & ""
    FN = Dir(DP & JN & "-??.jpg")
    AN = Dir(AP & 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

    Do Until AN = ""
    intPos = InStr(AN, ".")
    If intPos > 0 Then
    intSeq = Val(Mid(AN, intPos - 2, 2))
    If intSeq > intMax Then
    intMax = intSeq
    End If
    End If
    AN = 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</pre>


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

    Re: Double Loop (VB6)

    JN is declared in the first line, but it isn't assigned a value in the code you posted. Did you omit that part?

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

    Re: Double Loop (VB6)

    I haven't tested your code since I don't have a directory set up, but I do see two things in your code. First, as HANS has already pointed out, JN is never assigned a value. Second, you can not have two searches using the Dir() function going at the same time. Therefore, you need to move the statement "AN = Dir(AP & JN & "-??.jpg")" down in the code to after the first loop like this:

    <pre>Dim JN As String 'Job Number
    Dim FN As String 'FileName
    Dim AN As String 'Archive Name
    Dim N As Integer 'Number
    Dim DP As String 'Default Image Path
    Dim AP As String 'Archive 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



    intMax = 0

    DP = "L:MMPDFImage"
    AP = "L:MMPDFArchive" & JN & ""
    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

    AN = Dir(AP & JN & "-??.jpg")
    Do Until AN = ""
    intPos = InStr(AN, ".")
    If intPos > 0 Then
    intSeq = Val(Mid(AN, intPos - 2, 2))
    If intSeq > intMax Then
    intMax = intSeq
    End If
    End If
    AN = 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
    </pre>

    Legare Coleman

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

    Re: Double Loop (VB6)

    Hans, Legare.

    Sorry, I had omitted the assignment of JN to keep the post shorter.
    It is assigned via an inputbox in the original code as below.
    I'll try you method later Legare.

    Thanks to you both for the help.

    <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", vbInformation, "Information"
    Exit Sub
    End If
    If lstImages.SelCount = 0 Then
    MsgBox "No Images Selected", vbInformation, "Information"
    Exit Sub
    End If

    <font color=red>JN = InputBox("Job Number", "")</font color=red>
    'Ensure Job No is entered

    If JN = "" Then
    MsgBox "You Have Missed a Job No Or A Registration No" & vbCrLf & _
    "Please Try Again", vbInformation, "Information": Exit Sub
    End If

    If Len(JN) > 5 Then
    MsgBox "Too Many Characters" & vbCrLf & _
    "You Can Only Use 5 Characters" & vbCrLf & _
    "Please Enter A Valid 5 Character Number", vbInformation, "Information": Exit Sub
    End If

    If Len(JN) < 5 Then
    MsgBox "Not Enough Characters" & vbCrLf & _
    "You Need To Use 5 Characters" & vbCrLf & _
    "Please Enter A Valid 5 Character Number", vbInformation, "Information": Exit Sub
    End If

    If IsNumeric(JN) Then 'Check If Estimate Number or Registration
    '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

    If intMax = 100 Then MsgBox "You Have Exceeded The Amount Of Images" & vbCrLf & _
    "That Can Be Saved For This File", vbCritical, "Error": Exit Sub

    FF = JN & "-" & Format(intMax, "00") & ".jpg"
    FileCopy lstImages.List(N), DP & FF

    'Update the log file
    WriteLog GetComputerName & " " & GetNetUser & " File " & lstImages.List(N) & " Was Copied To " & DP & FF

    End If
    Next N
    Else
    WriteLog GetComputerName & " " & GetNetUser & " Invalid Job Number Using Import"
    MsgBox JN & " " & "Is Not A Valid Job Number" & vbCrLf & _
    "You Must Create A Valid Estimate Number", vbCritical, "Job No Error": Exit Sub

    End If

    'Tell user files have been exported
    MsgBox "Images Exported", , "Information"
    If MsgBox("Do You Want To Remove These Images From The Card ?." & _
    " These Images Will Not Be Retrievable !!?", vbYesNo + vbQuestion, " Clear Card") = vbYes Then
    Set fso = New FileSystemObject
    For N = 0 To lstImages.ListCount - 1
    If lstImages.Selected(N) Then
    fso.DeleteFile lstImages.List(N)
    lstImages.Refresh
    End If
    Next N
    End If

    Set fso = Nothing
    ClearList
    Unload Me
    End Sub
    </pre>


Posting Permissions

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