PDA

View Full Version : Solved: Picture Size



mdmackillop
05-21-2013, 01:06 PM
Im running the following function to obtain the pixel size of jpg files. The answer is being returned in the form of ?3648 x 2736?. I'm trying to strip out the "?", but failing with Substitute. I can use Left/Right, but it's a bit messy. Any suggestions?



Sub Testing()
MsgBox fnGetDetailsOfVB("C:\Pics", "Photo.jpg")
End Sub


Function fnGetDetailsOfVB(pth, fil)
Dim objShell
Dim objFolder
Dim objFolderItem
Dim objInfo

Set objShell = CreateObject("shell.application")
Set objFolder = objShell.Namespace(pth & "\")
If (Not objFolder Is Nothing) Then
Set objFolderItem = objFolder.ParseName(fil)
If (Not objFolderItem Is Nothing) Then
objInfo = objFolder.GetDetailsOf(objFolderItem, 31)
End If
Set objFolderItem = Nothing
End If
fnGetDetailsOfVB = objInfo
Set objFolder = Nothing
Set objShell = Nothing
End Function

SamT
05-21-2013, 07:44 PM
Str = Mid(Str,2,Len(Str)-2)

snb
05-22-2013, 02:00 AM
keep it simple:

With CreateObject("shell.application").namespace("E:\OF\")
msgbox .getdetailsof(.Items.Item("example.jpg"), 26)
End With
or

With CreateObject("shell.application").namespace("E:\OF\")
msgbox split(.getdetailsof(.Items.Item("example.jpg"), -1),vblf)(0)
End With
or

With CreateObject("shell.application").namespace("E:\OF\")
msgbox mid(join(filter(split(.getdetailsof(.Items.Item("example.jpg"), -1),vblf),"Dimensions: "),""),12)
End With


see also:
http://www.snb-vba.eu/VBA_Bestanden_en.html#L_78

mdmackillop
05-22-2013, 08:35 AM
Thanks both.
@snb Much neater. I was using the verbose Microsoft version!
I still can't puzzle out the ? characters. The left character is code 63, but this still fails
p = "C:\Temp"
f = "Photo.jpg"

With CreateObject("shell.application").Namespace(p)
MsgBox Split(.getdetailsof(.Items.Item(f), 31), Chr(63))(1)
End With

snb
05-22-2013, 12:56 PM
The problem is this method is referring to the shell.application.
In my case that is Windows XP, but other versions of windows will use different numbers for the same properties.
On my system 31 doesn't return anything.
Can you show the result in your system ?

mdmackillop
05-22-2013, 01:59 PM
The answer is being returned in the form of ?3648 x 2736?. I'm using Windows 7 and 26 returned nothing. I looped 1 to 50 and found 31 returned the size parameters as shown. I can work with this result, I'm mainly puzzled at why "?" or chr(63) will not clear these characters. Does it do so in XP?

snb
05-22-2013, 02:06 PM
In XP 26 is returning '3648 x 2736 pixels'

You might try

c00=mid(.getdetailsof(.Items.Item(f), 31),2)
msgbox left(c00,len(c00)-1))


The ? might stand for an unrecognized character.
you can check


msgbox asc(left(.getdetailsof(.Items.Item(f), 31),1))

SamT
05-22-2013, 02:14 PM
:rotlaugh:


Str = Mid(Str,2,Len(Str)-2)

Str =.getdetailsof(.Items.Item(f), 31)

MsgBox Str = Mid(Str,2,Len(Str)-2)

mdmackillop
05-22-2013, 02:38 PM
Exactly what I did! It returned 63.

Final test as below. It seems that ? is not a simple character. I'll put it down to experience


Option Explicit
Sub Test()
Dim t, tt, Res, p, f, x
Dim MyTest As String

p = "C:\Temp"
f = "Photo.jpg"

MyTest = "?90 x 92?"

With CreateObject("shell.application").Namespace(p)
Res = .getdetailsof(.Items.Item(f), 31)
t = Left(Res, 1)
tt = Right(Res, 1)

Debug.Print Res
Debug.Print Application.Substitute(Res, t, "")
Debug.Print Application.Substitute(Res, tt, "")
End With

Debug.Print "MyTest - " & Application.Substitute(MyTest, Chr(63), "")

End Sub

Results
?90 x 92?
90 x 92?
?90 x 92
MyTest - 90 x 92

snb
05-22-2013, 02:44 PM
That's correct, like * ? isn't a simple character.

If I use:
c00 = "?1024 x 2480?"
c01 = Replace(c00, "?", "")
sn = Split(c00, "?")
x3 = UBound(sn) & sn(1)

I get the results I hoped for.
If you use Excel formulae the ? will be considered as a joker. So I would avoid application.substitute.
You might have to put \ or ~ before the ?

or you could consider to use:


Res=format(.getdetailsof(.Items.Item(f), 31))


PS. Since I use XP I can't test your code.

SamT
05-22-2013, 03:07 PM
Asc() Function ?
Sub Test()
Dim t, tt, Res, p, f, x
Dim MyTest As String

p = "C:\Temp"
f = "Photo.jpg"

MyTest = "?90 x 92?"

With CreateObject("shell.application").Namespace(p)
Res = .getdetailsof(.Items.Item(f), 31)
t = Left(Res, 1)
tt = Right(Res, 1)

Debug.Print Res
Debug.Print Asc(t)
Debug.Print Asc(tt)
End With
End Sub

Asc(string)

The required string argument is any valid string expression. If the string contains no characters, a run-time error occurs.

Remarks

The range for returns is 0 – 255 on non-DBCS systems, but –32768 – 32767 on DBCS systems.

mdmackillop
05-22-2013, 03:17 PM
Hi Sam
I got the expected result.
?90 x 92?
63
63
I don't think it's worth spending more time on this. Just "one of those things"

SamT
05-22-2013, 03:19 PM
Time to :beerchug:

mdmackillop
05-22-2013, 03:30 PM
Hi Snb
just tried Format and also CSTR but no change. I'll go with the Mid function I think as Post 2. Seems the easiest solution.
Thanks both.
Regards
Malcolm

belgas
05-23-2013, 04:50 AM
solved my problem: p