File Length

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

File Length

Post by D Willett »

Hi
My project is built around a 5 character job number and every job is referenced as such, ie:

12345
12346
12347 etc etc etc

We've had new management software installed which uses different lengths of 6 and 8..
Some parts of my code look for filename length which is usually 8 characters because the format of our images, ie:

12345-01.jpg
12345-02.jpg etc


frmSEL.txtWarrImg = strFolder & "\" & Left$(Me.Controls("Text" & I), 8) & ".jpg"

Which will take the left 8 characters. It's worked for years like this with no issues.
Now I have to account for 5, 6 and 8 character job numbers.
How do I combat this?
I'm thinking as all images end with ".jpg" I should use the [Right] function but it is the [Left] of .jpg that I need as a text string which could be 8,9 or 11 characters.

I'm confused ...
Cheers ...

Dave.

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

Re: File Length

Post by HansV »

So what will the value of the text boxes Text1 etc. look like?
Best wishes,
Hans

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

Re: File Length

Post by D Willett »

They could be:

12345-02.jpg (8 left of .jpg)
123450-02.jpg (9 lft of .jpg)
12345000-02.jpg (11 left of .jpg)
Cheers ...

Dave.

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

Re: File Length

Post by HansV »

If that is the content of the text boxes, you don't need to use Left at all, because the value already includes .jpg. Simply use

frmSEL.txtWarrImg = strFolder & "\" & Me.Controls("Text" & I)
Best wishes,
Hans

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

Re: File Length

Post by D Willett »

But it's all the characters left of ".jpg" I need not all the string.
Cheers ...

Dave.

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

Re: File Length

Post by HansV »

But in the line

frmSEL.txtWarrImg = strFolder & "\" & Left$(Me.Controls("Text" & I), 8) & ".jpg"

you're extracting the characters before ".jpg", then adding ".jpg" again. Am I missing something?
Best wishes,
Hans

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

Re: File Length

Post by D Willett »

lol I just saw it ......... Having a bad day here !
I'm going to leave it till Monday :grin: :hairout:
Cheers ...

Dave.

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

Re: File Length

Post by HansV »

Have a good weekend, Dave!
Best wishes,
Hans

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

Re: File Length

Post by D Willett »

Cheers Hans lol .. have a great weekend too.. :-)
Cheers ...

Dave.

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

Re: File Length

Post by D Willett »

Back to the start now lol...

The textbox controls are populated by ( now I've made them visible - I had forgot ):

Code: Select all

arrFileNames(I, 2) = Format(fso.GetFile(strFolder & "\" & strFile).DateLastModified, "dd/mm/yy") & _
                             "  -  " & vbCrLf & "Added To Console On : " & Format(fso.GetFile(strFolder & "\" & strFile).DateLastModified, "dd/mm/yy")
Which gives the following:

98754-01 -Created 31/03/08 -
Added To Console On : 31/03/08

Which is why I used the left function to take just the job number (98754) and extension (-01) which is 8 characters together 98754-01.
Now if my job number is 5,6 or 8 then I can't use the left function. Below is a snippet from a routine for reference:

Code: Select all

Private Function imgRclick(I As Integer, Button As Integer)
    Dim oMenu  As cPOPupMenu
    Dim lMenuChosen As Long
    If Button = vbRightButton Then
        If Me.Controls("Text" & I) = vbNullString Then Exit Function
        Set oMenu = New cPOPupMenu
        lMenuChosen = oMenu.Popup("Add Image To Mail List", "-", "Zoom Image", "-", "Add or View Comment", "-", "Print This Image", "-", "Archive This Image",    "-", "Transfer To FTP", "-", "View Info", "-", "Send As Order", "-", "SEL Warranty Claim", "-", "Unspecified Method", "-", "Save As Useful Image !!")

        Select Case lMenuChosen
            Case 1
                 Me.lstEmail.AddItem strFolder & Left$(Me.Controls("Text" & I), 8) & ".jpg"
                
            Case 3 etc etc etc etc 
Cheers ...

Dave.

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

Re: File Length

Post by HansV »

Try the following:

Declare variables at the beginning of the procedure:

Dim strValue As String
Dim lngPos As Long

When you want to extract the job, use code like this:

' Value of text box
strValue = Me.Controls("Text" & I)
' Position of 1st space
lngPos = InStr(strValue, " ")
' Get part before space
strValue = Left(strValue, lngPos - 1)

You can use this to assemble the filename, e.g.

frmSEL.txtWarrImg = strFolder & "\" & strValue & ".jpg"
Best wishes,
Hans

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

Re: File Length

Post by D Willett »

:cheers:
Looks good !! Just done some testing and seems to return the section I need. As there's a couple of routines within the project I should give myself a couple of hrs to test properly before re-saving.

Thanks once again Hans.
Cheers ...

Dave.

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

Re: File Length

Post by D Willett »

Just taking this further, if I want to extract left of strValue - 4 also, then the following does work:

Code: Select all

    Dim strValue1 As String
    Dim strValue2 As String
    Dim lngPos1 As Long
    Dim lngPos2 As Long
        
    strValue1 = Me.Controls("Text" & I)
    strValue2 = Me.Controls("Text" & I)
    
    lngPos1 = InStr(strValue1, " ")
    lngPos2 = InStr(strValue2, " ")
    
    strValue1 = Left(strValue1, lngPos1 - 1)
    strValue2 = Left(strValue2, lngPos2 - 4)
But it looks quite unconventional to me ! tested works ok but will it cause me issues in the future?
Cheers ...

Dave.

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

Re: File Length

Post by HansV »

That should work fine!
Best wishes,
Hans

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

Re: File Length

Post by D Willett »

Cheers. I did test it and it worked, but thought you would add your efficient version lol.

I'll give myself a browny point :-)
Cheers ...

Dave.