Results 1 to 12 of 12

Thread: Code works perfect but I want to change something

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2009
    Location
    Belgium
    Posts
    58

    Code works perfect but I want to change something

    Hi, I have this code:

    Code:
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim input As String = "CreateObject(1800, 2920.920166, 8716.677734, 7188.390137, 0.0000, 0.0000, 180.0000);"
            Dim pattern As String = "\d+\.?\d*"
            Dim numbers As System.Text.RegularExpressions.MatchCollection
            numbers = System.Text.RegularExpressions.Regex.Matches(input, pattern)
            If numbers.Count >= 3 Then
                For i As Integer = 1 To 3
                    MessageBox.Show(numbers(i).Value)
                Next
            End If
        End Sub
    This works perfect but It gives me a MessageBox. I want a RichTextBox as answer but when I change I get no error but my answer is something else.
    I do this
    Code:
    RichTextBox1.Text = numbers(i).Value
    And get as answer only 7188.390137 but I must get as answer
    2920.920166, 8716.677734, 7188.390137. With MessageBox it works perfect ..

    Thanks in advance..

  2. #2
    Addicted Member ZenDisaster's Avatar
    Join Date
    Dec 2006
    Location
    Bay Area, CA
    Posts
    140

    Re: Code works perfect but I want to change something

    RichTextBox1.Text += numbers(i).Value & ", "

  3. #3

    Thread Starter
    Member
    Join Date
    Sep 2009
    Location
    Belgium
    Posts
    58

    Re: Code works perfect but I want to change something

    Thank you, It worked, I get as anwser 2920.920166, 8716.677734, 7188.390137, Can we remove this last comma?

  4. #4
    Addicted Member ZenDisaster's Avatar
    Join Date
    Dec 2006
    Location
    Bay Area, CA
    Posts
    140

    Re: Code works perfect but I want to change something

    Code:
                For i As Integer = 1 To 3
                    RichTextBox1.Text += numbers(i).Value & ", "
                Next
                RichTextBox1.Text = Strings.Left(RichTextBox1.Text, Len(RichTextBox1.Text) - 2)
    Last edited by ZenDisaster; Oct 11th, 2009 at 08:26 AM.

  5. #5

    Thread Starter
    Member
    Join Date
    Sep 2009
    Location
    Belgium
    Posts
    58

    Re: Code works perfect but I want to change something

    Didn't work .. Anything else you know maybe?

  6. #6
    Addicted Member ZenDisaster's Avatar
    Join Date
    Dec 2006
    Location
    Bay Area, CA
    Posts
    140

    Re: Code works perfect but I want to change something

    try that one. I mistook numbers for an array then saw it was a collection of regex match objects.

  7. #7

    Thread Starter
    Member
    Join Date
    Sep 2009
    Location
    Belgium
    Posts
    58

    Re: Code works perfect but I want to change something

    Super Thank you ZenDisaster.

  8. #8
    Addicted Member ZenDisaster's Avatar
    Join Date
    Dec 2006
    Location
    Bay Area, CA
    Posts
    140

    Re: Code works perfect but I want to change something

    Glad I could help.

  9. #9

    Thread Starter
    Member
    Join Date
    Sep 2009
    Location
    Belgium
    Posts
    58

    Re: Code works perfect but I want to change something

    Can you help again for something? ^^

    I want to put this in front of these codes:

    Code:
    MoveObject(
    and will end with this
    Code:
    );
    Example:
    Code:
    MoveObject(2920.920166, 8716.677734, 7188.390137);
    How can I do this?

  10. #10

    Thread Starter
    Member
    Join Date
    Sep 2009
    Location
    Belgium
    Posts
    58

    Re: Code works perfect but I want to change something

    *Spam*

    But no one who can help?

  11. #11
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: Code works perfect but I want to change something

    First off, instead of manually joining strings in an array together and removing the last 'extra' comma, you should use the String.Join function, which does not produce the extra comma in the first place.

    To add the MoveObject text, simply prefix the string with that string.

    All in all, you could get something like this. I put the numbers values into a separate array so I could use the String.Join function. I'm sure this can be done with LINQ much more elegantly though, but that shouldn't matter.

    vb.net Code:
    1. 'Load values into array
    2. Dim values(3) As String
    3. For i As Integer = 1 To 3
    4.    values(i) = numbers(i).Value
    5. Next
    6.  
    7. 'Join array into string
    8. Dim valueString As String = String.Join(", ", values)
    9.  
    10. 'Append moveObject text:
    11. RichTextBox1.Text = "MoveObject(" & valueString & ");"

  12. #12

    Thread Starter
    Member
    Join Date
    Sep 2009
    Location
    Belgium
    Posts
    58

    Re: Code works perfect but I want to change something

    Thank you very much ^^

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