Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2011
    Posts
    14

    Unanswered: Issues with vb and filenames

    Hello,
    I seem to have one more problem with my image viewer. When we save our pictures into their respective folders, they have a naming scheme like this, if the account number is 11111, then the named picture on the server will be 0011111_01_01.jpg. The _01_01 stands for dwelling number and picture number respectively. In most cases, we take multiple images, so picture numbers are sequentially numbered _01.jpg, _02.jpg, _03.jpg etc. My image viewer works perfectly currently, as long as the dnum, or in my case dwelling number equals 01. But there are instances where dnum will equal 02, for a second dwelling. The resulting picture number is 0011111_02_01.jpg. These with a different dnum are not being pulled by the viewer. Given the code I currently have, how might I be able to circumvent this? Any ideas are very appreciated. Code below. Oh, and just to be clear, there is always a dwelling one and only sometimes a dwelling two. So in the folder, there may be 0011111_01_01.jpg and 0011111_01_02.jpg (pictures of the main dwelling) and then 0011111_02_01.jpg (for the second structure). My viewer currently scrolls through all pictures with the _01_0*.jpg names, but not the _02_0*.jpg names. I want to go through the first structures pics and then right into the second structures pics.

    Pulls first picture with the account number
    pNum = 1
    dNum = 1
    Me.RPC.SetFocus
    Rec = Me.RPC.Text

    pth = "r:\" & "P0" & Left(Rec, 2) & "\"
    pFile = "00" & Rec & "_0" & dNum & "_0" & pNum & ".jpg"
    strFile = Dir(pth & pFile)

    If strFile <> "" Then

    Me.Ph.Picture = pth & pFile
    Me.PicNum.SetFocus
    Me.PicNum.Text = pNum

    When next is clicked...
    pNum = PicNum + 1
    dNum = 1
    Me.RPC.SetFocus
    Rec = Me.RPC.Text

    pth = "r:\" & "P0" & Left(Rec, 2) & "\"
    pFile = "00" & Rec & "_0" & dNum & "_0" & pNum & ".jpg"
    strFile = Dir(pth & pFile)

    If strFile <> "" Then

    Me.Ph.Picture = pth & pFile
    Me.PicNum.SetFocus
    Me.PicNum.Text = pNum
    End If
    Last edited by lherndon; 04-15-11 at 11:46.

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    When next is clicked...
    pNum = PicNum + 1
    dNum = 1 '<- this looks suspicious
    Me.RPC.SetFocus
    Rec = Me.RPC.Text
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Since your files nomenclature seems to be very regular, why don't you create a sorted array of file names then loop through this array to retrieve the name of the next file?

    It could be something like:
    Code:
    Function GetFileNames(StorageFolder As String) As Variant
    
        Dim i As Integer
        Dim fso As Scripting.FileSystemObject
        Dim x As Scripting.Folder
        Dim y As Scripting.File
        Dim z As Variant
        
        Set fso = New Scripting.FileSystemObject
        Set x = fso.GetFolder(StorageFolder)
        ReDim z(0 To x.Files.Count - 1)
        For Each y In x.Files
            z(i) = y.Name
            i = i + 1
        Next y
        
        ' Sorting does not seem to be necessary.
        '
        ' Quicksort z, 0, UBound(z)
        GetFileNames = z
    
    End Function
    When I try the array seem to be sorted, but if necessay you can force a sort on it:
    Code:
    Public Sub Quicksort(A As Variant, ByVal LowerBount As Long, ByVal UpperBount As Long)
                          
        Dim varMedVal As Variant
        Dim lngHigh As Long
        Dim lngLow As Long
        Dim i As Long
    
        If LowerBount >= UpperBount Then Exit Sub
        i = Int((UpperBount - LowerBount + 1) * Rnd + LowerBount)
        varMedVal = A(i)
        A(i) = A(LowerBount)
        lngLow = LowerBount
        lngHigh = UpperBount
        Do
            Do While A(lngHigh) >= varMedVal
                lngHigh = lngHigh - 1
                If lngHigh <= lngLow Then Exit Do
            Loop
            If lngHigh <= lngLow Then
                A(lngLow) = varMedVal
                Exit Do
            End If
            A(lngLow) = A(lngHigh)
            lngLow = lngLow + 1
            Do While A(lngLow) < varMedVal
                lngLow = lngLow + 1
                If lngLow >= lngHigh Then Exit Do
            Loop
            If lngLow >= lngHigh Then
                lngLow = lngHigh
                A(lngHigh) = varMedVal
                Exit Do
            End If
            A(lngHigh) = A(lngLow)
        Loop
        Quicksort A, LowerBount, lngLow - 1
        Quicksort A, lngLow + 1, UpperBount
        
    End Sub
    Have a nice day!

  4. #4
    Join Date
    Apr 2011
    Posts
    14

    Thanks

    Thanks guys for your responses.
    Healdem, I know the dnum = 1 is most certainly the cluprit for my problem currently, but I have tried changing and rearranging in every way that my limited expertise could come up with. Sinddha, I will try your suggestion for the array. Thanks.

Posting Permissions

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