Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

String parsing

Posted on 2001-06-04
5
Medium Priority
?
139 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 120 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
Suggested Courses

618 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