Visual Basic

Moderators: None (Apply to moderate this forum)
Number of threads: 18013
Number of posts: 55386

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Path problem Posted by Ringo4269 on 5 Aug 2005 at 8:17 PM
I'm trying to select a media file from a filebox and play it. If the file is in the same directory as my program then this works.

FilenameTxt.Text = File1.FileName
FileName = FilenameTxt.Text
Play_MM

but when I modofy the code like this so it should work with files other than in my directory, It does not work

FilenameTxt.Text = File1.Path & "\" & File1.FileName
FileName = FilenameTxt.Text
Play_MM

I put it in the text box so I can see how it assembles the name and everything looks correct, but it does not work.
Any ideas what could be wrong with teh path?
Play_MM is below

Public Function Play_MM()
mciSendString "Close MM", 0, 0, 0
Last$ = Mainform.hwnd & " Style " & &H40000000
ToDo$ = "open " & FileName & " Alias MM parent " & Last$
i = mciSendString(ToDo$, 0&, 0, 0)
i = mciSendString("put MM window at 16 10 124 120", 0&, 0, 0)
i = mciSendString("play MM", 0&, 0, 0)
End Function

Thanks Ringo
Report
Re: Path problem Posted by BitByBit_Thor on 6 Aug 2005 at 4:25 AM
: I'm trying to select a media file from a filebox and play it. If the file is in the same directory as my program then this works.
:
: FilenameTxt.Text = File1.FileName
: FileName = FilenameTxt.Text
: Play_MM
:
: but when I modofy the code like this so it should work with files other than in my directory, It does not work
:
: FilenameTxt.Text = File1.Path & "\" & File1.FileName
: FileName = FilenameTxt.Text
: Play_MM
:
: I put it in the text box so I can see how it assembles the name and everything looks correct, but it does not work.
: Any ideas what could be wrong with teh path?
: Play_MM is below
:
: Public Function Play_MM()
: mciSendString "Close MM", 0, 0, 0
: Last$ = Mainform.hwnd & " Style " & &H40000000
: ToDo$ = "open " & FileName & " Alias MM parent " & Last$
: i = mciSendString(ToDo$, 0&, 0, 0)
: i = mciSendString("put MM window at 16 10 124 120", 0&, 0, 0)
: i = mciSendString("play MM", 0&, 0, 0)
: End Function
:
: Thanks Ringo
:

There are two properties: FileName and FileTitle.
FileName: the full path to the file
FileTitle: the name of the file, without the path

So, to play the file selected:

ToDo$ = "open " & File1.FileName & "..."

In VB.NET only FileName is available for OpenFileDialog... But in VB6 both properties are available.

(There is no property called File1.Path is there?!)
Greets...
Richard

Report
Re: Path problem Posted by Ringo4269 on 6 Aug 2005 at 4:48 PM
: : I'm trying to select a media file from a filebox and play it. If the file is in the same directory as my program then this works.
: :
: : FilenameTxt.Text = File1.FileName
: : FileName = FilenameTxt.Text
: : Play_MM
: :
: : but when I modofy the code like this so it should work with files other than in my directory, It does not work
: :
: : FilenameTxt.Text = File1.Path & "\" & File1.FileName
: : FileName = FilenameTxt.Text
: : Play_MM
: :
: : I put it in the text box so I can see how it assembles the name and everything looks correct, but it does not work.
: : Any ideas what could be wrong with teh path?
: : Play_MM is below
: :
: : Public Function Play_MM()
: : mciSendString "Close MM", 0, 0, 0
: : Last$ = Mainform.hwnd & " Style " & &H40000000
: : ToDo$ = "open " & FileName & " Alias MM parent " & Last$
: : i = mciSendString(ToDo$, 0&, 0, 0)
: : i = mciSendString("put MM window at 16 10 124 120", 0&, 0, 0)
: : i = mciSendString("play MM", 0&, 0, 0)
: : End Function
: :
: : Thanks Ringo
: :
:
: There are two properties: FileName and FileTitle.
: FileName: the full path to the file
: FileTitle: the name of the file, without the path
:
: So, to play the file selected:
:
: ToDo$ = "open " & File1.FileName & "..."
:
: In VB.NET only FileName is available for OpenFileDialog... But in VB6 both properties are available.
:
: (There is no property called File1.Path is there?!)
: Greets...
: Richard
:
I guess I should have said I'm using VB6, so there is no filetitle that I know of. File1.Path is there and it returns what looks correct. That is why I put it in teh textbox then pass the contents of teh textbox to mcisendstring.
FOr example, this is the contents of teh textbox when I navigate to a file
c:\Documents and Settings\Owner\Desktop\funny videos\cat_in_a_fan.wmv

which does not work
but If I don't use teh path property and and access a file in my program directory so that the text box looks like this

