Solved

String parsing

Posted on 2001-06-04
5
131 Views
Last Modified: 2010-05-02
I have a string which contains the below information:

,080800 - Anthelmintics,081202 - Aminoglycosides,081204 - Antifungal Antibiotics

I need to look for a comma in the string and then get only the numbers which follow each comma.

Can you please help with the coding for this.

Thanks
0
Comment
Question by:meyer1049
5 Comments
 
LVL 2

Accepted Solution

by:
damienm earned 30 total points
Comment Utility
If the number always has 6 characters you could use something like below.

Private Sub Command1_Click()
Dim strVal As String
strVal = ",080800 - Anthelmintics,081202 - Aminoglycosides,081204 - Antifungal Antibiotics"
startval = 1
While InStr(startval, strVal, ",")
    MsgBox Mid(strVal, InStr(startval, strVal, ",") + 1, 6)
    startval = InStr(startval, strVal, ",") + 1
Wend
End Sub
0
 
LVL 15

Expert Comment

by:robbert
Comment Utility
Dim arr1 As Variant
Dim arr2 As Variant
Dim strVal As String
Dim i As Integer

strVal = ",080800 - Anthelmintics,081202 - Aminoglycosides,081204 - Antifungal Antibiotics"
strVal = Right(strVal, Len(strVal - 1)

arr1 = Split(strVal, ",")
For i = 0 To UBound(arr1)
    arr2 = Split(arr1(i), " ")
    MsgBox arr2(0)
Next
0
 
LVL 2

Expert Comment

by:damienm
Comment Utility
Robert,

You are missing a ) after Len

strVal = Right(strVal, Len(strVal) - 1)
0
 
LVL 18

Expert Comment

by:deighton
Comment Utility
Dim s As String
Dim lNumbers()
Dim count As Long
Dim sTemp As String
Dim c As Long


s = ",080800 - Anthelmintics,081202 - Aminoglycosides,081204 - Antifungal Antibiotics"""

While InStr(s, ",")
    s = Right(s, Len(s) - InStr(s, ","))
    c = 1
    sTemp = ""
    count = count + 1
    ReDim Preserve lNumbers(count)
   
    While IsNumeric(Mid(s, c, 1))
        sTemp = sTemp & Mid(s, c, 1)
        c = c + 1
    Wend
    lNumbers(count) = Val(sTemp)
Wend


For c = 1 To count
    Debug.Print lNumbers(count)
Next
0
 
LVL 2

Expert Comment

by:smkkaleem
Comment Utility
I used a string array to fill the required number. Also they would be displayed in the Immediate Window. Any questions, please comment

Private Sub Command1_Click()
Dim p_str As String, p_Num(1 To 3) As String, i As Integer, p_intStart As Integer
p_str = ",080800 - Anthelmintics,081202 - Aminoglycosides,081204 - Antifungal Antibiotics"
p_intStart = InStr(1, p_str, ",")
For i = 1 To 3
    p_Num(i) = Trim(Mid(p_str, InStr(p_intStart, p_str, ",") + 1, InStr(InStr(p_intStart, p_str, ","), p_str, "-") - InStr(p_intStart, p_str, ",") - 1))
    p_intStart = InStr(InStr(p_intStart, p_str, ","), p_str, "-")
    Debug.Print p_Num(i)
Next i
End Sub
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now