Solved

formatting strings

Posted on 1999-01-21
4
133 Views
Last Modified: 2010-05-03
If I have a string like 1,2,3,4,5,6,... how do I convert this into separate integers like 1 2 3 4 5 6 ....  So the question is how do I remove the commas and convert this string into the integers that are separated by the commas.
0
Comment
Question by:arkady5
  • 3
4 Comments
 
LVL 2

Accepted Solution

by:
cjwik earned 10 total points
ID: 1469878
You have to build your own function that will handel this for you. Use the instr function to help you search for commas, or maybe use the len to get hold of how long your string is and start steping throug it one step at the time.
0
 
LVL 18

Expert Comment

by:deighton
ID: 1469879
That answers all very well, but reject it if you want because I've got the code ready for you!
 

0
 
LVL 18

Expert Comment

by:deighton
ID: 1469880
That answers all very well, but reject it if you want because I've got the code ready for you!
 

0
 
LVL 18

Expert Comment

by:deighton
ID: 1469881
Private Sub Command1_Click()

Dim i As Integer, stemp As String, sstring As String
Dim n(10) As Integer, j As Integer

i = 1

sstring = "1,2,3,4,5,6"

While i <= Len(sstring)
  If Mid(sstring, i, 1) <> "," Then
     stemp = stemp & Mid(sstring, i, 1)
  Else
     MsgBox (stemp)    'store it here
     j = j + 1
     n(j) = Val(stemp)
     stemp = ""
  End If
  i = i + 1
Wend
MsgBox stemp 'store it here
j = j + 1
n(j) = Val(stemp)


End Sub

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…

860 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