|
|
|
date: Wed, 14 Nov 2007 13:12:05 -0800,
group: microsoft.public.access.modulesdaovba.ado
back
Using InStr Function to Parce a string
In inStr function and using it has always caused me a headache.
I did the following to get the [personName] from the datafile path. I would
like to know if there was an easier way to accomplish the same.
------------------------------------------------------------
'Get the Person name from the file path
'example C:\ProjectName_ContractCode_\DatabaseName_PersonName.mdb
Dim CPos, LastPos, DPos, UPos, nameLength As Integer
'Get the position of the .dot
DPos = InStr(strPath, ".")
'There are several underscores in the path
'I know the name comes after the last underscore
'Get the position of the last underscore
CPos = InStr(strPath, "_")
Do While CPos > 0
LastPos = CPos
CPos = InStr(CPos + 1, strPath, "_")
Loop
'the length of the name is the distance between the last underscore and the
dot
nameLength = DPos - LastPos - 1
strName = Right$(strPath, (nameLength + 4))
strName = Left$(strName, nameLength)
date: Wed, 14 Nov 2007 13:12:05 -0800
author: Lisab
Re: Using InStr Function to Parce a string
Perhaps this will be easier, based on the example that has underscore before
person's name:
Left(Mid(strPath, InStrRev(strPath, "_") + 1), Len(Mid(strPath,
InStrRev(strPath, "_") + 1)) - 4)
--
Ken Snell
<MS ACCESS MVP>
"Lisab" wrote in message
news:1BEFE0C9-964A-4CEC-8744-03C1CCC19494@microsoft.com...
> In inStr function and using it has always caused me a headache.
>
> I did the following to get the [personName] from the datafile path. I
> would
> like to know if there was an easier way to accomplish the same.
> ------------------------------------------------------------
> 'Get the Person name from the file path
> 'example C:\ProjectName_ContractCode_\DatabaseName_PersonName.mdb
>
> Dim CPos, LastPos, DPos, UPos, nameLength As Integer
>
> 'Get the position of the .dot
> DPos = InStr(strPath, ".")
>
> 'There are several underscores in the path
> 'I know the name comes after the last underscore
> 'Get the position of the last underscore
> CPos = InStr(strPath, "_")
> Do While CPos > 0
> LastPos = CPos
> CPos = InStr(CPos + 1, strPath, "_")
>
> Loop
>
> 'the length of the name is the distance between the last underscore and
> the
> dot
> nameLength = DPos - LastPos - 1
>
> strName = Right$(strPath, (nameLength + 4))
> strName = Left$(strName, nameLength)
date: Wed, 14 Nov 2007 16:24:23 -0500
author: Ken Snell \(MVP\) etl
Re: Using InStr Function to Parce a string
THANKS.
OMG, I have to be fresh and headach free in order to deal with mixing the
Left,Right, Mid, & InStr functions :)
InStrRev --> that a new one I didn't know about
Thanks again.
"Ken Snell (MVP)" wrote:
> Perhaps this will be easier, based on the example that has underscore before
> person's name:
>
> Left(Mid(strPath, InStrRev(strPath, "_") + 1), Len(Mid(strPath,
> InStrRev(strPath, "_") + 1)) - 4)
>
> --
>
> Ken Snell
> <MS ACCESS MVP>
>
>
>
> "Lisab" wrote in message
> news:1BEFE0C9-964A-4CEC-8744-03C1CCC19494@microsoft.com...
> > In inStr function and using it has always caused me a headache.
> >
> > I did the following to get the [personName] from the datafile path. I
> > would
> > like to know if there was an easier way to accomplish the same.
> > ------------------------------------------------------------
> > 'Get the Person name from the file path
> > 'example C:\ProjectName_ContractCode_\DatabaseName_PersonName.mdb
> >
> > Dim CPos, LastPos, DPos, UPos, nameLength As Integer
> >
> > 'Get the position of the .dot
> > DPos = InStr(strPath, ".")
> >
> > 'There are several underscores in the path
> > 'I know the name comes after the last underscore
> > 'Get the position of the last underscore
> > CPos = InStr(strPath, "_")
> > Do While CPos > 0
> > LastPos = CPos
> > CPos = InStr(CPos + 1, strPath, "_")
> >
> > Loop
> >
> > 'the length of the name is the distance between the last underscore and
> > the
> > dot
> > nameLength = DPos - LastPos - 1
> >
> > strName = Right$(strPath, (nameLength + 4))
> > strName = Left$(strName, nameLength)
>
>
>
date: Wed, 14 Nov 2007 15:46:22 -0800
author: Lisab
|
|