|
-
Feb 20th, 2003, 05:06 PM
#1
Thread Starter
Addicted Member
[RESOLVED] split string
How to split "154*321/5+33-255"
to:
list1.additem "154"
list1.additem "*321"
list1.additem "/5"
list1.additem "+33"
list1.additem "-255"
?
-
Feb 20th, 2003, 05:17 PM
#2
Kars Lensen,
Use the Instr and Mid functions.
-
Feb 20th, 2003, 06:47 PM
#3
Here you go.
VB Code:
Option Explicit
Dim strEqu As String
Private Sub Command1_Click()
Dim i As Integer
Do While Len(strEqu) > 0
For i = 2 To Len(strEqu)
' loop until you find a non numeric character
If Not IsNumeric(Mid(strEqu, i, 1)) Then
' Add that portion to the listbox
List1.AddItem Left$(strEqu, i - 1)
' Remove the portion just added to the
' listbox from the original string.
strEqu = Mid(strEqu, i)
' Restart the for loop with the new string.
Exit For
End If
' When you reach the end of the string add
' whatever is left to the list box.
If i = Len(strEqu) Then
List1.AddItem strEqu
strEqu = ""
End If
Next i
Loop
End Sub
Private Sub Form_Load()
strEqu = "154*321/5+33-255"
End Sub
-
Feb 21st, 2003, 12:59 AM
#4
Thread Starter
Addicted Member
Thanks MarkT !!
Regards, K.
-
Feb 21st, 2003, 01:14 AM
#5
Thread Starter
Addicted Member
Just one problem: If there is a point (.) like 125*25/1.25 the number must appear:
125
*25
/1.25 ???!
-
Feb 21st, 2003, 03:36 AM
#6
Change: If Not IsNumeric(Mid(strEqu, i, 1)) Then
To: If (Not IsNumeric(Mid(strEqu, i, 1)) And (Mid(strEqu, i, 1) <> ".")) Then
so it treats "." as a numeric value
-
Feb 21st, 2003, 04:35 AM
#7
Thread Starter
Addicted Member
Thats it, thanks leinad31 !
-
Feb 21st, 2003, 07:34 AM
#8
Registered User
What about handling for 10^2 and 1.90*102 (1.9E2)?
e.g. Powers and scientific form etc?
What are the limitations of the equation the user will enter?
s.
-
Feb 21st, 2003, 11:16 AM
#9
Depends on what the intended output is for those cases. But if there are more possibilities to consider then he'll probably use select case to handle them.
Probably something like..
VB Code:
Select Case Mid(strEqu, i, 1)
Case "0" To "9"
Case "."
Case "^"
Case Else
End Select
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|