Character Position

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Character Position

Post by D Willett »

Revisiting some code which has worked fine over the last couple of years, the following now fails on certain pdf files.
My pdf files were usually named as (example) Meth1.pdf. They now have to have a different name:(example) Front-Wing-Left-Hand.pdf

With this change the code now bombs out when it encounters this type of filename.
I'm not sure how to change the pos declarations as there could be numerous "-" characters in each filename.
Can anyone see a solution to this?
Cheers

Code: Select all

Private Sub List2_Click()

    Dim pos1 As Integer, pos2 As Integer
    Dim pos1str As String, pos2str As String
    Dim N As Integer
    
    pos1 = InStrRev(List2.List(N), "-")    '6
    pos2 = InStrRev(List2.List(N), "\", pos1 - 1)    '0
    pos1str = Mid(List2.List(N), pos2 + 1, pos1 - 1)    '98754
    
    
    If Right(List2, 3) = "pdf" Then
        Me.MousePointer = vbHourglass
    End If

    If Right(List2, 3) = "jpg" Then
        Me.ImgPrevFTP.Picture = LoadPicture("L:\MMPDF\ConsoleFiles\" & pos1str & "\" & List2)
        
        'Me.PrevImg.Picture = LoadPicture("L:\MMPDF\ConsoleFiles\" & pos1str & "\" & List2)
    End If
    Me.MousePointer = vbDefault

End Sub
Cheers ...

Dave.

User avatar
HansV
Administrator
Posts: 78629
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Character Position

Post by HansV »

Why do you have a variable N in there? You never assign a value to it, but you do use it.
Best wishes,
Hans

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: Character Position

Post by D Willett »

Hi Hans. I have no idea sorry, its a routine you wrote a few years ago, I have probably changed it at some stage :scratch:
Cheers ...

Dave.

User avatar
HansV
Administrator
Posts: 78629
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Character Position

Post by HansV »

I'm afraid I can't make heads or tails of this version of the code. Can you explain what it is supposed to do?
Best wishes,
Hans

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: Character Position

Post by D Willett »

As far as I can recollect, the code checks through the filename to return the job number, but when it reaches a pdf with a long filename, such as :
"12345-Meth-Bumper-Wing-LH.pdf" it selects "12345-Meth-Bumper" as the job number, then it bombs out.
I would use a Left(5) routine but the job number is not always 5 characters.

Code: Select all

Private Sub List2_Click()

    Dim pos1 As Integer, pos2 As Integer
    Dim pos1str As String, pos2str As String
    Dim N      As Integer

    pos1 = InStrRev(List2.List(N), "-")    '6
    pos2 = InStrRev(List2.List(N), "\", pos1 - 1)    '0
    pos1str = Mid(List2.List(N), pos2 + 1, pos1 - 1)    '98754


    If Right(List2, 3) = "pdf" Then
        Me.MousePointer = vbHourglass
    End If

    If Right(List2, 3) = "jpg" Then
       ' ########## bombs out on the following line ##########
        Me.ImgPrevFTP.Picture = LoadPicture("L:\MMPDF\ConsoleFiles\" & pos1str & "\" & List2)

    End If
    Me.MousePointer = vbDefault

End Sub
You do not have the required permissions to view the files attached to this post.
Cheers ...

Dave.

User avatar
HansV
Administrator
Posts: 78629
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Character Position

Post by HansV »

What would be the correct path?
Best wishes,
Hans

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: Character Position

Post by D Willett »

L:\MMPDF\ConsoleFiles\12345\12345-019.jpg

Cheers
Cheers ...

Dave.

User avatar
HansV
Administrator
Posts: 78629
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Character Position

Post by HansV »

Thanks, And what is the actual value of List2?
Best wishes,
Hans

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: Character Position

Post by D Willett »

Heres a screen section Hans. Thanks.
You do not have the required permissions to view the files attached to this post.
Cheers ...

Dave.

User avatar
HansV
Administrator
Posts: 78629
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Character Position

Post by HansV »

So there is no backslash in the listbox items at all? :scratch:
Best wishes,
Hans

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: Character Position

Post by D Willett »

Confusing I know... sorry Hans :groan:
Cheers ...

Dave.

User avatar
HansV
Administrator
Posts: 78629
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Character Position

Post by HansV »

I assume that you posted only part of the code (otherwise it makes no sense), but here is a modified and simplified version of that part:

Code: Select all

Sub List2_Click()
    Dim pos1 As Integer
    Dim pos1str As String
    pos1 = InStr(Me.List2, "-")
    pos1str = Left(Me.List2, pos1 - 1)

    If Right(Me.List2, 3) = "pdf" Then
        Me.MousePointer = vbHourglass
    End If

    If Right(Me.List2, 3) = "jpg" Then
        Me.PrevImg.Picture = LoadPicture("L:\MMPDF\ConsoleFiles\" & pos1str & "\" & Me.List2)
    End If
    Me.MousePointer = vbDefault
End Sub
Best wishes,
Hans

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: Character Position

Post by D Willett »

Cheers Hans.. see attached, this is what is returned?
You do not have the required permissions to view the files attached to this post.
Cheers ...

Dave.

User avatar
HansV
Administrator
Posts: 78629
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Character Position

Post by HansV »

There are clearly backslashes \ in the code after ConsoleFiles and after pos1str:

LoadPicture("L:\MMPDF\ConsoleFiles\" & pos1str & "\" & Me.List2)

So I don't understand why the backslashes are missing in the error message. Do you have other code that removes backslashes?
Best wishes,
Hans

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: Character Position

Post by D Willett »

I'll step through and see here it picks them up.
Cheers Hans
Cheers ...

Dave.

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: Character Position

Post by D Willett »

Not sure if this the right way to go, but it seems to be working:

Code: Select all

Sub List2_Click()
    Dim pos1 As Integer
    Dim pos1str As String
    pos1 = InStr(Me.List2, "-")
    pos1str = Left(Me.List2, pos1 - 1)

    If Right(Me.List2, 3) = "pdf" Then
        Me.MousePointer = vbHourglass
    End If

    If Right(Me.List2, 3) = "jpg" Then
                Me.ImgPrevFTP.Picture = LoadPicture("L:" & "\" & "MMPDF" & "\" & "ConsoleFiles" & "\" & pos1str & "\" & Me.List2)
        
    End If
    Me.MousePointer = vbDefault
End Sub
Cheers ...

Dave.

User avatar
HansV
Administrator
Posts: 78629
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Character Position

Post by HansV »

The result should be exactly the same as what I posted, but if it works for you, go with it!
Best wishes,
Hans