Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I make this?
#1
So I want to make a program which will separate the Email IDs from richbox1 or Textbox1 to Another Textbox/richbox. Here's the GUI.

When I press the ">>sort>>" button, this should Get the lines containing "@" symbol from Text/Richbox 1.....


[Image: 410cca1ba5a3c42948f72625e22ee762.png?1330083670]

Any Idea How?

Reply
#2
Code:
For Each Str As String In TextBox1.Text.Split(vbNewLine)
            If Str.Contains("@") Then
                TextBox2.Text += vbNewLine & Str
            End If
        Next
[Image: cooldude.png]

(09-05-2011, 08:36 AM)Orgy Wrote: If you understand what you're doing, you aren't learning anything. ;)
Reply
#3
Quote:Get the lines containing "@" symbol from Text/Richbox 1.

(02-24-2012, 09:27 AM)★Cooldude★ Wrote:
Code:
For Each Str As String In TextBox1.Text.Split(vbNewLine)
            If Str.Contains("@"c) Then
                TextBox2.Text += vbNewLine & Str
            End If
        Next

You shouldn't be using + though. The only reason that works is because VB explicitly defines the types on each side of the operand as a string for you, so it assumes that you want to concat them. Also, you should be putting the newline after the string, otherwise you'll end up with a new blank/empty line in the sorted textbox everytime. Also, I'm not sure why you're using the vb newline char or split though, there's already a method to get textbox lines.

Doing this is going to be very slow the more data you have in Textbox2:
Code:
TextBox2.Text += vbNewLine & Str

Because what that does, is it looks at the whole value of Textbox2.Text, and then adds vbNewLine and Str to it, every time that loop goes through. You don't need to look at what's in Textbox2 every time, that should just be foregotten about, it should have taken care of itself if you're defining what data to add to it anyway, unless you need to double check it's value every time though, I don't see a reason to use &= or +=.

If there's lots of lines to iterate through too, stringbuilder is your best option as it's fast.
Code:
Dim sb As New StringBuilder
For Each objLine As String In TextBox1.Lines
    If objLine.Contains("@") Then
        sb.AppendLine(objLine)
    End If
Next
TextBox2.Text = sb.ToString

If you're sure that will do, otherwise you could use regex to find emails in each line... Or use something like this at least:
Code:
If objLine.Contains("@"c) AndAlso objLine.Contains("."c) Then
Reply
#4
(02-24-2012, 01:12 PM)AceInfinity Wrote:
(02-24-2012, 09:27 AM)★Cooldude★ Wrote:
Code:
For Each Str As String In TextBox1.Text.Split(vbNewLine)
            If Str.Contains("@"c) Then
                TextBox2.Text += vbNewLine & Str
            End If
        Next
You shouldn't be using + though. The only reason that works is because VB explicitly defines the types on each side of the operand as a string for you, so it assumes that you want to concat them. Also, you should be putting the newline after the string, otherwise you'll end up with a new blank/empty line in the sorted textbox everytime. Also, I'm not sure why you're using the vb newline char or split though, there's already a method to get textbox lines.

Doing this is going to be very slow the more data you have in Textbox2:
Code:
TextBox2.Text += vbNewLine & Str

Because what that does, is it looks at the whole value of Textbox2.Text, and then adds vbNewLine and Str to it, every time that loop goes through. You don't need to look at what's in Textbox2 every time, that should just be foregotten about, it should have taken care of itself if you're defining what data to add to it anyway, unless you need to double check it's value every time though, I don't see a reason to use &= or +=.

If there's lots of lines to iterate through too, stringbuilder is your best option as it's fast.
Code:
Dim sb As New StringBuilder
For Each objLine As String In TextBox1.Lines
    If objLine.Contains("@") Then
        sb.AppendLine(objLine)
    End If
Next
TextBox2.Text = sb.ToString

If you're sure that will do, otherwise you could use regex to find emails in each line... Or use something like this at least:
Code:
If objLine.Contains("@"c) AndAlso objLine.Contains("."c) Then

I didn't realize you could get all of the lines in a textbox like that, thanks. Smile

[Image: cooldude.png]

(09-05-2011, 08:36 AM)Orgy Wrote: If you understand what you're doing, you aren't learning anything. ;)
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)