Solved

Getting multiple substrings from a line in a file

Posted on 1998-11-16
2
162 Views
Last Modified: 2010-04-30
I need to be able to get the string values from the following file entry.  The three string variables vary in length from 2 to 8 characters and also vary from line to line.  I need to print the three values to a listbox. I need help extracting the strings.


D [str_var_1] [str_var_2] 750.0 6500.0 0 2 0 [Str_var_3]
D [str_var_1] [str_var_2] 130.0 8925.0 0 2 0 [Str_var_3]
D [str_var_1] [str_var_2] 265.0 7925.0 0 2 0 [Str_var_3]
0
Comment
Question by:rround
  • 2
2 Comments
 
LVL 18

Accepted Solution

by:
deighton earned 100 total points
ID: 1445048
Private Sub Command1_Click()

    Dim x As String, y As String, z As String

    Call Get_Strings("D [str_var_1] [str_var_2] 750.0 6500.0 0 2 0 [Str_var_3]", x, y, z)
   
    MsgBox x + " " + y + " " + z


End Sub


Private Sub Get_Strings(ByVal sUString As String, x As String, y As String, z As String)

    Dim c As Long
    Dim n As Long
    Dim sTemp As String

    For c = 1 To Len(sUString)
       
        If Mid(sUString, c, 1) = " " Then
       
            n = n + 1
            If n = 2 Then x = sTemp
            If n = 3 Then y = sTemp
         
           
            sTemp = ""
           
        Else
   
            sTemp = sTemp & Mid(sUString, c, 1)
       
        End If
       
    Next
   
    z = sTemp
   

'   D [str_var_1] [str_var_2] 750.0 6500.0 0 2 0 [Str_var_3]
 '  D [str_var_1] [str_var_2] 130.0 8925.0 0 2 0 [Str_var_3]
  ' D [str_var_1] [str_var_2] 265.0 7925.0 0 2 0 [Str_var_3]


End Sub

0
 
LVL 18

Expert Comment

by:deighton
ID: 1445049
This assumes your string values have no spaces in them, space delimitted list.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA color chart bars 12 86
change vba from autofit to 13.5 width? 4 29
passing parameter in sql procedure 9 63
RUNRMTCMD from AS/400 12 47
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

777 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