|
-
Apr 14th, 2006, 09:34 AM
#1
Thread Starter
Lively Member
variables format
Hallo!
I have created a vb application in which the variables take their values by another program. The format of the variables looks like that:
[V1,V2,V3]
Can i convert the list somehow so the variables are appeared without the brackets?
e.g. V1,V2,V3
Thank you!
Last edited by maki; Apr 14th, 2006 at 10:50 AM.
-
Apr 14th, 2006, 09:41 AM
#2
Re: variables format
VB Code:
Dim RawData$
Dim NewData$
RawData = "[V1,V2,V3]"
NewData = Replace(RawData, "[", "")
NewData = Replace(NewData, "]", "")
or
VB Code:
Dim RawData$
Dim NewData$
RawData = "[V1,V2,V3]"
NewData = Mid(RawData, 2)
NewData = Left(NewData, Len(NewData) - 1)
that will remove the brackets, is that what you mean?
Last edited by the182guy; Apr 14th, 2006 at 09:45 AM.
Chris
-
Apr 14th, 2006, 10:07 AM
#3
Thread Starter
Lively Member
Re: variables format
Yes!
Thank you very much!
Can i ask something else also?
If a have a string variable that looks like that:
a=(X1,Y1,Z1,W1), (X2,Y2,Z2,W2)
can i remove the parenthesis and store the data in an array per parenthesis context.
eg 1st record X1,Y1,Z1,W1
2nd record X2,Y2,Z2,W2
Thanks again!
-
Apr 14th, 2006, 10:12 AM
#4
Re: variables format
okay try this
VB Code:
Dim a As String
Dim DataArray() As String
a = "(X1,Y1,Z1,W1), (X2,Y2,Z2,W2), (X9,Y9,Z9,W9)"
DataArray = Split(a, "), ")
For i = 0 To UBound(DataArray)
DataArray(i) = Replace(DataArray(i), "(", "")
DataArray(i) = Replace(DataArray(i), ")", "")
Next i
MsgBox DataArray(0)
MsgBox DataArray(1)
MsgBox DataArray(2)
-
Apr 14th, 2006, 10:28 AM
#5
Thread Starter
Lively Member
Re: variables format
I get a compile error "expected array" for UBound
-
Apr 14th, 2006, 10:31 AM
#6
Re: variables format
hmm i copied it and pasted exactly and ran it without error, did you change any of the code?
this line
VB Code:
Dim DataArray[B]() [/B]As String
must have the brackets or it will give that error
-
Apr 14th, 2006, 10:42 AM
#7
Thread Starter
Lively Member
Re: variables format
Maybe it is my fault. I will be more specific.
I have a variable named schedule and has the follwing content:
[(103,r1,c1,p1),(101,r1,c1,p2),(301,r1,c1,p2),(102,r1,c1,p3),(302,r1,c2,p2),(202,r1,c2,p3),(201,r1,c2 ,p4),(303,r1,c3,p1),(102,r2,c3,p2),(103,r2,c3,p3),(101,r2,c3,p4),(102,r4,c4,p4),(203,r1,c4,p5),(101, r4,c4,p5)]
I used the first code you send me and i removed the brackets.
I used the following code
VB Code:
Dim RawData$
Dim NewData$
Dim a As String
Dim DataArray As String
RawData = schedule
NewData = Replace(RawData, "[", "")
NewData = Replace(NewData, "]", "")
a = NewData
DataArray = Split(a, "),")
For i = 0 To UBound(DataArray)
DataArray(i) = Replace(DataArray(i), "(", "")
DataArray(i) = Replace(DataArray(i), ")", "")
Next i
MsgBox DataArray(0)
MsgBox DataArray(1)
MsgBox DataArray(2)
That's only a part of the code. Could the rest of the code that i have created before create any problem?
-
Apr 14th, 2006, 10:46 AM
#8
Re: variables format
the only problem with the code is the line
VB Code:
Dim DataArray[B]()[/B] As String
it should have those brackets, i just tried all of the code with the shedule content, and works, your code doesnt have the () brackets in the above line
-
Apr 14th, 2006, 10:49 AM
#9
Thread Starter
Lively Member
Re: variables format
Yes you are right!
I must have been a little bit careless!!!
Thank you very much! You really help me a lot!
-
Apr 14th, 2006, 10:53 AM
#10
Re: variables format
alright no probs mate
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
|