Results 1 to 7 of 7

Thread: converting an arraylist to an array...

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Posts
    13

    converting an arraylist to an array...

    i'm somewhat new to vb, but i am writing this code using vb.net and in the process of learning stumbled across an arraylist

    i tried converting the arraylist to an array using

    dim a as array
    a = mailbody.toarray()

    and then attempted to print out the array on a email

    message.body = string.join(vbnewline, a)

    somehow this code isn't working and i can't figure out how, any help would be gladly appreciated ^^

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    What's not working about it? Some sort of run time error, or a compile error?

    Help me to help you.
    Help me to help you.
    Help me to help you.
    Help me to help you.
    Help me to help you.

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Posts
    13
    well heres the whole code, but i'm not sure how to put it in vb format on this forum... <-- newbie

    and when i debug it gives me a system.invaldidcastexception


    Public Sub sender(ByRef mailbody As ArrayList)
    Dim a As Array
    Dim message As System.Web.Mail.MailMessage = New System.Web.Mail.MailMessage
    Dim NumberEmail As Integer
    'Dim errorlinenumber As Integer
    Try
    For NumberEmail = 1 To projectnum - 1
    'message.To = "[email protected]"
    message.To = fformstorage(NumberEmail)
    message.From = "[email protected]"
    'note to self: edit sender line later
    'i'm not sure what the server is called yet so i'm calling it "server" for now
    message.Subject = "code error"
    message.BodyFormat = MailFormat.Text
    'all this other commented out material are here just for test/debugging purposes only
    'message.Body = ("wow IT WORKED!")
    'For errorlinenumber = 1 To sp.stringnumber
    a = mailbody.ToArray()
    message.Body = String.Join(vbNewLine, a)
    Try
    'SmtpMail.SmtpServer = "server"
    SmtpMail.Send(message)
    Catch ehttp As System.Web.HttpException
    Console.WriteLine(ehttp.Message)
    Console.WriteLine("Here is the full error message")
    Console.Write(ehttp.ToString())
    End Try
    Next
    Catch e As System.Exception
    'display text of uknown error
    Console.WriteLine("unknown exception occured ", e.Message)
    Console.WriteLine("Here is the full error message")
    Console.WriteLine(e.ToString())

    End Try

    End Sub

  4. #4
    Hyperactive Member LeeSalter's Avatar
    Join Date
    Oct 2002
    Location
    Notts, England
    Posts
    307
    I assume this is falling over at the
    Code:
    a = mailbody.ToArray()
    line...?

    If so, try this:-

    Code:
    mailbody.CopyTo(a)
    Let me know how you get on...
    "I'm Brian and so is my Wife"

  5. #5
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Originally posted by ultimia
    well heres the whole code, but i'm not sure how to put it in vb format on this forum... <-- newbie

    Hi,

    Click on the "faq" tag at the top of the forum and go to the third section for full formatting instructions.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  6. #6
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    i thought i'd post this to help you with another vb.net feature:

    you have a comment that says 'note to self:edit sender line later

    you can use a 'token' to mark this in your TASKS. try this:

    'todo edit sender line later

    this will make it show up in your task view and you can double click on that task and go straight to that comment. no more searching for buried comments

  7. #7

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Posts
    13
    wow thanks guys for the tips and advice. I ended up doing

    a = mailbody.ToArray(Type.GetType("System.String"))
    message.Body = String.Join(vbNewLine, a)

    and got it through that way. Thanks for the advice though ^^

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