From: Larry Serflaten on 10 May 2010 12:09 "LondonLad" <LondonLad(a)discussions.microsoft.com> wrote > A bit late to answer this been away for a few days, but here goes. > This is the full path string that I need to extract data from:- > > 1. F:\Stored Data\Library\Danny Williams\03 Love is Kind.mp3 > 2. F:\Stored Data\Library\Ken Follet\The Dangers of Time > 3. F:\Stored Data\Library\Roger Moore&Tony Curtis\Five Miles to Midnight.avi > 4. F:\Stored Data\Library\Barry White\05 Just The Way You Are.wma > 5. F:\Stored Data\Library\Hols 07\Italian Lakes.wmv > > The first job is to split the Library Folder by File.extn with MP3 and wma > going into the same New Folder then with the music I want just the Artists > Name and the Title of the recording. Some recordings do not have a number in > the Title Section. If I may interject here, a job like this is often best done in a piecemeal fashion. If I understand correctly, you want to move files with certain extentions (mp3, wma, etc.) from one folder, to a new folder, or perhaps, just to create a text file listing the whole bunch. In that process you want to extract out the artist and song titles for moving, /or/ listing from their current paths. In addition, you'd like to filter out occasional numbers that appear randomly in the artist or song title. By piecemeal, I mean that you have a repetative pattern of folders containing songs, that need extraction and filtering. Taken to its lowest level, both artists and songs need filtering, which could be handled by the same filter routine. If you use a FileListBox to list your files, you can assign a pattern to it that will cause it to list only the files you want (mp3, wma, etc.) which also extracts the filenames to a list. It would seem, half the job would be done right there, just by putting the FileListBox to use. You could visit each folder (extracting the artists name) and loop through the list to get the desired filenames. Then all that is left is to do the filtering on each. Are you looking to move the files, or create some large text file listing the songs you find? LFS
From: Rick Rothstein on 10 May 2010 12:47 I'm still not totally clear where you are going with all this; however, I think this might help you. The following code snippet assumes your list of directories is stored in an array named FileNames, so change that as necessary. The code loops through the FileNames array and splits out the artist, title and file extension into three arrays named Artist, Title, and Extension. These three arrays are coordinated by their index; so, for, say the 4th item in the FileNames array (index value 3 if Option Base is set to 0, otherwise index value 4 if Option Base is set to 1), which is this... F:\Stored Data\Library\Barry White\05 Just The Way You Are.wma then these are the contents of the arrays... Artist(4) ==> "Barry White" Title(4) ==> "Just The Way You Are" Extension(4) ==> "wma" So, you can just iterate the three arrays, examine the relevant array and place the data according to your needs. By the way, I notice one of your filename paths does not have an extension... the Extension array will contain the empty string for it. Okay, here is the code... Dim X As Long, Position As Long, FileNames() As String, Parts() As String Dim Artist() As String, Title() As String, Extension() As String '.... '.... ReDim Artist(LBound(FileNames) To UBound(FileNames)) ReDim Title(LBound(FileNames) To UBound(FileNames)) ReDim Extension(LBound(FileNames) To UBound(FileNames)) For X = LBound(FileNames) To UBound(FileNames) Parts = Split(FileNames(X), "\") Artist(X) = Parts(UBound(Parts) - 1) Position = InStrRev(Parts(UBound(Parts)), ".") If Position = 0 Then Title(X) = Parts(UBound(Parts)) Else Title(X) = Left(Parts(UBound(Parts)), Position - 1) If Title(X) Like "#*" Then Title(X) = Trim(Split(Title(X), Val(Title(X)), 2)(1)) End If Extension(X) = Mid(Parts(UBound(Parts)), Position + 1) End If Next '.... '.... -- Rick (MVP - Excel) "LondonLad" <LondonLad(a)discussions.microsoft.com> wrote in message news:064CB269-AAE9-46DE-AB9B-2BA7D4A771B2(a)microsoft.com... > Hi Rick > A bit late to answer this been away for a few days, but here goes. > This is the full path string that I need to extract data from:- > > 1. F:\Stored Data\Library\Danny Williams\03 Love is Kind.mp3 > 2. F:\Stored Data\Library\Ken Follet\The Dangers of Time > 3. F:\Stored Data\Library\Roger Moore&Tony Curtis\Five Miles to > Midnight.avi > 4. F:\Stored Data\Library\Barry White\05 Just The Way You Are.wma > 5. F:\Stored Data\Library\Hols 07\Italian Lakes.wmv > > The first job is to split the Library Folder by File.extn with MP3 and wma > going into the same New Folder then with the music I want just the Artists > Name and the Title of the recording. Some recordings do not have a number > in > the Title Section. > > Regards > > Ron > > "Rick Rothstein" wrote: > >> Your original question was basically "how do I determine if there is a >> digit >> in my text"? Now, while I'm not 100% sure what the code snippet you >> posted >> should be doing, it does seem to hint at that you may have been asking >> the >> wrong question initially. I think you saw a path to your end result and >> asked us about one step along the way, but I am thinking there is a >> better >> way to get to your ultimate goal. Can you do us a favor? Forget about the >> ListBox and what you have split out and not split out... can you just >> give >> us maybe 4 or 5 samples of possible starting text (full path if that is >> what >> you have)(with and without numbers in whatever places numbers could >> possibly >> be located) and how you need each of them to look after being processed >> by >> the parsing part of your code? >> >> -- >> Rick (MVP - Excel) >> >> >> >> "LondonLad" <LondonLad(a)discussions.microsoft.com> wrote in message >> news:459AD240-D89F-47D1-9AC1-4EBA43121520(a)microsoft.com... >> > Hi Rick >> > After my post I found that it was possible to get a number in the file >> > extn. >> > which >> > was picked up using the like example and I could not figure how to >> > avoid >> > this. >> > Your code sample was the shortest way to find if numbers were included >> > this >> > is what I finished up with in my test project. >> > I split the full string which includes folders and place the results in >> > a >> > ListBox >> > >> > txtA = LTrim(Mid(txtAns.List(2), 4)) >> > xStr = Mid(txtAns.List(3), 4) >> > strAns = Val(xStr) >> > If strAns > 0 Then strNum = 7 Else strNum = 5 >> > xStr = LTrim(Mid(txtAns.List(3), strNum)) >> > xLen(2) = Len(xStr) >> > txtB = Left(xStr, xLen(2) - 3) >> > >> > I am willing to change this if you can show me a better way. >> > Thanks for your interest. >> > >> > Regards >> > >> > Ron >> > >> > "Rick Rothstein" wrote: >> > >> >> Just curious... what "other errors" do you think you would encounter >> >> by >> >> using the Like operator as proposed in my first posting? >> >> >> >> I'm also curious about the code you plan to use for your If..Then >> >> test? >> >> >> >> -- >> >> Rick (MVP - Excel) >> >> >> >> >> >> "LondonLad" <LondonLad(a)discussions.microsoft.com> wrote in message >> >> news:9DC2AFF9-E9BC-416A-B95F-A3ED27B01463(a)microsoft.com... >> >> > Hi >> >> > Thank you all for your posts. >> >> > In the end I used Val as I felt that this gave less chance of other >> >> > errors >> >> > later. >> >> > >> >> > Regards >> >> > >> >> > Ron >> >> > >> >> > "Helmut Meukel" wrote: >> >> > >> >> >> "LondonLad" <LondonLad(a)discussions.microsoft.com> schrieb im >> >> >> Newsbeitrag >> >> >> news:B96BED25-0A88-4124-9E61-3B874330B57D(a)microsoft.com... >> >> >> > Hi >> >> >> > xStr can contain a string which includes numbers or not contain >> >> >> > numbers >> >> >> > >> >> >> > if it contains numbers I want to edit it. >> >> >> > >> >> >> > In my example which does not work >> >> >> > xStr = "03 Best of Time" >> >> >> > >> >> >> > If IsNumeric(xStr) Then txtHold.Text = "Yes" Else txtHold.Text = >> >> >> > "No" >> >> >> > >> >> >> > Can you help please >> >> >> > >> >> >> > Ron >> >> >> >> >> >> >> >> >> >> >> >> Ron, >> >> >> >> >> >> depending on where the number(s) are, Val(xStr) may work. >> >> >> >> >> >> The ancient Val function returns a Double if the string starts with >> >> >> a number. It stops conversion when it encounters a non-numerical >> >> >> character. If the string starts with a non-numerical character it >> >> >> will return 0. It's not localized, it recognizes only the dot as >> >> >> decimal sign. >> >> >> Spaces are totally ignored by Val. >> >> >> >> >> >> Here some examples: >> >> >> Val("123 that's for me") will return 123 but >> >> >> Val("1, 2, 3, that's for me") will return 1, because there is a >> >> >> comma after the 1. >> >> >> Val(".25 $") will return 0.25 >> >> >> Val("$ 125") will return 0, because the string starts with a >> >> >> non-numerical character >> >> >> Val("5 6 7 8") will return 5678 >> >> >> Val("- 12" will return -12 >> >> >> >> >> >> If you are certain about how your data looks like, >> >> >> and you want speed, Val may be your choice. >> >> >> >> >> >> Helmut. >> >> >> >> >> >> >> >> >> . >> >> >> >> >> . >> >> >> . >>
From: LondonLad on 11 May 2010 03:49 Hi Rick At the moment I split the information with the Split Function and put the results into a listbox. I would like to use an array for this but was unable to find a suitable example. Can you offer help on an Array? Regards Ron "Rick Rothstein" wrote: > I'm still not totally clear where you are going with all this; however, I > think this might help you. The following code snippet assumes your list of > directories is stored in an array named FileNames, so change that as > necessary. The code loops through the FileNames array and splits out the > artist, title and file extension into three arrays named Artist, Title, and > Extension. These three arrays are coordinated by their index; so, for, say > the 4th item in the FileNames array (index value 3 if Option Base is set to > 0, otherwise index value 4 if Option Base is set to 1), which is this... > > F:\Stored Data\Library\Barry White\05 Just The Way You Are.wma > > then these are the contents of the arrays... > > Artist(4) ==> "Barry White" > Title(4) ==> "Just The Way You Are" > Extension(4) ==> "wma" > > So, you can just iterate the three arrays, examine the relevant array and > place the data according to your needs. By the way, I notice one of your > filename paths does not have an extension... the Extension array will > contain the empty string for it. Okay, here is the code... > > Dim X As Long, Position As Long, FileNames() As String, Parts() As String > Dim Artist() As String, Title() As String, Extension() As String > '.... > '.... > ReDim Artist(LBound(FileNames) To UBound(FileNames)) > ReDim Title(LBound(FileNames) To UBound(FileNames)) > ReDim Extension(LBound(FileNames) To UBound(FileNames)) > For X = LBound(FileNames) To UBound(FileNames) > Parts = Split(FileNames(X), "\") > Artist(X) = Parts(UBound(Parts) - 1) > Position = InStrRev(Parts(UBound(Parts)), ".") > If Position = 0 Then > Title(X) = Parts(UBound(Parts)) > Else > Title(X) = Left(Parts(UBound(Parts)), Position - 1) > If Title(X) Like "#*" Then > Title(X) = Trim(Split(Title(X), Val(Title(X)), 2)(1)) > End If > Extension(X) = Mid(Parts(UBound(Parts)), Position + 1) > End If > Next > '.... > '.... > > -- > Rick (MVP - Excel) > > > > "LondonLad" <LondonLad(a)discussions.microsoft.com> wrote in message > news:064CB269-AAE9-46DE-AB9B-2BA7D4A771B2(a)microsoft.com... > > Hi Rick > > A bit late to answer this been away for a few days, but here goes. > > This is the full path string that I need to extract data from:- > > > > 1. F:\Stored Data\Library\Danny Williams\03 Love is Kind.mp3 > > 2. F:\Stored Data\Library\Ken Follet\The Dangers of Time > > 3. F:\Stored Data\Library\Roger Moore&Tony Curtis\Five Miles to > > Midnight.avi > > 4. F:\Stored Data\Library\Barry White\05 Just The Way You Are.wma > > 5. F:\Stored Data\Library\Hols 07\Italian Lakes.wmv > > > > The first job is to split the Library Folder by File.extn with MP3 and wma > > going into the same New Folder then with the music I want just the Artists > > Name and the Title of the recording. Some recordings do not have a number > > in > > the Title Section. > > > > Regards > > > > Ron > > > > "Rick Rothstein" wrote: > > > >> Your original question was basically "how do I determine if there is a > >> digit > >> in my text"? Now, while I'm not 100% sure what the code snippet you > >> posted > >> should be doing, it does seem to hint at that you may have been asking > >> the > >> wrong question initially. I think you saw a path to your end result and > >> asked us about one step along the way, but I am thinking there is a > >> better > >> way to get to your ultimate goal. Can you do us a favor? Forget about the > >> ListBox and what you have split out and not split out... can you just > >> give > >> us maybe 4 or 5 samples of possible starting text (full path if that is > >> what > >> you have)(with and without numbers in whatever places numbers could > >> possibly > >> be located) and how you need each of them to look after being processed > >> by > >> the parsing part of your code? > >> > >> -- > >> Rick (MVP - Excel) > >> > >> > >> > >> "LondonLad" <LondonLad(a)discussions.microsoft.com> wrote in message > >> news:459AD240-D89F-47D1-9AC1-4EBA43121520(a)microsoft.com... > >> > Hi Rick > >> > After my post I found that it was possible to get a number in the file > >> > extn. > >> > which > >> > was picked up using the like example and I could not figure how to > >> > avoid > >> > this. > >> > Your code sample was the shortest way to find if numbers were included > >> > this > >> > is what I finished up with in my test project. > >> > I split the full string which includes folders and place the results in > >> > a > >> > ListBox > >> > > >> > txtA = LTrim(Mid(txtAns.List(2), 4)) > >> > xStr = Mid(txtAns.List(3), 4) > >> > strAns = Val(xStr) > >> > If strAns > 0 Then strNum = 7 Else strNum = 5 > >> > xStr = LTrim(Mid(txtAns.List(3), strNum)) > >> > xLen(2) = Len(xStr) > >> > txtB = Left(xStr, xLen(2) - 3) > >> > > >> > I am willing to change this if you can show me a better way. > >> > Thanks for your interest. > >> > > >> > Regards > >> > > >> > Ron > >> > > >> > "Rick Rothstein" wrote: > >> > > >> >> Just curious... what "other errors" do you think you would encounter > >> >> by > >> >> using the Like operator as proposed in my first posting? > >> >> > >> >> I'm also curious about the code you plan to use for your If..Then > >> >> test? > >> >> > >> >> -- > >> >> Rick (MVP - Excel) > >> >> > >> >> > >> >> "LondonLad" <LondonLad(a)discussions.microsoft.com> wrote in message > >> >> news:9DC2AFF9-E9BC-416A-B95F-A3ED27B01463(a)microsoft.com... > >> >> > Hi > >> >> > Thank you all for your posts. > >> >> > In the end I used Val as I felt that this gave less chance of other > >> >> > errors > >> >> > later. > >> >> > > >> >> > Regards > >> >> > > >> >> > Ron > >> >> > > >> >> > "Helmut Meukel" wrote: > >> >> > > >> >> >> "LondonLad" <LondonLad(a)discussions.microsoft.com> schrieb im > >> >> >> Newsbeitrag > >> >> >> news:B96BED25-0A88-4124-9E61-3B874330B57D(a)microsoft.com... > >> >> >> > Hi > >> >> >> > xStr can contain a string which includes numbers or not contain > >> >> >> > numbers > >> >> >> > > >> >> >> > if it contains numbers I want to edit it. > >> >> >> > > >> >> >> > In my example which does not work > >> >> >> > xStr = "03 Best of Time" > >> >> >> > > >> >> >> > If IsNumeric(xStr) Then txtHold.Text = "Yes" Else txtHold.Text = > >> >> >> > "No" > >> >> >> > > >> >> >> > Can you help please > >> >> >> > > >> >> >> > Ron > >> >> >> > >> >> >> > >> >> >> > >> >> >> Ron, > >> >> >> > >> >> >> depending on where the number(s) are, Val(xStr) may work. > >> >> >> > >> >> >> The ancient Val function returns a Double if the string starts with > >> >> >> a number. It stops conversion when it encounters a non-numerical > >> >> >> character. If the string starts with a non-numerical character it > >> >> >> will return 0. It's not localized, it recognizes only the dot as > >> >> >> decimal sign. > >> >> >> Spaces are totally ignored by Val. > >> >> >> > >> >> >> Here some examples: > >> >> >> Val("123 that's for me") will return 123 but > >> >> >> Val("1, 2, 3, that's for me") will return 1, because there is a > >> >> >> comma after the 1. > >> >> >> Val(".25 $") will return 0.25 > >> >> >> Val("$ 125") will return 0, because the string starts with a > >> >> >> non-numerical character > >> >> >> Val("5 6 7 8") will return 5678 > >> >> >> Val("- 12" will return -12 > >> >> >> > >> >> >> If you are certain about how your data looks like, > >> >> >> and you want speed, Val may be your choice. > >> >> >> > >> >> >> Helmut. > >> >> >> > >> >> >> > >> >> >> . > >> >> >> > >> >> . > >> >> > >> . > >> > . >
From: Rick Rothstein on 11 May 2010 04:13 Given that my code returns three coordinated arrays, I'm not entirely sure what your question is actually looking to do. I thought my posted code was an example. -- Rick (MVP - Excel) "LondonLad" <LondonLad(a)discussions.microsoft.com> wrote in message news:80107147-84DC-42FB-A8DC-D36F352BDABC(a)microsoft.com... > Hi Rick > At the moment I split the information with the Split Function and put the > results > into a listbox. I would like to use an array for this but was unable to > find > a suitable > example. > Can you offer help on an Array? > > Regards > > Ron > > "Rick Rothstein" wrote: > >> I'm still not totally clear where you are going with all this; however, I >> think this might help you. The following code snippet assumes your list >> of >> directories is stored in an array named FileNames, so change that as >> necessary. The code loops through the FileNames array and splits out the >> artist, title and file extension into three arrays named Artist, Title, >> and >> Extension. These three arrays are coordinated by their index; so, for, >> say >> the 4th item in the FileNames array (index value 3 if Option Base is set >> to >> 0, otherwise index value 4 if Option Base is set to 1), which is this... >> >> F:\Stored Data\Library\Barry White\05 Just The Way You Are.wma >> >> then these are the contents of the arrays... >> >> Artist(4) ==> "Barry White" >> Title(4) ==> "Just The Way You Are" >> Extension(4) ==> "wma" >> >> So, you can just iterate the three arrays, examine the relevant array and >> place the data according to your needs. By the way, I notice one of your >> filename paths does not have an extension... the Extension array will >> contain the empty string for it. Okay, here is the code... >> >> Dim X As Long, Position As Long, FileNames() As String, Parts() As String >> Dim Artist() As String, Title() As String, Extension() As String >> '.... >> '.... >> ReDim Artist(LBound(FileNames) To UBound(FileNames)) >> ReDim Title(LBound(FileNames) To UBound(FileNames)) >> ReDim Extension(LBound(FileNames) To UBound(FileNames)) >> For X = LBound(FileNames) To UBound(FileNames) >> Parts = Split(FileNames(X), "\") >> Artist(X) = Parts(UBound(Parts) - 1) >> Position = InStrRev(Parts(UBound(Parts)), ".") >> If Position = 0 Then >> Title(X) = Parts(UBound(Parts)) >> Else >> Title(X) = Left(Parts(UBound(Parts)), Position - 1) >> If Title(X) Like "#*" Then >> Title(X) = Trim(Split(Title(X), Val(Title(X)), 2)(1)) >> End If >> Extension(X) = Mid(Parts(UBound(Parts)), Position + 1) >> End If >> Next >> '.... >> '.... >> >> -- >> Rick (MVP - Excel) >> >> >> >> "LondonLad" <LondonLad(a)discussions.microsoft.com> wrote in message >> news:064CB269-AAE9-46DE-AB9B-2BA7D4A771B2(a)microsoft.com... >> > Hi Rick >> > A bit late to answer this been away for a few days, but here goes. >> > This is the full path string that I need to extract data from:- >> > >> > 1. F:\Stored Data\Library\Danny Williams\03 Love is Kind.mp3 >> > 2. F:\Stored Data\Library\Ken Follet\The Dangers of Time >> > 3. F:\Stored Data\Library\Roger Moore&Tony Curtis\Five Miles to >> > Midnight.avi >> > 4. F:\Stored Data\Library\Barry White\05 Just The Way You Are.wma >> > 5. F:\Stored Data\Library\Hols 07\Italian Lakes.wmv >> > >> > The first job is to split the Library Folder by File.extn with MP3 and >> > wma >> > going into the same New Folder then with the music I want just the >> > Artists >> > Name and the Title of the recording. Some recordings do not have a >> > number >> > in >> > the Title Section. >> > >> > Regards >> > >> > Ron >> > >> > "Rick Rothstein" wrote: >> > >> >> Your original question was basically "how do I determine if there is a >> >> digit >> >> in my text"? Now, while I'm not 100% sure what the code snippet you >> >> posted >> >> should be doing, it does seem to hint at that you may have been asking >> >> the >> >> wrong question initially. I think you saw a path to your end result >> >> and >> >> asked us about one step along the way, but I am thinking there is a >> >> better >> >> way to get to your ultimate goal. Can you do us a favor? Forget about >> >> the >> >> ListBox and what you have split out and not split out... can you just >> >> give >> >> us maybe 4 or 5 samples of possible starting text (full path if that >> >> is >> >> what >> >> you have)(with and without numbers in whatever places numbers could >> >> possibly >> >> be located) and how you need each of them to look after being >> >> processed >> >> by >> >> the parsing part of your code? >> >> >> >> -- >> >> Rick (MVP - Excel) >> >> >> >> >> >> >> >> "LondonLad" <LondonLad(a)discussions.microsoft.com> wrote in message >> >> news:459AD240-D89F-47D1-9AC1-4EBA43121520(a)microsoft.com... >> >> > Hi Rick >> >> > After my post I found that it was possible to get a number in the >> >> > file >> >> > extn. >> >> > which >> >> > was picked up using the like example and I could not figure how to >> >> > avoid >> >> > this. >> >> > Your code sample was the shortest way to find if numbers were >> >> > included >> >> > this >> >> > is what I finished up with in my test project. >> >> > I split the full string which includes folders and place the results >> >> > in >> >> > a >> >> > ListBox >> >> > >> >> > txtA = LTrim(Mid(txtAns.List(2), 4)) >> >> > xStr = Mid(txtAns.List(3), 4) >> >> > strAns = Val(xStr) >> >> > If strAns > 0 Then strNum = 7 Else strNum = 5 >> >> > xStr = LTrim(Mid(txtAns.List(3), strNum)) >> >> > xLen(2) = Len(xStr) >> >> > txtB = Left(xStr, xLen(2) - 3) >> >> > >> >> > I am willing to change this if you can show me a better way. >> >> > Thanks for your interest. >> >> > >> >> > Regards >> >> > >> >> > Ron >> >> > >> >> > "Rick Rothstein" wrote: >> >> > >> >> >> Just curious... what "other errors" do you think you would >> >> >> encounter >> >> >> by >> >> >> using the Like operator as proposed in my first posting? >> >> >> >> >> >> I'm also curious about the code you plan to use for your If..Then >> >> >> test? >> >> >> >> >> >> -- >> >> >> Rick (MVP - Excel) >> >> >> >> >> >> >> >> >> "LondonLad" <LondonLad(a)discussions.microsoft.com> wrote in message >> >> >> news:9DC2AFF9-E9BC-416A-B95F-A3ED27B01463(a)microsoft.com... >> >> >> > Hi >> >> >> > Thank you all for your posts. >> >> >> > In the end I used Val as I felt that this gave less chance of >> >> >> > other >> >> >> > errors >> >> >> > later. >> >> >> > >> >> >> > Regards >> >> >> > >> >> >> > Ron >> >> >> > >> >> >> > "Helmut Meukel" wrote: >> >> >> > >> >> >> >> "LondonLad" <LondonLad(a)discussions.microsoft.com> schrieb im >> >> >> >> Newsbeitrag >> >> >> >> news:B96BED25-0A88-4124-9E61-3B874330B57D(a)microsoft.com... >> >> >> >> > Hi >> >> >> >> > xStr can contain a string which includes numbers or not >> >> >> >> > contain >> >> >> >> > numbers >> >> >> >> > >> >> >> >> > if it contains numbers I want to edit it. >> >> >> >> > >> >> >> >> > In my example which does not work >> >> >> >> > xStr = "03 Best of Time" >> >> >> >> > >> >> >> >> > If IsNumeric(xStr) Then txtHold.Text = "Yes" Else txtHold.Text >> >> >> >> > = >> >> >> >> > "No" >> >> >> >> > >> >> >> >> > Can you help please >> >> >> >> > >> >> >> >> > Ron >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> Ron, >> >> >> >> >> >> >> >> depending on where the number(s) are, Val(xStr) may work. >> >> >> >> >> >> >> >> The ancient Val function returns a Double if the string starts >> >> >> >> with >> >> >> >> a number. It stops conversion when it encounters a non-numerical >> >> >> >> character. If the string starts with a non-numerical character >> >> >> >> it >> >> >> >> will return 0. It's not localized, it recognizes only the dot as >> >> >> >> decimal sign. >> >> >> >> Spaces are totally ignored by Val. >> >> >> >> >> >> >> >> Here some examples: >> >> >> >> Val("123 that's for me") will return 123 but >> >> >> >> Val("1, 2, 3, that's for me") will return 1, because there is a >> >> >> >> comma after the 1. >> >> >> >> Val(".25 $") will return 0.25 >> >> >> >> Val("$ 125") will return 0, because the string starts with a >> >> >> >> non-numerical character >> >> >> >> Val("5 6 7 8") will return 5678 >> >> >> >> Val("- 12" will return -12 >> >> >> >> >> >> >> >> If you are certain about how your data looks like, >> >> >> >> and you want speed, Val may be your choice. >> >> >> >> >> >> >> >> Helmut. >> >> >> >> >> >> >> >> >> >> >> >> . >> >> >> >> >> >> >> . >> >> >> >> >> . >> >> >> . >>
From: LondonLad on 11 May 2010 07:10 Hi Rick I took your code and added this line as below Private Sub Form_Load() Dim X As Long, Position As Long, FileNames() As String, Parts() As String Dim Artist() As String, Title() As String, Extension() As String FileNames() = "F:\Stored Data\Library\Barry White\05 Just The Way You Are.wma" ReDim Artist(LBound(FileNames) To UBound(FileNames)) ReDim Title(LBound(FileNames) To UBound(FileNames)) ReDim Extension(LBound(FileNames) To UBound(FileNames)) For X = LBound(FileNames) To UBound(FileNames) Parts = Split(FileNames(X), "\") Artist(X) = Parts(UBound(Parts) - 1) Position = InStrRev(Parts(UBound(Parts)), ".") If Position = 0 Then Title(X) = Parts(UBound(Parts)) Else Title(X) = Left(Parts(UBound(Parts)), Position - 1) If Title(X) Like "#*" Then Title(X) = Trim(Split(Title(X), Val(Title(X)), 2)(1)) End If Extension(X) = Mid(Parts(UBound(Parts)), Position + 1) End If Next End Sub But I get a Compile Error Can't assign To Array What have I done wrong please? Ron "Rick Rothstein" wrote: > Given that my code returns three coordinated arrays, I'm not entirely sure > what your question is actually looking to do. I thought my posted code was > an example. > > -- > Rick (MVP - Excel) > > > > "LondonLad" <LondonLad(a)discussions.microsoft.com> wrote in message > news:80107147-84DC-42FB-A8DC-D36F352BDABC(a)microsoft.com... > > Hi Rick > > At the moment I split the information with the Split Function and put the > > results > > into a listbox. I would like to use an array for this but was unable to > > find > > a suitable > > example. > > Can you offer help on an Array? > > > > Regards > > > > Ron > > > > "Rick Rothstein" wrote: > > > >> I'm still not totally clear where you are going with all this; however, I > >> think this might help you. The following code snippet assumes your list > >> of > >> directories is stored in an array named FileNames, so change that as > >> necessary. The code loops through the FileNames array and splits out the > >> artist, title and file extension into three arrays named Artist, Title, > >> and > >> Extension. These three arrays are coordinated by their index; so, for, > >> say > >> the 4th item in the FileNames array (index value 3 if Option Base is set > >> to > >> 0, otherwise index value 4 if Option Base is set to 1), which is this... > >> > >> F:\Stored Data\Library\Barry White\05 Just The Way You Are.wma > >> > >> then these are the contents of the arrays... > >> > >> Artist(4) ==> "Barry White" > >> Title(4) ==> "Just The Way You Are" > >> Extension(4) ==> "wma" > >> > >> So, you can just iterate the three arrays, examine the relevant array and > >> place the data according to your needs. By the way, I notice one of your > >> filename paths does not have an extension... the Extension array will > >> contain the empty string for it. Okay, here is the code... > >> > >> Dim X As Long, Position As Long, FileNames() As String, Parts() As String > >> Dim Artist() As String, Title() As String, Extension() As String > >> '.... > >> '.... > >> ReDim Artist(LBound(FileNames) To UBound(FileNames)) > >> ReDim Title(LBound(FileNames) To UBound(FileNames)) > >> ReDim Extension(LBound(FileNames) To UBound(FileNames)) > >> For X = LBound(FileNames) To UBound(FileNames) > >> Parts = Split(FileNames(X), "\") > >> Artist(X) = Parts(UBound(Parts) - 1) > >> Position = InStrRev(Parts(UBound(Parts)), ".") > >> If Position = 0 Then > >> Title(X) = Parts(UBound(Parts)) > >> Else > >> Title(X) = Left(Parts(UBound(Parts)), Position - 1) > >> If Title(X) Like "#*" Then > >> Title(X) = Trim(Split(Title(X), Val(Title(X)), 2)(1)) > >> End If > >> Extension(X) = Mid(Parts(UBound(Parts)), Position + 1) > >> End If > >> Next > >> '.... > >> '.... > >> > >> -- > >> Rick (MVP - Excel) > >> > >> > >> > >> "LondonLad" <LondonLad(a)discussions.microsoft.com> wrote in message > >> news:064CB269-AAE9-46DE-AB9B-2BA7D4A771B2(a)microsoft.com... > >> > Hi Rick > >> > A bit late to answer this been away for a few days, but here goes. > >> > This is the full path string that I need to extract data from:- > >> > > >> > 1. F:\Stored Data\Library\Danny Williams\03 Love is Kind.mp3 > >> > 2. F:\Stored Data\Library\Ken Follet\The Dangers of Time > >> > 3. F:\Stored Data\Library\Roger Moore&Tony Curtis\Five Miles to > >> > Midnight.avi > >> > 4. F:\Stored Data\Library\Barry White\05 Just The Way You Are.wma > >> > 5. F:\Stored Data\Library\Hols 07\Italian Lakes.wmv > >> > > >> > The first job is to split the Library Folder by File.extn with MP3 and > >> > wma > >> > going into the same New Folder then with the music I want just the > >> > Artists > >> > Name and the Title of the recording. Some recordings do not have a > >> > number > >> > in > >> > the Title Section. > >> > > >> > Regards > >> > > >> > Ron > >> > > >> > "Rick Rothstein" wrote: > >> > > >> >> Your original question was basically "how do I determine if there is a > >> >> digit > >> >> in my text"? Now, while I'm not 100% sure what the code snippet you > >> >> posted > >> >> should be doing, it does seem to hint at that you may have been asking > >> >> the > >> >> wrong question initially. I think you saw a path to your end result > >> >> and > >> >> asked us about one step along the way, but I am thinking there is a > >> >> better > >> >> way to get to your ultimate goal. Can you do us a favor? Forget about > >> >> the > >> >> ListBox and what you have split out and not split out... can you just > >> >> give > >> >> us maybe 4 or 5 samples of possible starting text (full path if that > >> >> is > >> >> what > >> >> you have)(with and without numbers in whatever places numbers could > >> >> possibly > >> >> be located) and how you need each of them to look after being > >> >> processed > >> >> by > >> >> the parsing part of your code? > >> >> > >> >> -- > >> >> Rick (MVP - Excel) > >> >> > >> >> > >> >> > >> >> "LondonLad" <LondonLad(a)discussions.microsoft.com> wrote in message > >> >> news:459AD240-D89F-47D1-9AC1-4EBA43121520(a)microsoft.com... > >> >> > Hi Rick > >> >> > After my post I found that it was possible to get a number in the > >> >> > file > >> >> > extn. > >> >> > which > >> >> > was picked up using the like example and I could not figure how to > >> >> > avoid > >> >> > this. > >> >> > Your code sample was the shortest way to find if numbers were > >> >> > included > >> >> > this > >> >> > is what I finished up with in my test project. > >> >> > I split the full string which includes folders and place the results > >> >> > in > >> >> > a > >> >> > ListBox > >> >> > > >> >> > txtA = LTrim(Mid(txtAns.List(2), 4)) > >> >> > xStr = Mid(txtAns.List(3), 4) > >> >> > strAns = Val(xStr) > >> >> > If strAns > 0 Then strNum = 7 Else strNum = 5 > >> >> > xStr = LTrim(Mid(txtAns.List(3), strNum)) > >> >> > xLen(2) = Len(xStr) > >> >> > txtB = Left(xStr, xLen(2) - 3) > >> >> > > >> >> > I am willing to change this if you can show me a better way. > >> >> > Thanks for your interest. > >> >> > > >> >> > Regards > >> >> > > >> >> > Ron > >> >> > > >> >> > "Rick Rothstein" wrote: > >> >> > > >> >> >> Just curious... what "other errors" do you think you would > >> >> >> encounter > >> >> >> by > >> >> >> using the Like operator as proposed in my first posting? > >> >> >> > >> >> >> I'm also curious about the code you plan to use for your If..Then > >> >> >> test? > >> >> >> > >> >> >> -- > >> >> >> Rick (MVP - Excel) > >> >> >> > >> >> >> > >> >> >> "LondonLad" <LondonLad(a)discussions.microsoft.com> wrote in message > >> >> >> news:9DC2AFF9-E9BC-416A-B95F-A3ED27B01463(a)microsoft.com... > >> >> >> > Hi > >> >> >> > Thank you all for your posts. > >> >> >> > In the end I used Val as I felt that this gave less chance of > >> >> >> > other > >> >> >> > errors > >> >> >> > later. > >> >> >> > > >> >> >> > Regards > >> >> >> > > >> >> >> > Ron > >> >> >> > > >> >> >> > "Helmut Meukel" wrote: > >> >> >> > > >> >> >> >> "LondonLad" <LondonLad(a)discussions.microsoft.com> schrieb im > >> >> >> >> Newsbeitrag > >> >> >> >> news:B96BED25-0A88-4124-9E61-3B874330B57D(a)microsoft.com... > >> >> >> >> > Hi > >> >> >> >> > xStr can contain a string which includes numbers or not > >> >> >> >> > contain > >> >> >> >> > numbers > >> >> >> >> > > >> >> >> >> > if it contains numbers I want to edit it. > >> >> >> >> > > >> >> >> >> > In my example which does not work > >> >> >> >> > xStr = "03 Best of Time" > >> >> >> >> > > >> >> >> >> > If IsNumeric(xStr) Then txtHold.Text = "Yes" Else txtHold.Text > >> >> >> >> > = > >> >> >> >> > "No" > >> >> >> >> > > >> >> >> >> > Can you help please > >> >> >> >> > > >> >> >> >> > Ron > >> >> >> >> > >> >> >> >> > >> >> >> >> > >> >> >> >> Ron, > >> >> >> >> > >> >> >> >> depending on where the number(s) are, Val(xStr) may work. > >> >> >> >> > >> >> >> >> The ancient Val function returns a Double if the string starts > >> >> >> >> with > >> >> >> >> a number. It stops conversion when it encounters a non-numerical > >> >> >> >> character. If the string starts with a non-numerical character > >> >> >> >> it > >> >> >> >> will return 0. It's not localized, it recognizes only the dot as > >> >> >> >> decimal sign. > >> >> >> >> Spaces are totally ignored by Val. > >> >> >> >> > >> >> >> >> Here some examples: > >> >> >> >> Val("123 that's for me") will return 123 but > >> >> >> >> Val("1, 2, 3, that's for me") will return 1, because there is a > >> >> >> >> comma after the 1. > >> >> >> >> Val(".25 $") will return 0.25 > >> >> >> >> Val("$ 125") will return 0, because the string starts with a > >> >> >> >> non-numerical character > >> >> >> >> Val("5 6 7 8") will return 5678 > >> >> >> >> Val("- 12" will return -12 > >> >> >> >> > >> >> >> >> If you are certain about how your data looks like, > >> >> >> >> and you want speed, Val may be your choice. > >> >> >> >> > >> >> >> >> Helmut. > >> >> >> >> > >> >> >> >> > >> >> >> >> . > >> >> >> >> > >> >> >> . > >> >> >> > >> >> . > >> >> > >> . > >> > . >
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 4 Prev: It was a good ride - will miss y'all! Next: data disapear |