Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String - Visual Basic 6.0

Status
Not open for further replies.

Danielvb

Programmer
Oct 8, 2002
34
US
Hello Gurus: Marry Christmas to all!!

Please I need help.
-- I have a record thas has comma delimeter
-- Sometimes the user do not validate the name and people-status and in the string migh come a comma
-- I move the big record to the sRecord variable

"1250A","James, Fernandez",20020211,5,"Student ,", 4587


I am using the split function to get the information

MyInfo = split(sRecord,",",-1,1)

The problem is because the "James, Fernandez" has a comma in the string, it separates the first and last name which is wrong


My array should looks lilke this one:
=========================
MyInfo(0) = "1250A"
MyInfo(1) = "James Fernandez"
MyInfo(2) = 20020211
MyInfo(3) = 5
MyInfo(4) = "Student"
MyInfo(5) = 4587


However my array looks like this one right now:
=================================
MyInfo(0) = "1250A"
MyInfo(1) = "James "
MyInfo(2) = "Fernandez"
MyInfo(3) = 20020211
MyInfo(4) = 5
MyInfo(5) = "Student"
MyInfo(6) = ""
MyInfo(7) = 4587

Any advice how to fix this problem, it will be appreciated it.

Thanks to all for your knowledge

Daniel
Hollywood, FL








 
You could search for commas in between the '""' and then use the replace function but I would suggest you use XML. You could build an XML doc with all the information you need in each tag and parsing it would be quicker and easier.
 
You could search for commas in between the ' "" ' and then use the replace function but I would suggest you use XML. You could build an XML doc with all the information you need in each tag and parsing it would be quicker and easier.
 
Do some validation on the fields as the input comes in...

and to snag those comma's out of each textbox use the replace function:

Replace "James, Fernandez", ",", " "
which would change James, Fernandez to James Fernandez

Tuna - It's fat free until you add the Mayo!
 
Try blocking the ',' key from working in that textbox:

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = Asc(",") Then KeyAscii = 0
End Sub

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
How do you open the data source? I asked this thinking you're opening a txt file with sequential data. If so, there won't be any need to worry about the commas as each piece of comma-delimited data can be stored directly into a variable, including array ones.

See help on the following commands:
- Open <strFile> As Input For #<nFileNum>
- Input #<nFileNum>, <fieldlist>

[peace]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top