Hy guys,
I need some help with strings. The two strings show like this.
1. -Value1;-Value2;-Value3
2. -Value1;-Value2;-Value3;Value4
I would like to add all values with "-" in one string.
Thanks for help!
Printable View
Hy guys,
I need some help with strings. The two strings show like this.
1. -Value1;-Value2;-Value3
2. -Value1;-Value2;-Value3;Value4
I would like to add all values with "-" in one string.
Thanks for help!
what is your code and where are you loading the strings
is the string an array with ; as a delimiter
or do you have a file with a bunch of numbers
Sorry
Both strings are arrays an the ; is the delimiter
the second string is comeing from a file
the first from the registry
Code:For Each Item in arrayname
singlestring=singlestring & "-" & Item
next Item
Code:Option Explicit
Private Sub Form_Load()
Dim Sfile As String, var1 As String
Dim sResult As Variant
'Sfile = "yourpath/yourfile/ext"
var1 = "-4;-4;-4;6;6"
'Open Sfile For Input As intNum
'read the complete file into a string variable
'var1 = StrConv(InputB(LOF(intNum), intNum), vbUnicode)
' Close intNum
Dim i As Integer
'use the split function to split the string
'into sections using the ; as the split pos
sResult = Split(var1, ";")
'read the split into the public array
Dim myArr() As Integer
For i = 0 To UBound(sResult)
ReDim Preserve myArr(i)
myArr(i) = Trim(sResult(i))
Next i
For i = 1 To UBound(myArr)
If Left(myArr(i), 1) = "-" Then
myArr(i) = myArr(i) + myArr(i - 1)
End If
Next i
'display
For i = 1 To UBound(myArr)
MsgBox myArr(i)
Next i
' then rejoin the array...and put it back or whatever you
'plan on doing
End Sub