Solved

String parsing

Posted on 2001-06-04
5
135 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 2

Accepted Solution

by:
damienm earned 30 total points
ID: 6153142
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
ID: 6153163
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
ID: 6153204
Robert,

You are missing a ) after Len

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

Expert Comment

by:deighton
ID: 6153293
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
ID: 6153318
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

749 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