Results 1 to 23 of 23

Thread: Select issue

Hybrid View

  1. #1
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Select issue

    Here it is, using LINQ:

    vb.net Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.     Dim emailGroup As String
    3.  
    4.     'set the max email addresses per batch, and email seperator character
    5.     Dim maxLengthPerBatch As Integer = 4
    6.     Dim emailSeperator As String = ";"
    7.  
    8.     counter(True, maxLengthPerBatch)
    9.     Dim emailBatches = From email In emailGroup.Split(emailSeperator.ToCharArray) _
    10.                        Group email By url = email.Split("@"c)(1) Into email = Distinct() _
    11.                        Select splitted = From em In email _
    12.                             Group em By gnum = (counter() Mod email.Count) \ maxLengthPerBatch Into em = Group _
    13.                             Order By gnum, em _
    14.                             Select emails = Join(em.ToArray, emailSeperator)
    15.     emailBatches = emailBatches.ToList
    16.  
    17.     'now we have all the batches in our emailBatches variable
    18.     'so we can enumerate thru them and send emails
    19.  
    20.     'let's see if it prints correctly in our debug window.
    21.     For Each batch In emailBatches
    22.         For Each item As String In batch
    23.             Debug.WriteLine(item)
    24.         Next
    25.     Next
    26. End Sub
    27.  
    28. 'dummy procedure to mimic i++ kind of thing in C#, since vb.net doesn't have one
    29. Private Function counter(Optional ByVal reset As Boolean = False, Optional ByVal resetSeed As Integer = -1) As Integer
    30.     Static i As Integer = resetSeed
    31.     If reset Then i = resetSeed
    32.     i += 1
    33.     Return i
    34. End Function

    Pradeep
    Last edited by si_the_geek; Mar 1st, 2009 at 03:21 PM. Reason: removed accidental Email tags
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

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