| Subject |
Re: manipulating a string |
| From |
Charlie <tm@tc.com> |
| Date |
Wed, 23 Mar 2022 18:08:38 -0400 |
| Newsgroups |
dbase.getting-started |
Hi Mervyn
Think I am missing something. I copied the code below (both the program and function together in one program). I changed the folder also. But nothing really happens when I try to run it.... This is regarding the jpg folder. The other script works well.
Mervyn Bick Wrote:
> On 2022/03/21 23:33, Charlie wrote:
> > Hi Mervyn.... Thanks very much. I got this though... Error: OLE Dispatch Exception.
> >
> > It is referring to line 14 which is cNew = a.item(0).submatches.item(0)
> >
> > All fields have a length of 10 but they have an actual length that varies between 6 and 10. Most are less than 10. I am not sure if that is the reason for the error.
> >
> > To further complicate I have a directory full of images which are named the same as each sku + .jpg. Those names have to be changed at the same time as the sku so possibly a loop would work better to do both at the same time?
> >
>
>
> This may be due to the sku not having any leading characters. Try this
> revised version of the function in update_sku.prg which is attached.
> This tests to see if the string passed to it is valid.
>
>
> I have removed the XDML code to update your table so you will need to
> create a separate little program to execute the function.
>
>
> use yourtablename
> replace all yourfieldname with update_sku(yourfieldname)
> use
>
>
> To rename your .jpg files edit the folder name in the attached program
> update_sku_jpg.prg
>
> The revised function will ONLY change character(s)+4digits+character(s)
> to character(s)+0+4digits+character(s). If there are no leading or
> trailing character(s) or if there aren't 4 digits the string is passed
> back unchanged.
>
> The code has been tested but you still need to make sure you have
> backups of the original table and images before you run the programs.
>
> Mervyn.
>
>
>
>
>
>
>
> function update_sku(cString)
> oRegExp = new OleAutoClient("VBScript.RegExp")
> oRegExp.global := true
> oRegExp.ignoreCase := true
> oRegExp.Pattern := "(\D+)(\d{4})(\D+)"
> a = oRegExp.execute( cString )
> if oRegExp.test(cString)
> cNew = a.item(0).submatches.item(0)
> cNew+='0'
> cNew+= a.item(0).submatches.item(1)
> cNew+= a.item(0).submatches.item(2)
> else
> cNew = cString
> endif
> return cNew
> clear
> cFolder = 'D:\examples\jpgs\' //Include final \
> aFiles = new Array()
> nFiles = aFiles.dir(cFolder+'*.jpg')
> f = new file()
> for nFile = 1 to nFiles
> if cFolder+aFiles[ nFile,1] # update_sku(cFolder+aFiles[nFile,1])
> ? 'Changed '+cFolder+aFiles[ nFile,1],' to ',update_sku(cFolder+aFiles[nFile,1])
> f.rename(cFolder+aFiles[ nFile,1],update_sku(cFolder+aFiles[nFile,1]))
> endif
> next
|
|