Results 1 to 7 of 7

Thread: Finding the path of a picture

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2001
    Location
    2 miles from everywhere
    Posts
    80

    Finding the path of a picture

    I want a label to display the path of a picture box's picture... How would I do that?
    Do you know if you will answer no to this question?
    If we've never seen something happen, we can't know if its impossible.
    If the soles of a shoe make faces at the floor when we don't look and isn't being watched via mirror or video tape, will we ever know?
    If someone orders you to disobey all of their orders, do you obey or disobey?

  2. #2
    Frenzied Member Rick Bull's Avatar
    Join Date
    Apr 2002
    Location
    England
    Posts
    1,444
    I think the picture property returns a handle to the picture's memory address, but if you keep track of it's location you should be able to use something like this:

    VB Code:
    1. Public Function GetPath(ByVal FileName As String) As String
    2.     Dim intFound As Integer
    3.     intFound = InStrRev(FileName, "\")
    4.     If intFound > 0 Then GetPath = Mid(FileName, 1, intFound)
    5. End Function

    I haven't tested it but I think that's right.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 2001
    Location
    2 miles from everywhere
    Posts
    80
    But how do I use that?
    Do you know if you will answer no to this question?
    If we've never seen something happen, we can't know if its impossible.
    If the soles of a shoe make faces at the floor when we don't look and isn't being watched via mirror or video tape, will we ever know?
    If someone orders you to disobey all of their orders, do you obey or disobey?

  4. #4
    Frenzied Member Tec-Nico's Avatar
    Join Date
    Jun 2002
    Location
    México
    Posts
    1,192

    Exclamation

    Hey Rick Bull... the idea is alright. But you forgot to declare InStrRev, I ran a project using it and it asked for a declaration for it.

    Besides I also believe you should have given an example of how to use the code. I tried:


    Private Sub Form_Load()
    Label1.Caption = GetPath(Picture1)
    End Sub
    We miss you, friend... Rest in Peace, we will take care of the rest of it.

    [vbcode]
    On Error Me.Fault = False
    [/vbcode]
    - Silence is the human way to share ignorance
    Tec-Nico

  5. #5
    Frenzied Member Rick Bull's Avatar
    Join Date
    Apr 2002
    Location
    England
    Posts
    1,444
    All right to use it you could have something like this:

    VB Code:
    1. Dim strPictureFileName As String, strPicturePath As String
    2. strPictureFileName = "C:\Windows\Desktop\Picture.bmp"
    3. strPicturePath = GetPath(strPictureFileName)
    4. MsgBox(strPicturePath)

    That should display "C:\Windows\Desktop". Obviously you will want to store the proper filename in strPictureFileName, not just "C:\Windows\Desktop\Picture.bmp".

    And I didn't forget to declare InstrRev, it sounds like you have VB5 or eariler, you need 6. If you want the function I could probably work it out for you (if I can be bothered )

  6. #6
    Frenzied Member Tec-Nico's Avatar
    Join Date
    Jun 2002
    Location
    México
    Posts
    1,192
    Nah... It is ok. I use VB4 indeed and VB5 CCE, I could upgrade to VB6 but I like the 4 better, I guess it is because of a certain something it has. Don't worry about giving the function, it can easily be declared by accessing the kernel32 but still, I think that if our friend did not have VB6 he would have had the same problem I did. Still, I consider your solution a good idea.

    Just point out you need to know the location of the picture in order to display the path in the caption of the label, else if you are using the control (Like I did in the code I presented earlier) it will not show the source file you got the picture from.
    We miss you, friend... Rest in Peace, we will take care of the rest of it.

    [vbcode]
    On Error Me.Fault = False
    [/vbcode]
    - Silence is the human way to share ignorance
    Tec-Nico

  7. #7
    Frenzied Member Rick Bull's Avatar
    Join Date
    Apr 2002
    Location
    England
    Posts
    1,444
    I did say that in my first post

Posting Permissions

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



Click Here to Expand Forum to Full Width