cat_in_a_fan.wmv
then it works. Could it have somethign to do with spaces in teh path?
Ringo


Report
Re: Path problem Posted by Ringo4269 on 6 Aug 2005 at 4:53 PM
: : : I'm trying to select a media file from a filebox and play it. If the file is in the same directory as my program then this works.
: : :
: : : FilenameTxt.Text = File1.FileName
: : : FileName = FilenameTxt.Text
: : : Play_MM
: : :
: : : but when I modofy the code like this so it should work with files other than in my directory, It does not work
: : :
: : : FilenameTxt.Text = File1.Path & "\" & File1.FileName
: : : FileName = FilenameTxt.Text
: : : Play_MM
: : :
: : : I put it in the text box so I can see how it assembles the name and everything looks correct, but it does not work.
: : : Any ideas what could be wrong with teh path?
: : : Play_MM is below
: : :
: : : Public Function Play_MM()
: : : mciSendString "Close MM", 0, 0, 0
: : : Last$ = Mainform.hwnd & " Style " & &H40000000
: : : ToDo$ = "open " & FileName & " Alias MM parent " & Last$
: : : i = mciSendString(ToDo$, 0&, 0, 0)
: : : i = mciSendString("put MM window at 16 10 124 120", 0&, 0, 0)
: : : i = mciSendString("play MM", 0&, 0, 0)
: : : End Function
: : :
: : : Thanks Ringo
: : :
: :
: : There are two properties: FileName and FileTitle.
: : FileName: the full path to the file
: : FileTitle: the name of the file, without the path
: :
: : So, to play the file selected:
: :
: : ToDo$ = "open " & File1.FileName & "..."
: :
: : In VB.NET only FileName is available for OpenFileDialog... But in VB6 both properties are available.
: :
: : (There is no property called File1.Path is there?!)
: : Greets...
: : Richard
: :
: I guess I should have said I'm using VB6, so there is no filetitle that I know of. File1.Path is there and it returns what looks correct. That is why I put it in teh textbox then pass the contents of teh textbox to mcisendstring.
: FOr example, this is the contents of teh textbox when I navigate to a file
: c:\Documents and Settings\Owner\Desktop\funny videos\cat_in_a_fan.wmv
:
: which does not work
: but If I don't use teh path property and and access a file in my program directory so that the text box looks like this
:
: cat_in_a_fan.wmv
: then it works. Could it have somethign to do with spaces in teh path?
: Ringo
:
:

Ok so it is the spaces in the path. A path like F:\test\file.wmv works fine, so do I get around this problem?
Ringo



Report
Re: Path problem Posted by pseudocoder on 6 Aug 2005 at 8:24 PM
: Ok so it is the spaces in the path. A path like F:\test\file.wmv works fine, so do I get around this problem?
: Ringo

You could try getting the short path name, and build your path that way... from the API Guide
Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" _
(ByVal lpszLongPath As String, ByVal lpszShortPath As String, _
ByVal lBuffer As Long) As Long

Public Function GetShortPath(strFileName As String) As String
    
    Dim lngRes As Long, strPath As String
    'Create a buffer
    strPath = String$(165, 0)
    'retrieve the short pathname
    lngRes = GetShortPathName(strFileName, strPath, 164)
    'remove all unnecessary chr$(0)'s
    GetShortPath = Left$(strPath, lngRes)
End Function

Private Sub Form_Load()
    MsgBox GetShortPath("c:\Program Files\")
End Sub

Report
Re: Path problem Posted by BitByBit_Thor on 7 Aug 2005 at 12:59 PM
This message was edited by BitByBit_Thor at 2005-8-7 12:59:42

I could hardly believe that VB6 and it's controls would ever need Short file names!

Let me ask it more clearly: What is the typename of the control of File1?

Greets...
Richard



Report
Re: Path problem Posted by Bulgarian_VB on 13 Aug 2005 at 12:10 PM
: This message was edited by BitByBit_Thor at 2005-8-7 12:59:42

: I could hardly believe that VB6 and it's controls would ever need Short file names!
:
: Let me ask it more clearly: What is the typename of the control of File1?
:
: Greets...
: Richard
:
:
:
:
Richard,

File1 is a FileListBox control, not a CommonDialog control. The control itself doesn't need short path. It is the MM subsystem that needs it, becuase its command parameter separator is a space, and if the path contains a space ... you can imagine what happens. Something like DOS.

Report
Re: Path problem Posted by BitByBit_Thor on 14 Aug 2005 at 10:08 AM
: Richard,
:
: File1 is a FileListBox control, not a CommonDialog control.

So much could have been spared me if he had just answered that question

:The control itself doesn't need short path. It is the MM subsystem that needs it, becuase its command parameter separator is a space, and if the path contains a space ... you can imagine what happens. Something like DOS.
:

Then your solution should definitely work...


Greets...
Richard




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.