|
|
#1 |
|
Lively Member
Join Date: Feb 05
Posts: 81
![]() |
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
|
|
|
|
|
|
#2 |
|
Super Moderator
Join Date: Jan 05
Location: Sunny Adelaide
Posts: 12,532
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
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? |
|
|
|
|
|
#3 |
|
Lively Member
Join Date: Feb 05
Posts: 81
![]() |
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 |
|
|
|
|
|
#4 |
|
Super Moderator
Join Date: Jan 05
Location: Sunny Adelaide
Posts: 12,532
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: Split text with length
So each line goes into a different variable.
What result do you want? |
|
|
|
|
|
#5 |
|
Lively Member
Join Date: Feb 05
Posts: 81
![]() |
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. |
|
|
|
|
|
#6 |
|
Super Moderator
Join Date: Jan 05
Location: Sunny Adelaide
Posts: 12,532
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
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? |
|
|
|
|
|
#7 |
|
Lively Member
Join Date: Feb 05
Posts: 116
![]() |
Re: Split text with length
Your description of the problem is a little vague, but the following code should get you started.
You need to change "yourdatabase.mdb" to the name of your database. Inside the database, create a table with 6 fields - idnum as an autonumbered primary key and 5 fields named add1, add2, add3, add4 and add5. You need to create a form with a textbox called txtAddress and a commandbutton called cmdSave, then add a reference to the Microsoft ADO 2.x Library. VB Code:
I would recommend looking at some tutorials if you have never worked with databases before through VB. eg. http://www.developerkb.com/modules/w...hp?category=23 |
|
|
|
|
|
#8 |
|
Lively Member
Join Date: Feb 05
Posts: 81
![]() |
Re: Split text with length
Thank you for the coding.
I would like to split the text at "," , For example: 265, Kuala Kangsar Road, 65000 Ipoh. The result will be: 265 Kuala Kangsar Road 65000 Ipoh I would like to split the text at "," but with the fixed length (30). The result I would like to have is: 265, Kuala Kangsar Road 65000 Ipoh Please help
|
|
|
|
|
|
#9 |
|
Lively Member
Join Date: Feb 05
Posts: 116
![]() |
Re: Split text with length
That's more difficult to do - why not have separate text boxes for each line of the address? You'd find it a lot easier to code.
|
|
|
|
|
|
#10 |
|
Re: Split text with length
Is this what you want?
VB Code:
__________________
Tips, Examples & Tutorials: A valuable forum tool • Generate unique TreeView keys • TreeView with "open" and "closed folder" icons • Time code using GetTickCount • How to trap the Tab key • Scroll a form • NumberBox ActiveX control • Color a ListView row • An InputBox form • How to use SaveSetting and GetSetting • A program registration scheme • Spellcheck a Textbox • Resize controls • Open Windows Explorer at Last Visited Path • A Blackjack Game • Count lines of code • Private Message Viewer • Copy/Paste VB Code • Paste VB Code Add-In • Insert Procedure Names Add-In • A calculator for the game of Spider • My review of REALbasic 2008 • VB6 Debug Tutorial • Picture Viewer • VBF Photo Contest Winners Please go to the Thread Tools menu and click Mark Thread Resolved when you have your answer. If someone helped you today then please consider rating their post. |
|
|
|
|
|
|
#11 |
|
Lively Member
Join Date: Feb 05
Posts: 116
![]() |
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.
|
|
|
|
|
|
#12 |
|
Re: Split text with length
OK, here is a fix.
VB Code:
__________________
Tips, Examples & Tutorials: A valuable forum tool • Generate unique TreeView keys • TreeView with "open" and "closed folder" icons • Time code using GetTickCount • How to trap the Tab key • Scroll a form • NumberBox ActiveX control • Color a ListView row • An InputBox form • How to use SaveSetting and GetSetting • A program registration scheme • Spellcheck a Textbox • Resize controls • Open Windows Explorer at Last Visited Path • A Blackjack Game • Count lines of code • Private Message Viewer • Copy/Paste VB Code • Paste VB Code Add-In • Insert Procedure Names Add-In • A calculator for the game of Spider • My review of REALbasic 2008 • VB6 Debug Tutorial • Picture Viewer • VBF Photo Contest Winners Please go to the Thread Tools menu and click Mark Thread Resolved when you have your answer. If someone helped you today then please consider rating their post. |
|
|
|
|
|
|
#13 |
|
MS SQL Powerposter
Join Date: Mar 04
Location: CT
Posts: 12,269
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
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?
__________________
*** Read the sticky in the DB forum about how to get your question answered quickly!! *** Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post". Some Informative Links: [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ] [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ VB.Net Database Class ] [ Loading Pictures from DB ] MS MVP 2006, 2007, 2008 |
|
|
|
|
|
#14 |
|
Lively Member
Join Date: Feb 05
Posts: 81
![]() |
Re: Split text with length
yes, the user used to put delimiter between a house (or lot#) and the street name.
|
|
|
|
|
|
#15 |
|
Re: Split text with length
Is my code anything like what you want?
__________________
Tips, Examples & Tutorials: A valuable forum tool • Generate unique TreeView keys • TreeView with "open" and "closed folder" icons • Time code using GetTickCount • How to trap the Tab key • Scroll a form • NumberBox ActiveX control • Color a ListView row • An InputBox form • How to use SaveSetting and GetSetting • A program registration scheme • Spellcheck a Textbox • Resize controls • Open Windows Explorer at Last Visited Path • A Blackjack Game • Count lines of code • Private Message Viewer • Copy/Paste VB Code • Paste VB Code Add-In • Insert Procedure Names Add-In • A calculator for the game of Spider • My review of REALbasic 2008 • VB6 Debug Tutorial • Picture Viewer • VBF Photo Contest Winners Please go to the Thread Tools menu and click Mark Thread Resolved when you have your answer. If someone helped you today then please consider rating their post. |
|
|
|
|
|
|
#16 |
|
Lively Member
Join Date: Feb 05
Posts: 81
![]() |
Re: Split text with length
Thank you. I need to try it out first. Heres are my coding, since i dont know how to fixed the length, i make it in other way. It might not in the good standard but it works. I will try yours too.
Dim strLineArr() As String Dim strWordArr() As String Dim intLineIdx As Integer, intWordIdx As Integer strLineArr() = Split(txtAddress.Text, vbCrLf) For intLineIdx = 0 To UBound(strLineArr) strWordArr() = Split(strLineArr(intLineIdx), ",") If Len(strWordArr(0)) < 5 Then rs_add(1) = strWordArr(0) & "," & "" & strWordArr(1) & "," For intWordIdx = 2 To UBound(strWordArr) rs_add(intWordIdx) = strWordArr(intWordIdx) & "," Next Else For intWordIdx = 0 To UBound(strWordArr) rs_add(intWordIdx) = strWordArr(intWordIdx) & "," Next End If Next |
|
|
|
|
|
#17 | |
|
MS SQL Powerposter
Join Date: Mar 04
Location: CT
Posts: 12,269
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: Split text with length
Quote:
Do you always have a house/lot# in your data entry - or can there be a street name by itself?
__________________
*** Read the sticky in the DB forum about how to get your question answered quickly!! *** Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post". Some Informative Links: [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ] [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ VB.Net Database Class ] [ Loading Pictures from DB ] MS MVP 2006, 2007, 2008 |
|
|
|
|
![]() |
|
||||||
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|