Link to home
Start Free TrialLog in
Avatar of Steve Lim
Steve Lim

asked on

Splitting a string from CSV file by comma delimited

Hi All,

Have a problem and need help here. i am using vb6 and now face 2 problem .
1. Need to split the string into variable from CSV file but the data may contain comma in quote, which is -
 
            - string = abc,"3,4,5,6","3",Steve,got,"1,2,3",problem
             
             * i want to split into 6 variable to become
               
                aVar = "abc"
                bVar = "3,4,5,6"
                cVar = "3"
                dVar = "Steve"
                eVar = "got"
                fVar = "1,2,3"
                gVar = "problem"

2. i want to sort the string in 2 element, which is sort bVar then follow by fVar.

Anyone able to advice,

thanks in advance.

Regards
Steve
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

in vb6 (long time not using) should have a Split function, use it to split the string into an array variable.

and then doing a loop to compare the values and sort accordingly (this depends on your logic of sorting).
Avatar of Steve Lim
Steve Lim

ASKER

Thanks Ryan but i try to using split function but the problem is the comma in quote.
Private Sub Command1_Click()
Dim myStr As String
Dim xPos As Integer

myStr = "This:is:a:test:string"
xPos = InStr(1, myStr, ":")

Debug.Print Mid$(myStr, 1, xPos - 1)
Debug.Print Mid$(myStr, xPos + 1, Len(myStr))

Open in new window


I programmed vb6 back in 1999 this worked then :-)
SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
hi Ryan,

got it
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi All,

Thanks alot and appreaciate all the advice and guide, due to the project is in rush, i using a stupid method to do it and finally i have done what i want.

Regards
Steve
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I have recommended this question be closed as follows:

Split:
-- aikimark (https:#a42180666)
-- aikimark (https:#a42180575)
-- GrahamSkan (https:#a42180168)
-- Ryan Chong (https:#a42179336)


If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.

MacroShadow
Experts-Exchange Cleanup Volunteer