Results 1 to 10 of 10

Thread: variables format

  1. #1

    Thread Starter
    Lively Member maki's Avatar
    Join Date
    Mar 2006
    Location
    Greece
    Posts
    82

    Resolved 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.

  2. #2
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: variables format

    VB Code:
    1. Dim RawData$
    2. Dim NewData$
    3.  
    4. RawData = "[V1,V2,V3]"
    5.  
    6. NewData = Replace(RawData, "[", "")
    7. NewData = Replace(NewData, "]", "")
    or
    VB Code:
    1. Dim RawData$
    2. Dim NewData$
    3.  
    4. RawData = "[V1,V2,V3]"
    5.  
    6. NewData = Mid(RawData, 2)
    7. 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

  3. #3

    Thread Starter
    Lively Member maki's Avatar
    Join Date
    Mar 2006
    Location
    Greece
    Posts
    82

    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!

  4. #4
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: variables format

    okay try this

    VB Code:
    1. Dim a As String
    2. Dim DataArray() As String
    3.  
    4.  
    5. a = "(X1,Y1,Z1,W1), (X2,Y2,Z2,W2), (X9,Y9,Z9,W9)"
    6.  
    7. DataArray = Split(a, "), ")
    8.  
    9. For i = 0 To UBound(DataArray)
    10.     DataArray(i) = Replace(DataArray(i), "(", "")
    11.     DataArray(i) = Replace(DataArray(i), ")", "")
    12. Next i
    13.  
    14. MsgBox DataArray(0)
    15. MsgBox DataArray(1)
    16. MsgBox DataArray(2)
    Chris

  5. #5

    Thread Starter
    Lively Member maki's Avatar
    Join Date
    Mar 2006
    Location
    Greece
    Posts
    82

    Re: variables format

    I get a compile error "expected array" for UBound

  6. #6
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    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:
    1. Dim DataArray[B]() [/B]As String
    must have the brackets or it will give that error
    Chris

  7. #7

    Thread Starter
    Lively Member maki's Avatar
    Join Date
    Mar 2006
    Location
    Greece
    Posts
    82

    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:
    1. Dim RawData$
    2. Dim NewData$
    3. Dim a As String
    4. Dim DataArray As String
    5. RawData = schedule
    6.    NewData = Replace(RawData, "[", "")
    7.    NewData = Replace(NewData, "]", "")
    8.     a = NewData
    9.    DataArray = Split(a, "),")
    10.    
    11.  
    12. For i = 0 To UBound(DataArray)
    13.     DataArray(i) = Replace(DataArray(i), "(", "")
    14.     DataArray(i) = Replace(DataArray(i), ")", "")
    15. Next i
    16.  
    17. MsgBox DataArray(0)
    18. MsgBox DataArray(1)
    19. 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?

  8. #8
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: variables format

    the only problem with the code is the line
    VB Code:
    1. 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
    Chris

  9. #9

    Thread Starter
    Lively Member maki's Avatar
    Join Date
    Mar 2006
    Location
    Greece
    Posts
    82

    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!

  10. #10
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: variables format

    alright no probs mate
    Chris

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width