-
Oct 11th, 2009, 08:08 AM
#1
Thread Starter
Member
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..
-
Oct 11th, 2009, 08:11 AM
#2
Addicted Member
Re: Code works perfect but I want to change something
RichTextBox1.Text += numbers(i).Value & ", "
-
Oct 11th, 2009, 08:14 AM
#3
Thread Starter
Member
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?
-
Oct 11th, 2009, 08:19 AM
#4
Addicted Member
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.
-
Oct 11th, 2009, 08:26 AM
#5
Thread Starter
Member
Re: Code works perfect but I want to change something
Didn't work .. Anything else you know maybe?
-
Oct 11th, 2009, 08:26 AM
#6
Addicted Member
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.
-
Oct 11th, 2009, 08:30 AM
#7
Thread Starter
Member
Re: Code works perfect but I want to change something
Super Thank you ZenDisaster.
-
Oct 11th, 2009, 08:31 AM
#8
Addicted Member
Re: Code works perfect but I want to change something
Glad I could help.
-
Oct 11th, 2009, 08:52 AM
#9
Thread Starter
Member
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:
and will end with this Example:
Code:
MoveObject(2920.920166, 8716.677734, 7188.390137);
How can I do this?
-
Oct 11th, 2009, 10:40 AM
#10
Thread Starter
Member
Re: Code works perfect but I want to change something
*Spam*
But no one who can help?
-
Oct 11th, 2009, 11:32 AM
#11
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:
'Load values into array Dim values(3) As String For i As Integer = 1 To 3 values(i) = numbers(i).Value Next 'Join array into string Dim valueString As String = String.Join(", ", values) 'Append moveObject text: RichTextBox1.Text = "MoveObject(" & valueString & ");"
-
Oct 11th, 2009, 12:06 PM
#12
Thread Starter
Member
Re: Code works perfect but I want to change something
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
|