Consulting

Results 1 to 15 of 15

Thread: Solved: Picture Size

  1. #1
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location

    Solved: Picture Size

    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?



    [VBA]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
    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Str = Mid(Str,2,Len(Str)-2)
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    keep it simple:

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

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

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

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

  4. #4
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    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
    [VBA]p = "C:\Temp"
    f = "Photo.jpg"

    With CreateObject("shell.application").Namespace(p)
    MsgBox Split(.getdetailsof(.Items.Item(f), 31), Chr(63))(1)
    End With[/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    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 ?

  6. #6
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    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?
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  7. #7
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    In XP 26 is returning '3648 x 2736 pixels'

    You might try
    [vba]
    c00=mid(.getdetailsof(.Items.Item(f), 31),2)
    msgbox left(c00,len(c00)-1))
    [/vba]

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

    [vba]
    msgbox asc(left(.getdetailsof(.Items.Item(f), 31),1))
    [/vba]

  8. #8
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location

    Str = Mid(Str,2,Len(Str)-2)
    Str =.getdetailsof(.Items.Item(f), 31)

    MsgBox Str = Mid(Str,2,Len(Str)-2)
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  9. #9
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    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

    [VBA]
    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[/VBA]

    Results
    [VBA]?90 x 92?
    90 x 92?
    ?90 x 92
    MyTest - 90 x 92[/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  10. #10
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    That's correct, like * ? isn't a simple character.

    If I use:
    [vba] c00 = "?1024 x 2480?"
    c01 = Replace(c00, "?", "")
    sn = Split(c00, "?")
    x3 = UBound(sn) & sn(1)
    [/vba]
    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:

    [VBA]
    Res=format(.getdetailsof(.Items.Item(f), 31))
    [/VBA]

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

  11. #11
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Asc() Function ?
    [vba]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
    [/vba]
    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.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  12. #12
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    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"
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  13. #13
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Time to
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  14. #14
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    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
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  15. #15
    VBAX Newbie
    Joined
    May 2013
    Posts
    3
    Location
    solved my problem: p

Posting Permissions

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