File Length
-
- SilverLounger
- Posts: 1728
- Joined: 25 Jan 2010, 08:34
- Location: Stoke on Trent - Staffordshire - England
File Length
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 ...
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.
Dave.
-
- Administrator
- Posts: 78568
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- SilverLounger
- Posts: 1728
- Joined: 25 Jan 2010, 08:34
- Location: Stoke on Trent - Staffordshire - England
Re: File Length
They could be:
12345-02.jpg (8 left of .jpg)
123450-02.jpg (9 lft of .jpg)
12345000-02.jpg (11 left of .jpg)
12345-02.jpg (8 left of .jpg)
123450-02.jpg (9 lft of .jpg)
12345000-02.jpg (11 left of .jpg)
Cheers ...
Dave.
Dave.
-
- Administrator
- Posts: 78568
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: File Length
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)
frmSEL.txtWarrImg = strFolder & "\" & Me.Controls("Text" & I)
Best wishes,
Hans
Hans
-
- SilverLounger
- Posts: 1728
- Joined: 25 Jan 2010, 08:34
- Location: Stoke on Trent - Staffordshire - England
Re: File Length
But it's all the characters left of ".jpg" I need not all the string.
Cheers ...
Dave.
Dave.
-
- Administrator
- Posts: 78568
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: File Length
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?
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
Hans
-
- SilverLounger
- Posts: 1728
- Joined: 25 Jan 2010, 08:34
- Location: Stoke on Trent - Staffordshire - England
Re: File Length
lol I just saw it ......... Having a bad day here !
I'm going to leave it till Monday
I'm going to leave it till Monday
Cheers ...
Dave.
Dave.
-
- Administrator
- Posts: 78568
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- SilverLounger
- Posts: 1728
- Joined: 25 Jan 2010, 08:34
- Location: Stoke on Trent - Staffordshire - England
-
- SilverLounger
- Posts: 1728
- Joined: 25 Jan 2010, 08:34
- Location: Stoke on Trent - Staffordshire - England
Re: File Length
Back to the start now lol...
The textbox controls are populated by ( now I've made them visible - I had forgot ):
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:
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")
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.
Dave.
-
- Administrator
- Posts: 78568
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: File Length
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"
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
Hans
-
- SilverLounger
- Posts: 1728
- Joined: 25 Jan 2010, 08:34
- Location: Stoke on Trent - Staffordshire - England
Re: File Length
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.
Dave.
-
- SilverLounger
- Posts: 1728
- Joined: 25 Jan 2010, 08:34
- Location: Stoke on Trent - Staffordshire - England
Re: File Length
Just taking this further, if I want to extract left of strValue - 4 also, then the following does work:
But it looks quite unconventional to me ! tested works ok but will it cause me issues in the future?
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)
Cheers ...
Dave.
Dave.
-
- Administrator
- Posts: 78568
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- SilverLounger
- Posts: 1728
- Joined: 25 Jan 2010, 08:34
- Location: Stoke on Trent - Staffordshire - England
Re: File Length
Cheers. I did test it and it worked, but thought you would add your efficient version lol.
I'll give myself a browny point :-)
I'll give myself a browny point :-)
Cheers ...
Dave.
Dave.