For Programmers: Free Programming Magazines  


Home > Archive > Visual Basic Syntax > March 2006 > Is this possible









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Is this possible
Ron

2006-03-10, 7:00 pm

Hi
I run this code to list all the CD tracks from the My Music Library the
FileName is hard typed into the program like:-
FileName = Dir("C:\Documents and Settings\Ron\My Documents\My Music\The
Artists Name\The CD Name\*.*")

Do While Len(FileName)
List1.AddItem FileName
FileName = Dir()
Loop
I want to create FileName from the program with user input from listboxes on
Artists Name and from that selection The CD Name\*.*
So far I can get :- "C:\Documents and Settings\Ron\My Documents\My Music\The
Artists Name\"

Can you help please
If you need more code I can add to the post but its quite long so I have
not included it this far.
Randy Birch

2006-03-11, 3:58 am

You mean you want to change the hard-coded artist name to a name from a
listbox? If so, ...


dim sArtist as string

if list1.listindex > -1 then
sArtist = List1.List(List1.Listindex)
end if

if len(sArtist) > 0 then

FileName = Dir("C:\Documents and Settings\Ron\My Documents\My Music\" &
sArtist & "\The CD Name\*.*")
..... <other code>

end if


--

Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/

Please reply to the newsgroups so all can participate.




"Ron" <Ron@discussions.microsoft.com> wrote in message
news:2B355E9B-536C-46F8-B355-17ABB7F9BA4B@microsoft.com...
Hi
I run this code to list all the CD tracks from the My Music Library the
FileName is hard typed into the program like:-
FileName = Dir("C:\Documents and Settings\Ron\My Documents\My Music\The
Artists Name\The CD Name\*.*")

Do While Len(FileName)
List1.AddItem FileName
FileName = Dir()
Loop
I want to create FileName from the program with user input from listboxes on
Artists Name and from that selection The CD Name\*.*
So far I can get :- "C:\Documents and Settings\Ron\My Documents\My Music\The
Artists Name\"

Can you help please
If you need more code I can add to the post but its quite long so I have
not included it this far.

Ron

2006-03-11, 7:57 am

Hi Randy
Thanks for your post I have tried your code without success so I have
included some more code which comes before the part I want to change, as this
has to be able to work for any user not just me.
This is not for personal gain.

Option Explicit
Private Declare Function SHGetSpecialFolderPath Lib "Shell32.dll" Alias _
"SHGetSpecialFolderPathA" (ByVal hWndOwner As Long, ByVal lpszPath As
String, _
ByVal nFolder As Long, ByVal fCreate As Long) As Long

Private Const CSIDL_MYMUSIC As Long = &HD
Private Const MAX_PATH As Long = 260
Private gName As String
Private WithEvents Music As clsMusic


Private Sub Form_Load()
With Me
.Height = 5000
.Width = 10000
.Left = 700
End With
'Select Data
Call ScanMusicFolder 'Call Sub
GetMyMusicFolder 'Call Function
End Sub

Public Function GetMyMusicFolder() As String
Dim StrBuf As String

StrBuf = Space$(MAX_PATH)
If (SHGetSpecialFolderPath(Me.hWnd, StrBuf, CSIDL_MYMUSIC, 0&)) Then _
GetMyMusicFolder = TrimNull(StrBuf)
txtGotPath = GetMyMusicFolder & "\"

End Function

Private Sub ScanMusicFolder()
Dim MusicPath As String
Dim DirRet As String

MusicPath = AppendTrailingSlash(GetMyMusicFolder())

DirRet = Dir$(MusicPath, vbAlias - 1)
Do While Len(DirRet)
If (GetAttr(MusicPath & DirRet) And vbDirectory) Then
If (Len(Replace(DirRet, ".", ""))) Then _
Debug.Print "FOLDER: " & DirRet
'Filter un-wanted details
If DirRet = "." Or DirRet = ".." Or DirRet = "" _
Or DirRet = "Unknown Artist" Or DirRet = "Desktop.ini" _
Or DirRet = "License Backup" Or DirRet = "My Playlists"
Then
' do nothing
Else
List1.AddItem DirRet
End If
Else
Debug.Print "FILE: " & DirRet
'Filter un-wanted details
If DirRet = "." Or DirRet = ".." Or _
DirRet = "" Or DirRet = "Desktop.ini" Then
' do nothing
Else
List1.AddItem "FILE: " & DirRet
End If
End If

DirRet = Dir$()
Loop
End Sub

Public Sub txtGotPath_Click()
myPathHold = txtGotPath
Unload frmPath
List_Input.Show
End Sub

'List_Input Form

Private Sub Form_Load()
Set Music = New clsMusic
Dim myFile As String

Dim FileName As String
Dim i As Long
With Me
.Height = 6600
.Width = 9700
.Left = 700
End With
FileName = Dir(myPathHold)

Do While Len(FileName)
List1.AddItem FileName
FileName = Dir()
Loop

If I can get this part to work I will ask the other question if I cannot
figure it out myself.

"Randy Birch" wrote:

> You mean you want to change the hard-coded artist name to a name from a
> listbox? If so, ...
>
>
> dim sArtist as string
>
> if list1.listindex > -1 then
> sArtist = List1.List(List1.Listindex)
> end if
>
> if len(sArtist) > 0 then
>
> FileName = Dir("C:\Documents and Settings\Ron\My Documents\My Music\" &
> sArtist & "\The CD Name\*.*")
> ..... <other code>
>
> end if
>
> Randy Birch
> MS MVP Visual Basic
> http://vbnet.mvps.org/
>
> Please reply to the newsgroups so all can participate.
>
>
>
>


Randy Birch

2006-03-12, 7:00 pm

Not sure what "doesn't work" from your post; is the problem that you are
unsuccessfully attempting to get a list selection from the list_input form
for use somewhere in the main form?


And why are you using vbAlias in the Dir call -- that is for VBA running on
Mac's only.

--

Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/

Please reply to the newsgroups so all can participate.




"Ron" <Ron@discussions.microsoft.com> wrote in message
news:8E608F64-B1D4-46AB-9D15-A205D500BD5D@microsoft.com...
Hi Randy
Thanks for your post I have tried your code without success so I have
included some more code which comes before the part I want to change, as
this
has to be able to work for any user not just me.
This is not for personal gain.

Option Explicit
Private Declare Function SHGetSpecialFolderPath Lib "Shell32.dll" Alias _
"SHGetSpecialFolderPathA" (ByVal hWndOwner As Long, ByVal lpszPath As
String, _
ByVal nFolder As Long, ByVal fCreate As Long) As Long

Private Const CSIDL_MYMUSIC As Long = &HD
Private Const MAX_PATH As Long = 260
Private gName As String
Private WithEvents Music As clsMusic


Private Sub Form_Load()
With Me
.Height = 5000
.Width = 10000
.Left = 700
End With
'Select Data
Call ScanMusicFolder 'Call Sub
GetMyMusicFolder 'Call Function
End Sub

Public Function GetMyMusicFolder() As String
Dim StrBuf As String

StrBuf = Space$(MAX_PATH)
If (SHGetSpecialFolderPath(Me.hWnd, StrBuf, CSIDL_MYMUSIC, 0&)) Then _
GetMyMusicFolder = TrimNull(StrBuf)
txtGotPath = GetMyMusicFolder & "\"

End Function

Private Sub ScanMusicFolder()
Dim MusicPath As String
Dim DirRet As String

MusicPath = AppendTrailingSlash(GetMyMusicFolder())

DirRet = Dir$(MusicPath, vbAlias - 1)
Do While Len(DirRet)
If (GetAttr(MusicPath & DirRet) And vbDirectory) Then
If (Len(Replace(DirRet, ".", ""))) Then _
Debug.Print "FOLDER: " & DirRet
'Filter un-wanted details
If DirRet = "." Or DirRet = ".." Or DirRet = "" _
Or DirRet = "Unknown Artist" Or DirRet = "Desktop.ini" _
Or DirRet = "License Backup" Or DirRet = "My Playlists"
Then
' do nothing
Else
List1.AddItem DirRet
End If
Else
Debug.Print "FILE: " & DirRet
'Filter un-wanted details
If DirRet = "." Or DirRet = ".." Or _
DirRet = "" Or DirRet = "Desktop.ini" Then
' do nothing
Else
List1.AddItem "FILE: " & DirRet
End If
End If

DirRet = Dir$()
Loop
End Sub

Public Sub txtGotPath_Click()
myPathHold = txtGotPath
Unload frmPath
List_Input.Show
End Sub

'List_Input Form

Private Sub Form_Load()
Set Music = New clsMusic
Dim myFile As String

Dim FileName As String
Dim i As Long
With Me
.Height = 6600
.Width = 9700
.Left = 700
End With
FileName = Dir(myPathHold)

Do While Len(FileName)
List1.AddItem FileName
FileName = Dir()
Loop

If I can get this part to work I will ask the other question if I cannot
figure it out myself.

"Randy Birch" wrote:

> You mean you want to change the hard-coded artist name to a name from a
> listbox? If so, ...
>
>
> dim sArtist as string
>
> if list1.listindex > -1 then
> sArtist = List1.List(List1.Listindex)
> end if
>
> if len(sArtist) > 0 then
>
> FileName = Dir("C:\Documents and Settings\Ron\My Documents\My Music\" &
> sArtist & "\The CD Name\*.*")
> ..... <other code>
>
> end if
>
> Randy Birch
> MS MVP Visual Basic
> http://vbnet.mvps.org/
>
> Please reply to the newsgroups so all can participate.
>
>
>
>


Ron

2006-03-13, 7:57 am

Hi Randy
Just to confirm I am using a PC with OS xp not a mac, the code was provided
from a previous request for help, I do not have enough experience to spot the
point you made about vbAlias but it does work. The problem I have is the
variable inserted into the string does not work and I do not want to insert
my folder information as hard code but to add this part from the txtGotPath
or a variable to enable all users to use the program.

"Randy Birch" wrote:

> Not sure what "doesn't work" from your post; is the problem that you are
> unsuccessfully attempting to get a list selection from the list_input form
> for use somewhere in the main form?
>
>
> And why are you using vbAlias in the Dir call -- that is for VBA running on
> Mac's only.
>
> --
>
> Randy Birch
> MS MVP Visual Basic
> http://vbnet.mvps.org/
>
> Please reply to the newsgroups so all can participate.
>
>
>
>
> "Ron" <Ron@discussions.microsoft.com> wrote in message
> news:8E608F64-B1D4-46AB-9D15-A205D500BD5D@microsoft.com...
> Hi Randy
> Thanks for your post I have tried your code without success so I have
> included some more code which comes before the part I want to change, as
> this
> has to be able to work for any user not just me.
> This is not for personal gain.
>
> Option Explicit
> Private Declare Function SHGetSpecialFolderPath Lib "Shell32.dll" Alias _
> "SHGetSpecialFolderPathA" (ByVal hWndOwner As Long, ByVal lpszPath As
> String, _
> ByVal nFolder As Long, ByVal fCreate As Long) As Long
>
> Private Const CSIDL_MYMUSIC As Long = &HD
> Private Const MAX_PATH As Long = 260
> Private gName As String
> Private WithEvents Music As clsMusic
>
>
> Private Sub Form_Load()
> With Me
> .Height = 5000
> .Width = 10000
> .Left = 700
> End With
> 'Select Data
> Call ScanMusicFolder 'Call Sub
> GetMyMusicFolder 'Call Function
> End Sub
>
> Public Function GetMyMusicFolder() As String
> Dim StrBuf As String
>
> StrBuf = Space$(MAX_PATH)
> If (SHGetSpecialFolderPath(Me.hWnd, StrBuf, CSIDL_MYMUSIC, 0&)) Then _
> GetMyMusicFolder = TrimNull(StrBuf)
> txtGotPath = GetMyMusicFolder & "\"
>
> End Function
>
> Private Sub ScanMusicFolder()
> Dim MusicPath As String
> Dim DirRet As String
>
> MusicPath = AppendTrailingSlash(GetMyMusicFolder())
>
> DirRet = Dir$(MusicPath, vbAlias - 1)
> Do While Len(DirRet)
> If (GetAttr(MusicPath & DirRet) And vbDirectory) Then
> If (Len(Replace(DirRet, ".", ""))) Then _
> Debug.Print "FOLDER: " & DirRet
> 'Filter un-wanted details
> If DirRet = "." Or DirRet = ".." Or DirRet = "" _
> Or DirRet = "Unknown Artist" Or DirRet = "Desktop.ini" _
> Or DirRet = "License Backup" Or DirRet = "My Playlists"
> Then
> ' do nothing
> Else
> List1.AddItem DirRet
> End If
> Else
> Debug.Print "FILE: " & DirRet
> 'Filter un-wanted details
> If DirRet = "." Or DirRet = ".." Or _
> DirRet = "" Or DirRet = "Desktop.ini" Then
> ' do nothing
> Else
> List1.AddItem "FILE: " & DirRet
> End If
> End If
>
> DirRet = Dir$()
> Loop
> End Sub
>
> Public Sub txtGotPath_Click()
> myPathHold = txtGotPath
> Unload frmPath
> List_Input.Show
> End Sub
>
> 'List_Input Form
>
> Private Sub Form_Load()
> Set Music = New clsMusic
> Dim myFile As String
>
> Dim FileName As String
> Dim i As Long
> With Me
> .Height = 6600
> .Width = 9700
> .Left = 700
> End With
> FileName = Dir(myPathHold)
>
> Do While Len(FileName)
> List1.AddItem FileName
> FileName = Dir()
> Loop
>
> If I can get this part to work I will ask the other question if I cannot
> figure it out myself.
>
> "Randy Birch" wrote:
>
>
>

Randy Birch

2006-03-13, 7:02 pm

It's up to you to ensure the path returned is properly formatted for the
purpose you intend. This means judicious debug.print statements to ensure
the string has a trailing slash when required before you append your file to
the path, as well as ensuring any trailing nulls are removed before your
append.

As for the vbAlias -- I was just pointing out that that was for VBA under
Mac. This constant, as shown in the VBA help, has a value of 64 decimal, or
40 hex, which also corresponds to Windows' FILE_ATTRIBUTE_ENCRYPTED flag.

#define FILE_SHARE_READ 0x00000001
#define FILE_SHARE_WRITE 0x00000002
#define FILE_SHARE_DELETE 0x00000004
#define FILE_ATTRIBUTE_READONLY 0x00000001
#define FILE_ATTRIBUTE_HIDDEN 0x00000002
#define FILE_ATTRIBUTE_SYSTEM 0x00000004
#define FILE_ATTRIBUTE_DIRECTORY 0x00000010
#define FILE_ATTRIBUTE_ARCHIVE 0x00000020
#define FILE_ATTRIBUTE_ENCRYPTED 0x00000040
#define FILE_ATTRIBUTE_NORMAL 0x00000080
#define FILE_ATTRIBUTE_TEMPORARY 0x00000100
#define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200
#define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400
#define FILE_ATTRIBUTE_COMPRESSED 0x00000800
#define FILE_ATTRIBUTE_OFFLINE 0x00001000
#define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000
--

Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/

Please reply to the newsgroups so all can participate.




"Ron" <Ron@discussions.microsoft.com> wrote in message
news:55A67353-05D1-4188-8D20-51F37184A9AB@microsoft.com...
Hi Randy
Just to confirm I am using a PC with OS xp not a mac, the code was provided
from a previous request for help, I do not have enough experience to spot
the
point you made about vbAlias but it does work. The problem I have is the
variable inserted into the string does not work and I do not want to insert
my folder information as hard code but to add this part from the txtGotPath
or a variable to enable all users to use the program.

"Randy Birch" wrote:

> Not sure what "doesn't work" from your post; is the problem that you are
> unsuccessfully attempting to get a list selection from the list_input form
> for use somewhere in the main form?
>
>
> And why are you using vbAlias in the Dir call -- that is for VBA running
> on
> Mac's only.
>
> --
>
> Randy Birch
> MS MVP Visual Basic
> http://vbnet.mvps.org/
>
> Please reply to the newsgroups so all can participate.
>
>
>
>
> "Ron" <Ron@discussions.microsoft.com> wrote in message
> news:8E608F64-B1D4-46AB-9D15-A205D500BD5D@microsoft.com...
> Hi Randy
> Thanks for your post I have tried your code without success so I have
> included some more code which comes before the part I want to change, as
> this
> has to be able to work for any user not just me.
> This is not for personal gain.
>
> Option Explicit
> Private Declare Function SHGetSpecialFolderPath Lib "Shell32.dll" Alias _
> "SHGetSpecialFolderPathA" (ByVal hWndOwner As Long, ByVal lpszPath As
> String, _
> ByVal nFolder As Long, ByVal fCreate As Long) As Long
>
> Private Const CSIDL_MYMUSIC As Long = &HD
> Private Const MAX_PATH As Long = 260
> Private gName As String
> Private WithEvents Music As clsMusic
>
>
> Private Sub Form_Load()
> With Me
> .Height = 5000
> .Width = 10000
> .Left = 700
> End With
> 'Select Data
> Call ScanMusicFolder 'Call Sub
> GetMyMusicFolder 'Call Function
> End Sub
>
> Public Function GetMyMusicFolder() As String
> Dim StrBuf As String
>
> StrBuf = Space$(MAX_PATH)
> If (SHGetSpecialFolderPath(Me.hWnd, StrBuf, CSIDL_MYMUSIC, 0&)) Then _
> GetMyMusicFolder = TrimNull(StrBuf)
> txtGotPath = GetMyMusicFolder & "\"
>
> End Function
>
> Private Sub ScanMusicFolder()
> Dim MusicPath As String
> Dim DirRet As String
>
> MusicPath = AppendTrailingSlash(GetMyMusicFolder())
>
> DirRet = Dir$(MusicPath, vbAlias - 1)
> Do While Len(DirRet)
> If (GetAttr(MusicPath & DirRet) And vbDirectory) Then
> If (Len(Replace(DirRet, ".", ""))) Then _
> Debug.Print "FOLDER: " & DirRet
> 'Filter un-wanted details
> If DirRet = "." Or DirRet = ".." Or DirRet = "" _
> Or DirRet = "Unknown Artist" Or DirRet = "Desktop.ini"
> _
> Or DirRet = "License Backup" Or DirRet = "My Playlists"
> Then
> ' do nothing
> Else
> List1.AddItem DirRet
> End If
> Else
> Debug.Print "FILE: " & DirRet
> 'Filter un-wanted details
> If DirRet = "." Or DirRet = ".." Or _
> DirRet = "" Or DirRet = "Desktop.ini" Then
> ' do nothing
> Else
> List1.AddItem "FILE: " & DirRet
> End If
> End If
>
> DirRet = Dir$()
> Loop
> End Sub
>
> Public Sub txtGotPath_Click()
> myPathHold = txtGotPath
> Unload frmPath
> List_Input.Show
> End Sub
>
> 'List_Input Form
>
> Private Sub Form_Load()
> Set Music = New clsMusic
> Dim myFile As String
>
> Dim FileName As String
> Dim i As Long
> With Me
> .Height = 6600
> .Width = 9700
> .Left = 700
> End With
> FileName = Dir(myPathHold)
>
> Do While Len(FileName)
> List1.AddItem FileName
> FileName = Dir()
> Loop
>
> If I can get this part to work I will ask the other question if I cannot
> figure it out myself.
>
> "Randy Birch" wrote:
>
>
>


Karl E. Peterson

2006-03-13, 7:02 pm

Randy Birch wrote:
> It's up to you to ensure the path returned is properly formatted for
> the purpose you intend. This means judicious debug.print statements
> to ensure the string has a trailing slash when required before you
> append your file to the path, as well as ensuring any trailing nulls
> are removed before your append.


Or just simplify your life with some variation on this exceedingly common
theme:

Public Function ConcatPath(ByVal Path As String, ByVal File As String) As
String
' No leading or trailing spaces!
Path = Trim$(Path)
File = Trim$(File)
' Make sure we get a path separator between pieces.
If Right$(Path, 1) <> "\" Then Path = Path & "\"
If Left$(File, 1) = "\" Then
If Len(File) > 1 Then
File = Mid$(File, 2)
Else
File = ""
End If
End If
ConcatPath = Path & File
End Function

--
Working without a .NET?
http://classicvb.org/


Ron

2006-03-14, 7:57 am

"Karl E. Peterson" wrote:

> Randy Birch wrote:
>
> Or just simplify your life with some variation on this exceedingly common
> theme:
>
> Public Function ConcatPath(ByVal Path As String, ByVal File As String) As
> String
> ' No leading or trailing spaces!
> Path = Trim$(Path)
> File = Trim$(File)
> ' Make sure we get a path separator between pieces.
> If Right$(Path, 1) <> "\" Then Path = Path & "\"
> If Left$(File, 1) = "\" Then
> If Len(File) > 1 Then
> File = Mid$(File, 2)
> Else
> File = ""
> End If
> End If
> ConcatPath = Path & File
> End Function
> Working without a .NET?
> http://classicvb.org/


Hi Karl & Randy
I did run this function before I posted the variable and I have trimed all
the variables now but I cannot seem to write to FileName, and it does not
Debug.Print but all the variables do and I cannot see any leading or trailing
spaces. What am I doing wrong?

> Public Function AppendTrailingSlash(ByRef inPath As String, _

Optional ByVal inPathDelimiter As String = "\") As String
If (Right$(inPath, Len(inPathDelimiter)) = inPathDelimiter) Then _
AppendTrailingSlash = inPath Else _
AppendTrailingSlash = inPath & inPathDelimiter
End Function
>

Karl E. Peterson

2006-03-14, 7:02 pm

Ron wrote:
> Hi Karl & Randy
> I did run this function before I posted the variable and I have
> trimed all the variables now but I cannot seem to write to FileName,
> and it does not Debug.Print but all the variables do and I cannot see
> any leading or trailing spaces. What am I doing wrong?
>
> Public Function AppendTrailingSlash(ByRef inPath As String, _
> Optional ByVal inPathDelimiter As String = "\") As String
> If (Right$(inPath, Len(inPathDelimiter)) = inPathDelimiter) Then _
> AppendTrailingSlash = inPath Else _
> AppendTrailingSlash = inPath & inPathDelimiter
> End Function


Well, one thing that's totally wrong is line-wrapping a structure that
offers a multiline construct. I'd rebuild that as:

If (Right$(inPath, Len(inPathDelimiter)) = inPathDelimiter) Then
AppendTrailingSlash = inPath
Else
AppendTrailingSlash = inPath & inPathDelimiter
End If

Which is far more readable. As for what _else_ may be wrong, there's no way
to know given what you've offered here. What are you passing to this
function? What are you expecting it to return? What did you mean by "write
to Filename"?
--
Working without a .NET?
http://classicvb.org/


Ron

2006-03-15, 7:58 am

Hi Karl
When I say write to FileName this is what I mean:-
Dim FileName,mPathA,mArtists as String

'Kept Short for example
mPathA = ("C:\Docs and Setts\Me\My Docs\My Music\")
mArtists = "Artists Name"

'Result A will work
'Write to FileName
FileName = (mPathA & mArtists)

'Result B what I want to do, but does not work
'Write to FileName
FileName = Dir(mPathA & mArtists)
This is to explain what I mean, what should I have said please to make it
clear.

I am going back to what I am trying to do, I have put notes in the syntax to
show what is OK and where I get stuck and what help I need please.

I have a form call frmPath with 3 Listbox's and 1 Textbox. When I run the
form the end result should bulid a path to extract all CD's in the My Music
Folder and list them in listbox 1. Alow user input to select the artist name
required add this to the Path string and extract a list of CD's by that
artist and list them in Listbox 2. Allow user input to select a particular CD
and then list all the tracks on the CD in Listbox 3.
'Part One get Path, select artist from listbox1 add Path to selected artist
in Textbox
'this all works but I cannot get further. can you you help please.

Option Explicit
Private Declare Function SHGetSpecialFolderPath Lib "Shell32.dll" Alias _
"SHGetSpecialFolderPathA" (ByVal hWndOwner As Long, ByVal lpszPath As
String, _
ByVal nFolder As Long, ByVal fCreate As Long) As Long

Private Const CSIDL_MYMUSIC As Long = &HD
Private Const MAX_PATH As Long = 260
Private gName As String
Private WithEvents Music As clsMusic


Private Sub Form_Load()
With Me
.Height = 5000
.Width = 10000
.Left = 700
End With
'Select Data
Call ScanMusicFolder 'Call Sub
GetMyMusicFolder 'Call Function
End Sub

Public Function GetMyMusicFolder() As String
Dim StrBuf As String

StrBuf = Space$(MAX_PATH)
If (SHGetSpecialFolderPath(Me.hWnd, StrBuf, CSIDL_MYMUSIC, 0&)) Then _
GetMyMusicFolder = TrimNull(StrBuf)
txtGotPath = GetMyMusicFolder & "\"

End Function

Private Function TrimNull(ByRef inString As String) As String
Dim NullPos As Long

NullPos = InStr(1, inString, vbNullChar)
If (NullPos) Then TrimNull = Left$(inString, NullPos - 1) Else TrimNull
= inString
End Function
'***

Private Sub ScanMusicFolder()
Dim DirRet As String

MusicPath = AppendTrailingSlash(GetMyMusicFolder())

DirRet = Dir$(MusicPath, vbAlias - 1)
Do While Len(DirRet)
If (GetAttr(MusicPath & DirRet) And vbDirectory) Then
' If (Len(Replace(DirRet, ".", ""))) Then _
' Debug.Print "FOLDER: " & DirRet
'Filter un-wanted details
If DirRet = "." Or DirRet = ".." Or DirRet = "" _
Or DirRet = "Unknown Artist" Or DirRet = "Desktop.ini" _
Or DirRet = "License Backup" Or DirRet = "My Playlists"
Then
' do nothing
Else
List1.AddItem DirRet
End If
Else
' Debug.Print "FILE: " & DirRet
'Filter un-wanted details
If DirRet = "." Or DirRet = ".." Or _
DirRet = "" Or DirRet = "Desktop.ini" Then
' do nothing
Else
List1.AddItem "FILE: " & DirRet
End If
End If

DirRet = Dir$()
Loop
End Sub

Public Function AppendTrailingSlash(ByRef inPath As String, _
Optional ByVal inPathDelimiter As String = "\") As String
If (Right$(inPath, Len(inPathDelimiter)) = inPathDelimiter) Then
AppendTrailingSlash = inPath
Else
AppendTrailingSlash = inPath & inPathDelimiter
End If
End Function

Private Sub List1_Click()
txtGotPath = MusicPath & List1
End Sub

Public Sub txtGotPath_Click()
myPathHold = Trim$(txtGotPath) & Trim("\")
Unload frmPath
List_Input.Show
End Sub


Rick Rothstein [MVP - Visual Basic]

2006-03-15, 7:58 am

> When I say write to FileName this is what I mean:-
> Dim FileName,mPathA,mArtists as String


First off, of the three variables declared above, only mArtists is a
String... the other two will be Variants. Unlike other languages, VB does
not allow for short cut declarations like that. You have to do either this

Dim FileName As String, mPathA As String, mArtists as String

(if the above appears on two lines, it is because your news reader split it
for being too long, the above was typed on a single line) or do this

Dim FileName As String
Dim mPathA As String
Dim mArtists as String


> 'Kept Short for example
> mPathA = ("C:\Docs and Setts\Me\My Docs\My Music\")
> mArtists = "Artists Name"
>
> 'Result A will work
> 'Write to FileName
> FileName = (mPathA & mArtists)
>
> 'Result B what I want to do, but does not work
> 'Write to FileName
> FileName = Dir(mPathA & mArtists)


The reason the above doesn't work is because the concatenated string doesn't
end with a backslash. To the Dir function, mPathA looks like the directory
and mArtists looks like a file name that doesn't have an extension. Since
there is no such file in mPathA, the Dir function returns an empty string.
Add the "\" to the end of the concatenated string and you should get what
you want. Usually, I end string values like this with "\*.*" instead of just
"\" as I think that is clearer to understand.


Rick


Ron

2006-03-15, 7:01 pm

Hi Rick
Thanks for your reply, I did not know about the declarations fact, bad habit
from dBase lesson learnt. The other point you made I am not in the real
program doing and I do end the string with a backslash and *.* as you have
indicated but when I look or try to Debug.Print FileName = Dir() its blank.
taking the point that you seem to be saying it should work why does my fail?
'Note
On the 10th I posted the actual code I was using and where I had the error.
Regards
"Rick Rothstein [MVP - Visual Basic]" wrote:

>
> First off, of the three variables declared above, only mArtists is a
> String... the other two will be Variants. Unlike other languages, VB does
> not allow for short cut declarations like that. You have to do either this
>
> Dim FileName As String, mPathA As String, mArtists as String
>
> (if the above appears on two lines, it is because your news reader split it
> for being too long, the above was typed on a single line) or do this
>
> Dim FileName As String
> Dim mPathA As String
> Dim mArtists as String
>
>
>
> The reason the above doesn't work is because the concatenated string doesn't
> end with a backslash. To the Dir function, mPathA looks like the directory
> and mArtists looks like a file name that doesn't have an extension. Since
> there is no such file in mPathA, the Dir function returns an empty string.
> Add the "\" to the end of the concatenated string and you should get what
> you want. Usually, I end string values like this with "\*.*" instead of just
> "\" as I think that is clearer to understand.
>
>
> Rick
>
>
>

Karl E. Peterson

2006-03-15, 7:01 pm

Ron wrote:
> Hi Rick
> Thanks for your reply, I did not know about the declarations fact,
> bad habit from dBase lesson learnt. The other point you made I am not
> in the real program doing and I do end the string with a backslash
> and *.* as you have indicated but when I look or try to Debug.Print
> FileName = Dir() its blank. taking the point that you seem to be
> saying it should work why does my fail? 'Note
> On the 10th I posted the actual code I was using and where I had the
> error. Regards


I know I don't have the patience to go looking for it, so all I can is echo
Rick's suggested fix.
[color=darkred]

Do this:

FileName = Dir(mPathA & mArtists & "\*.*")

IF you're doing something else, post.
--
Working without a .NET?
http://classicvb.org/


Ron

2006-03-19, 6:59 pm


"Karl E. Peterson" wrote:

> I know I don't have the patience to go looking for it, so all I can is echo
> Rick's suggested fix.
>
>
> Do this:
>
> FileName = Dir(mPathA & mArtists & "\*.*")
>
> IF you're doing something else, post.
> --
> Working without a .NET?
> http://classicvb.org/
>
> Hi Karl
>Thanks for staying with me on this Karl, I now know whats wrong but I can't seem to solve the problem can you help please.


>If I have this the FileName remains empty
> FileName = Dir(mPathA & mArtists & "\*.*")


>However if I add a \ then type the track name in full and insert it between mArtists and the ampersand the FileName Debug.Prints and the Listbox will display all the tracks as required.


>I want a string variable called mCDName so the final Path will look like this:-


>FileName = Dir(mPathA & mArtists & "\" & mCDName & "\*.*" ) this is constructed as follows:-
>'Kept Short for example
>mPathA = ("C:\Docs and Setts\Me\My Docs\My Music\")
>mArtists = "Artists Name"
>mCDName = "CD Name"

I need to be able to select mCDName from a listbox the same as mArtists but
how can I search when the following strings don't work.
>
>FileName = Dir(mPathA & mArtists & "\")


>FileName = Dir(mPathA & mArtists & "\.*")


>FileName = Dir(mPathA & mArtists & "\*.*")


>All of the Artists Folders have have at least one CD Name in a folder down one level >some have many is there a way to search for them?


Karl E. Peterson

2006-03-20, 7:01 pm

Hi Ron --

I'm having a *really* hard time comprehending your response, partly because
of the odd quoting, and partly because, well, I just don't understand.

What I strongly recommend is that you "become one with your F8 key."
Single-step through your program, and examine each variable's value as you
go. When they change, make sure you understand why.

We clearly don't have the whole picture here, but you do. It's up to you to
look at it. This is really simple stuff. Slow down. Look. See.
(View-Locals, for an even better perspective!)

Thanks... Karl



Ron wrote:[color=darkred]
> "Karl E. Peterson" wrote:
>
>
>
>
>
> I need to be able to select mCDName from a listbox the same as
> mArtists but how can I search when the following strings don't work.
>
>
>

--
Working without a .NET?
http://classicvb.org/


Ron

2006-03-21, 7:58 am

Hi Karl
Thanks for your reply I have indeed stepped through the program as you
recommended. The results are in my last post but I can understand what seems
clear to me may not be clear to someone else, so I will try and claify the
situation.
I want to search the My Music Folder to obtain information about the CD's
stored there firstly by Artists Name then search again by a single artist for
all the CD's by that artists. When the second seach is completed list all the
tracks on that selected artists CD in a listbox. What that requires is a
string with 3 variables one for each search. Thats the whole task the way I
am doing this may not be the best way but it does work in part
OK what do I have so far.
First Search gets this
es wrong b ecause when I try to seach with this string I get a blank answer:-[color=darkred]
Trying as hard as I can I do not seem to be able to find out why that string
will not show what I want there are no spaces in the string and there
backslashes in the correct places. Does this string work on your PC?




"Karl E. Peterson" wrote:
[color=darkred]
> Hi Ron --
>
> I'm having a *really* hard time comprehending your response, partly because
> of the odd quoting, and partly because, well, I just don't understand.
>
> What I strongly recommend is that you "become one with your F8 key."
> Single-step through your program, and examine each variable's value as you
> go. When they change, make sure you understand why.
>
> We clearly don't have the whole picture here, but you do. It's up to you to
> look at it. This is really simple stuff. Slow down. Look. See.
> (View-Locals, for an even better perspective!)
>
> Thanks... Karl
>
>
>
> Ron wrote:
>
> --
> Working without a .NET?
> http://classicvb.org/
>
>
>

Karl E. Peterson

2006-03-21, 10:09 pm

Ron wrote:
> Hi Karl
> Thanks for your reply I have indeed stepped through the program as you
> recommended. The results are in my last post but I can understand
> what seems clear to me may not be clear to someone else, so I will
> try and claify the situation.
> I want to search the My Music Folder to obtain information about the
> CD's stored there firstly by Artists Name then search again by a
> single artist for all the CD's by that artists. When the second seach
> is completed list all the tracks on that selected artists CD in a
> listbox. What that requires is a string with 3 variables one for each
> search. Thats the whole task the way I am doing this may not be the
> best way but it does work in part
> OK what do I have so far.
> First Search gets this

At this point, jump into the Immediate window, and type this:

?"|";mPathA & mArtists & "\*.*";"|"

The vertical bars are there just to let you see leading/trailing spaces. If
that string looks good to you, jump into a command window, and try using it
there.
[color=darkred]
> Trying as hard as I can I do not seem to be able to find out why that
> string will not show what I want there are no spaces in the string
> and there backslashes in the correct places. Does this string work on
> your PC?


There's something fuzzy here, and there's absolutely no way for us to
diagnose it without the values of each of those variables. What you need to
do is get past "artists" and "CDs" and start talking files and folders.
That's the only concept computers (and programming languages) understand.

Wait a sec! Is that it? We're talking folders, here, aren't we? Try
something like this:

Dim file As String
Dim path As String
path = "x:\music\library\blues\Albert King"
file = Dir(path & "\*.*", vbDirectory)
Do While Len(file)
If GetAttr(path & "\" & file) And vbDirectory Then
If InStr(file, ".") <> 1 Then
' This is an actual folder!
Debug.Print file
End If
End If
file = Dir()
Loop

--
Working without a .NET?
http://classicvb.org/


Ron

2006-03-23, 8:08 am

Hi Karl
> At this point, jump into the Immediate window, and type this:
>
> ?"|";mPathA & mArtists & "\*.*";"|"

Did this and I cannot see any spaces in the sting. sorry I did not
understand the tem jump to a command window so I have not checked this.
>
> The vertical bars are there just to let you see leading/trailing spaces. If
> that string looks good to you, jump into a command window, and try using it
> there.
>
>
> There's something fuzzy here, and there's absolutely no way for us to
> diagnose it without the values of each of those variables. What you need to
> do is get past "artists" and "CDs" and start talking files and folders.
> That's the only concept computers (and programming languages) understand.
>
> Wait a sec! Is that it? We're talking folders, here, aren't we? Try
> something like this:


Yes they are all folders and I tried the code below and the result is that
file remains blank and vbDirectory has a value of 16
Does this give you any more clues as to what is going wrong? Just one
thought I had that this is part of a Class Module would that be effecting the
results?
> Dim file As String
> Dim path As String
> path = "x:\music\library\blues\Albert King"
> file = Dir(path & "\*.*", vbDirectory)
> Do While Len(file)
> If GetAttr(path & "\" & file) And vbDirectory Then
> If InStr(file, ".") <> 1 Then
> ' This is an actual folder!
> Debug.Print file
> End If
> End If
> file = Dir()
> Loop
>
> --
> Working without a .NET?
> http://classicvb.org/
>
>
>

Larry Serflaten

2006-03-23, 8:08 am


"Ron" <Ron@discussions.microsoft.com> wrote

> Yes they are all folders and I tried the code below and the result is that
> file remains blank and vbDirectory has a value of 16


Try this in a new form, change the "D:\Temp\" to your music directory.
It will list all the folders under that start folder. Your "mPathA & mArtists"
will have to exactly match any of those listed....

See if that gets you a little farther along....

LFS

Private Sub Form_Load()
Dim path As String
Dim List As New Collection

List.Add "D:\Temp\"

Do While List.Count
Debug.Print List(1)
FindSubs List
List.Remove 1
Loop
End Sub

Sub FindSubs(List As Collection)
Dim file As String
Dim path As String

path = List(1)
file = Dir(path & "*.*", vbDirectory)
Do While Len(file)
If Left(file, 1) <> "." Then
If GetAttr(path & file) And vbDirectory Then
List.Add path & file & "\"
End If
End If
file = Dir()
Loop
End Sub


Ron

2006-03-23, 7:08 pm

Hi Larry
Yes it does, I get what I wanted but I need to tailor it seach and display
in the format I require, but thank you for you help.
I also want to thank Karl for staying with me on this project even though I
did not always make myself clear.
Ok so thanks guys, if I get stuck again I post a new thread, but I have to
move house first, so must get on with the packing as she who must obeyed has
told me so. (Ha Ha)

"Larry Serflaten" wrote:

>
> "Ron" <Ron@discussions.microsoft.com> wrote
>
>
> Try this in a new form, change the "D:\Temp\" to your music directory.
> It will list all the folders under that start folder. Your "mPathA & mArtists"
> will have to exactly match any of those listed....
>
> See if that gets you a little farther along....
>
> LFS
>
> Private Sub Form_Load()
> Dim path As String
> Dim List As New Collection
>
> List.Add "D:\Temp\"
>
> Do While List.Count
> Debug.Print List(1)
> FindSubs List
> List.Remove 1
> Loop
> End Sub
>
> Sub FindSubs(List As Collection)
> Dim file As String
> Dim path As String
>
> path = List(1)
> file = Dir(path & "*.*", vbDirectory)
> Do While Len(file)
> If Left(file, 1) <> "." Then
> If GetAttr(path & file) And vbDirectory Then
> List.Add path & file & "\"
> End If
> End If
> file = Dir()
> Loop
> End Sub
>
>
>

Karl E. Peterson

2006-03-28, 10:03 pm

Glad you got it going. (Just got back from nearly a w offline, myself.)
--
Working without a .NET?
http://classicvb.org/


Ron wrote:[color=darkred]
> Hi Larry
> Yes it does, I get what I wanted but I need to tailor it seach and
> display in the format I require, but thank you for you help.
> I also want to thank Karl for staying with me on this project even
> though I did not always make myself clear.
> Ok so thanks guys, if I get stuck again I post a new thread, but I
> have to move house first, so must get on with the packing as she who
> must obeyed has told me so. (Ha Ha)
>
> "Larry Serflaten" wrote:
>



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com