|
-
Mar 13th, 2005, 01:41 AM
#1
Thread Starter
Lively Member
Split text with length
Hi,
I have a textbox with multiline for the address such as:
18-G, Kuala Kangsar Road, 65890 Ipoh, Perak
I split it with "," so that each line can be saved to the add1, add2, add3, add4, add5, etc...respectively.
The result is:
18-G
Kuala Kangsar Road
65890 Ipoh
Perak
But I would like to split it with the fixed length, like:
18-G, Kuala Kangsar Road,
65890 Ipoh,
Perak
Please help in the VB6 coding. Hope my question is clear to you, thanks in advance.
Viv
-
Mar 13th, 2005, 01:45 AM
#2
Re: Split text with length
No it isn't really
Can you show us exactly what your input is and what you want the output to be?
-
Mar 13th, 2005, 02:03 AM
#3
Thread Starter
Lively Member
Re: Split text with length
it is a texbox with multilines setting for user to key in the address.
I would like to split the address in the format like:
18-G, Kuala Kangsar Road,
65890 Ipoh,
Perak
and saved each line of the address to different field such as: add1, add2 and add3....
thanks
-
Mar 13th, 2005, 02:06 AM
#4
Re: Split text with length
So each line goes into a different variable.
What result do you want?
-
Mar 13th, 2005, 02:21 AM
#5
Thread Starter
Lively Member
Re: Split text with length
i want to save each line to the different variable in the database.
so that it can be used for the report. I would like to display the address in seperated line and not a whole one line.
-
Mar 13th, 2005, 02:38 AM
#6
Re: Split text with length
You want to access the database from VB? In that case, I can't help you, sorry.
Which bit of the coding do you need help with?
-
Mar 13th, 2005, 09:26 AM
#7
Re: Split text with length
Is this what you want?
VB Code:
Dim intPos As Integer
Dim strTest As String
Dim strAddress As String
strAddress = "18-G, Kuala Kangsar Road, 65890 Ipoh, Perak"
Do Until Len(strAddress) < 31
strTest = Left$(strAddress, 30)
intPos = InStrRev(strTest, ",")
Debug.Print Left$(strAddress, intPos)
strAddress = Right$(strAddress, Len(strAddress) - intPos)
' get rid of the leading space
If Left$(strAddress, 1) = " " Then
strAddress = Right$(strAddress, Len(strAddress) - 1)
End If
Loop
' Show the last part
Debug.Print strAddress
-
Mar 13th, 2005, 09:38 AM
#8
Lively Member
Re: Split text with length
Just to point out, though - if a line is longer than 30 characters, it will go into an unending loop.
-
Mar 13th, 2005, 10:18 AM
#9
Re: Split text with length
OK, here is a fix.
VB Code:
Dim intPos As Integer
Dim strTest As String
Dim strAddress As String
strAddress = "18-G, Kuala Kangsar Road, 65890 Ipoh, Perak ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"
Do Until Len(strAddress) < 31
strTest = Left$(strAddress, 30)
intPos = InStrRev(strTest, ",")
If intPos = 0 Then
'no comma so look for a space instead
intPos = InStrRev(strTest, " ")
End If
If intPos = 0 Then
' no space either so just artificially break it
intPos = 30
End If
Debug.Print Left$(strAddress, intPos)
strAddress = Right$(strAddress, Len(strAddress) - intPos)
' get rid of the leading space
If Left$(strAddress, 1) = " " Then
strAddress = Right$(strAddress, Len(strAddress) - 1)
End If
Loop
' Show the last part
Debug.Print strAddress
-
Mar 13th, 2005, 10:51 AM
#10
Re: Split text with length
There should be no comma delimiter between a house (or lot#) and the street name.
Are the users in your locale used to entering: 123, MAIN STREET??
Is that comma needed?
-
Mar 13th, 2005, 11:54 AM
#11
Thread Starter
Lively Member
Re: Split text with length
yes, the user used to put delimiter between a house (or lot#) and the street name.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|