Home > Archive > Visual Basic > May 2004 > Parsing the string, declaring the string by reference
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 |
Parsing the string, declaring the string by reference
|
|
| Oleg Shnayder 2004-05-28, 3:30 pm |
|
Hi All,
I am kind of new to Visual Basic and I have a generic question.
I have a string with full addresses [I don't know how many addresses
will be in the string, min = 2, max = 15]
Dim nMap As String
for example we have 3 addresses
nMap = "2054 Treat Blvd., Walnut Cr , Ca 94598#1181 Locust St., Walnut
Cr , Ca 94596#2991 N. Main St., Walnut Cr , CA 94596" ' here is the
string to split
Each address separated by '#'
now I called function to split the string and save each address into
separate string.
Call ParseTheString(nMap)
***** Defenition of the function
Function ParseTheString(ByVal SomeStr As String) As String
Dim strArray() As String
Dim StrLen As Integer
StrLen = Len(nMap)
strArray() = Split(nMap, "#")
' so I got an array with elements strArray(0), strArray(1) and
strArray(2)
'what I want to do is to save each member(index) of the
'array into the string passed by reference
'for example strArray(0) will be saved into TempStr0,
'strArray(1) will be saved into TempStr1,
' and etc.
' I want to declare AddrStr passed by reference so it will
' hold the value of TempStr0, TempStr1, etc.
ByRef AddrStr As String
Dim TempStr As String
Dim index As Integer
For index = 0 To UBound(strArray())
AddrStr = TempStr & Cstr(index)
' so AddrStr is refered now to TempStr0
&AddrStr = strArray(index)
Next index
' now I just need to return each string TempStr0,
' TempStr1, etc
End Function
Could somebody please let me know how can I do this.
If my logic is wrong (of course this is possible), could you please
direct me to the right path.
Thank you in advance.
Oleg
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
| |
| Bob O`Bob 2004-05-28, 4:30 pm |
| Oleg Shnayder wrote:
>
> Hi All,
>
> I am kind of new to Visual Basic and I have a generic question.
> I have a string with full addresses [I don't know how many addresses
> will be in the string, min = 2, max = 15]
> Dim nMap As String
> for example we have 3 addresses
> nMap = "2054 Treat Blvd., Walnut Cr , Ca 94598#1181 Locust St., Walnut
> Cr , Ca 94596#2991 N. Main St., Walnut Cr , CA 94596" ' here is the
> string to split
> Each address separated by '#'
> now I called function to split the string and save each address into
> separate string.
> Call ParseTheString(nMap)
> ***** Defenition of the function
> Function ParseTheString(ByVal SomeStr As String) As String
> Dim strArray() As String
> Dim StrLen As Integer
> StrLen = Len(nMap)
> strArray() = Split(nMap, "#")
> ' so I got an array with elements strArray(0), strArray(1) and
> strArray(2)
> 'what I want to do is to save each member(index) of the
> 'array into the string passed by reference
> 'for example strArray(0) will be saved into TempStr0,
> 'strArray(1) will be saved into TempStr1,
> ' and etc.
> ' I want to declare AddrStr passed by reference so it will
> ' hold the value of TempStr0, TempStr1, etc.
> ByRef AddrStr As String
> Dim TempStr As String
> Dim index As Integer
> For index = 0 To UBound(strArray())
> AddrStr = TempStr & Cstr(index)
> ' so AddrStr is refered now to TempStr0
> &AddrStr = strArray(index)
> Next index
> ' now I just need to return each string TempStr0,
> ' TempStr1, etc
> End Function
>
> Could somebody please let me know how can I do this.
> If my logic is wrong (of course this is possible), could you please
> direct me to the right path.
What you're s ing does not appear to me to make any sense.
Also you simply can not manipulate variable names like that.
Return the array AS an array. You're basically done already.
Also, I have to warn you that's an *extremely* poor choice of delimiter
character for separating addresses. You need to pick a character which
does NOT routinely occur in addresses, and # certainly fails that test.
Bob
| |
| Unforgiven 2004-05-28, 5:30 pm |
| Oleg Shnayder wrote:
: Hi All,
:
: I am kind of new to Visual Basic and I have a generic question.
: I have a string with full addresses [I don't know how many addresses
: will be in the string, min = 2, max = 15]
: Dim nMap As String
: for example we have 3 addresses
: nMap = "2054 Treat Blvd., Walnut Cr , Ca 94598#1181 Locust St.,
: Walnut Cr , Ca 94596#2991 N. Main St., Walnut Cr , CA 94596" '
: here is the string to split
: Each address separated by '#'
: now I called function to split the string and save each address into
: separate string.
: Call ParseTheString(nMap)
: ***** Defenition of the function
: Function ParseTheString(ByVal SomeStr As String) As String
: Dim strArray() As String
: Dim StrLen As Integer
: StrLen = Len(nMap)
: strArray() = Split(nMap, "#")
: ' so I got an array with elements strArray(0), strArray(1) and
: strArray(2)
: 'what I want to do is to save each member(index) of the
: 'array into the string passed by reference
: 'for example strArray(0) will be saved into TempStr0,
: 'strArray(1) will be saved into TempStr1,
: ' and etc.
: ' I want to declare AddrStr passed by reference so it will
: ' hold the value of TempStr0, TempStr1, etc.
: ByRef AddrStr As String
: Dim TempStr As String
: Dim index As Integer
: For index = 0 To UBound(strArray())
: AddrStr = TempStr & Cstr(index)
: ' so AddrStr is refered now to TempStr0
: &AddrStr = strArray(index)
: Next index
: ' now I just need to return each string TempStr0,
: ' TempStr1, etc
: End Function
:
: Could somebody please let me know how can I do this.
: If my logic is wrong (of course this is possible), could you please
: direct me to the right path.
: Thank you in advance.
:
: Oleg
:
:
: *** Sent via Developersdex http://www.developersdex.com ***
: Don't just participate in USENET...get rewarded for it!
Why not just do this?
Option Explicit
Dim strArray() As String ' This gets declared here so it has module level
scope
Public Sub ParseTheString()
Dim index As Integer
Dim nMap As String
nMap = "2054 Treat Blvd., Walnut Cr , Ca 94598#"
nMap = nMap & "1181 Locust St., Walnut Cr , Ca 94596#"
nMap = nMap & "2991 N. Main St., Walnut Cr , CA 94596"
strArray() = Split(nMap, "#")
' Press Ctrl-G to see the output
For index = LBound(strArray()) To UBound(strArray())
Debug.Print "This is address #" & index + 1 & " " & strArray(index)
Next index
End Sub
| |
| Gale Green 2004-05-28, 5:30 pm |
| On Fri, 28 May 2004 12:46:06 -0700, Bob O`Bob
<filterbob@yahoogroups.com> wrote:
>Also, I have to warn you that's an *extremely* poor choice of delimiter
>character for separating addresses. You need to pick a character which
>does NOT routinely occur in addresses, and # certainly fails that test.
Depends on the home country, and the scope of the application.
"#" is not a problem in the UK for example. It appears on telephone
keypads but never (well, not to my knowledge) in a street address.
Gale.
| |
|
| you mean there isn't any chances that, one day, a user enters something like
the following in an address field in all UK? <g>
"2840, app. #108, Bouchard st."
--
Best Regards
Yanick Lefebvre
"Gale Green" <gale@databeat.fsnet.co.uk> a écrit dans le message de
news:gj8fb01lo5hap21mps9sj7r5cf0436g46s@
4ax.com...
> On Fri, 28 May 2004 12:46:06 -0700, Bob O`Bob
> <filterbob@yahoogroups.com> wrote:
>
>
> Depends on the home country, and the scope of the application.
>
> "#" is not a problem in the UK for example. It appears on telephone
> keypads but never (well, not to my knowledge) in a street address.
>
> Gale.
>
| |
| Gale Green 2004-05-28, 6:30 pm |
| On Fri, 28 May 2004 16:47:34 -0400, "Zoury"
<yanick_lefebvre@hotmail.com> wrote:
>you mean there isn't any chances that, one day, a user enters something like
>the following in an address field in all UK? <g>
>"2840, app. #108, Bouchard st."
Of course there is a chance. I wouldn't use any displayable or
printable character as a delimiter.
I was merely pointing out (perhaps badly) that what counts in one
country doesn't necessarily matter in another country. If you're only
talking to UK people about UK addresses then, no, you will never see
"#" in a street address.
However, if you use any typable character as a delimiter then you are
looking for problems.
Gale.
| |
| Oleg Shnayder 2004-05-28, 6:30 pm |
|
Dim index As Integer
For index = LBound(strArray()) To UBound(strArray())
Debug.Print "This is address #" & index + 1 & " " &
strArray(index)
Next index
This is good, but unfortunatelly not good for me, the strings which I am
trying to get are going to be used in next Sub to determine the Map
Location.
something like that...
ActRoute.Waypoints.Add ActMap.FindResults(StrAddr_0).Item(1)
ActRoute.Waypoints.Add ActMap.FindResults(StrAddr_1).Item(1)
ActRoute.Waypoints.Add ActMap.FindResults(strAddr_2).Item(1)
and so on, as many addresses as it will be passed for directions (min =
2, max = as many as you want)
So, that where I am having a trouble, after
the string will be parsed, I need to return the parsing result to
Mapping Sub, where each string will have a new address.
Any guesses how to do it?
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
| |
| Randy Birch 2004-05-28, 7:30 pm |
| Still seems straightforward. Instead of passing "StrAddr_0", pass the array
member itself, ie :
ActRoute.Waypoints.Add ActMap.FindResults(strArray(0)).Item(1)
ActRoute.Waypoints.Add ActMap.FindResults(strArray(1)).Item(1)
ActRoute.Waypoints.Add ActMap.FindResults(strArray(2)).Item(1)
The nice thing about this is you now have a dynamic method of doing this ...
For index = LBound(strArray()) To UBound(strArray())
ActRoute.Waypoints.Add ActMap.FindResults(strArray(index)).Item(1)
Next
If there are 2 members in the array, the line gets called twice. If there
are 15 it's called 15 times.
--
Randy Birch
MVP Visual Basic
http://vbnet.mvps.org/
Please respond only to the newsgroups so all can benefit.
"Oleg Shnayder" <bind8@yahoo.com> wrote in message
news:#$j7ZfPREHA.3988@tk2msftngp13.phx.gbl...
:
: Dim index As Integer
: For index = LBound(strArray()) To UBound(strArray())
: Debug.Print "This is address #" & index + 1 & " " &
: strArray(index)
: Next index
:
: This is good, but unfortunatelly not good for me, the strings which I am
: trying to get are going to be used in next Sub to determine the Map
: Location.
: something like that...
:
: ActRoute.Waypoints.Add ActMap.FindResults(StrAddr_0).Item(1)
: ActRoute.Waypoints.Add ActMap.FindResults(StrAddr_1).Item(1)
: ActRoute.Waypoints.Add ActMap.FindResults(strAddr_2).Item(1)
:
: and so on, as many addresses as it will be passed for directions (min =
: 2, max = as many as you want)
: So, that where I am having a trouble, after
: the string will be parsed, I need to return the parsing result to
: Mapping Sub, where each string will have a new address.
: Any guesses how to do it?
:
: *** Sent via Developersdex http://www.developersdex.com ***
: Don't just participate in USENET...get rewarded for it!
| |
| Rick Rothstein 2004-05-28, 10:30 pm |
| > I was merely pointing out (perhaps badly) that what counts in one
> country doesn't necessarily matter in another country. If you're only
> talking to UK people about UK addresses then, no, you will never see
> "#" in a street address.
Except that the OP specifically gave US addresses in his examples.
Rick - MVP
| |
| Oleg Shnayder 2004-05-30, 6:30 pm |
|
Randy,
Thank you!
That was the simpliest and most effective (in my case) solution. I feel
guilty that I could not come up with it myself :)
Oleg
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
|
|
|
|
|