Click to See Complete Forum and Search --> : Finding the path of a picture
Drakon
Jun 12th, 2002, 11:50 AM
I want a label to display the path of a picture box's picture... How would I do that?
Rick Bull
Jun 12th, 2002, 01:18 PM
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:
Public Function GetPath(ByVal FileName As String) As String
Dim intFound As Integer
intFound = InStrRev(FileName, "\")
If intFound > 0 Then GetPath = Mid(FileName, 1, intFound)
End Function
I haven't tested it but I think that's right.
Drakon
Jun 12th, 2002, 01:39 PM
But how do I use that?
Tec-Nico
Jun 12th, 2002, 02:30 PM
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
Rick Bull
Jun 12th, 2002, 06:20 PM
All right to use it you could have something like this:
Dim strPictureFileName As String, strPicturePath As String
strPictureFileName = "C:\Windows\Desktop\Picture.bmp"
strPicturePath = GetPath(strPictureFileName)
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 ;))
Tec-Nico
Jun 12th, 2002, 09:05 PM
Nah... It is ok. :D 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.
Rick Bull
Jun 13th, 2002, 06:14 AM
I did say that in my first post ;)
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.