Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read from Array & Write to email message

Status
Not open for further replies.

SWarrior

MIS
Dec 19, 2003
111
US
Is there a way to directly read the contents of an array and write it as plain text into an email message ??

Right now, I can read from the array and write to file, then attach that file to an email, send the email, and then delete the email.txt temp file.

I've tried reading the array into a variable, but that did not work successfully.

Thanks in advance,
-SWarrior
 
Read array into variable as one string :

Code:
MyString = Join(MyArray)

For the mail part of your question, do a search in this forum on smtp.
 
JadeKnight,

It's a little more complicated than that. Here is the code that technically should work, it's only a snip of it, but here it is.
Code:
objMessage.TextBody = eMessage & vbCrLf

do 
 ' Array 1/ID 2/Con 3/Trans 4/Start 5/End 6/Con 7/Trans 8/Start 9/End 10/Enhan
 Counter = Counter + 1
 if arrayObj(Counter,1) = "" then
   msgbox("Array is Empty - Exiting")
   exit do
 end if

 objMessage.TextBody = objMessage.TextBody & arrayObj(1,1) & "        = " & arrayObj(Counter,1) & vbCrLf
 objMessage.TextBody = objMessage.TextBody & "     " & arrayObj(1,2) & "   = " & arrayObj(Counter,2) & vbCrLf
 objMessage.TextBody = objMessage.TextBody & "     " & arrayObj(1,3) & "   = " & arrayObj(Counter,3) & vbCrLf
 objMessage.TextBody = objMessage.TextBody & "     " & arrayObj(1,4) & "    = " & arrayObj(Counter,4) & vbCrLf
 objMessage.TextBody = objMessage.TextBody & "     " & arrayObj(1,5) & "      = " & arrayObj(Counter,5) & vbCrLf
 objMessage.TextBody = objMessage.TextBody & "     " & arrayObj(1,6) & "   = " & arrayObj(Counter,6) & vbCrLf
 objMessage.TextBody = objMessage.TextBody & "     " & arrayObj(1,7) & "   = " & arrayObj(Counter,7) & vbCrLf
 objMessage.TextBody = objMessage.TextBody & "     " & arrayObj(1,8) & "   = " & arrayObj(Counter,8) & vbCrLf
 objMessage.TextBody = objMessage.TextBody & "     " & arrayObj(1,9) & "     = " & arrayObj(Counter,9) & vbCrLf
 objMessage.TextBody = objMessage.TextBody & "     " & arrayObj(1,10) & " = " & arrayObj(Counter,10) & vbCrLf & vbCrLf

 objMessage.TextBody = objMessage.TextBody & "Script Started at:    " & ScriptStart & vbCrLf
 objMessage.TextBody = objMessage.TextBody & "Script Ended at:      " & ScriptEnd & vbCrLf
 objMessage.TextBody = objMessage.TextBody & "Script ran this long: " & hour(ScriptEnd-ScriptStart) & " Hours, " & minute(ScriptEnd-ScriptStart) & " Minutes, " & second(ScriptEnd-ScriptStart) & " Seconds." & vbCrLf

loop until Counter = 20
in theory,
objMessage.TextBody = objMessage.TextBody & whatever
should append 'whatever' to the TextBody, but it's not. This is what I need help with. Problem is, I need to read this information from an array, thus LOOPING is required.

-SWarrior
 
Or
Populate array (assuming 1 dimesion/simple list)

For i = LBound(YourArray) to UBound(YourArray)

strMessage = strMessage & YourArray(i) & vbCrLf

Next

Using Lbound and UBound, you dont need to worry how many items in array
Regards ACO
 
Hello SWarrior!

Your assignment statements look good. What are you getting as output? Have you tried putting in message boxes every so often and check to see what's in objMessage.TextBody?

I'm not sure what the rest of your code works or what you've tried so far, but here are some ideas:
1. Make sure the send message works for you by sending a simple text message like "Hey, it worked!"

2. Make sure your counter is starting at 2 (since it looks like element 1 is header type information).

3. As stated above, put in message box statements towards the bottom of your loop and see what you're getting for output. If objMessage.TextBody is being populated correctly, then you can at least rule out your assignment statements as a possible error.
 
Ok... this is interesting....

I added Dim EmailBody
Changed my variable within the DO Loop. , the last part of the code is this:
Code:
EmailBody = EmailBody & "Script Started at:    " & ScriptStart & vbCrLf
EmailBody = EmailBody & "Script Ended at:      " & ScriptEnd & vbCrLf
EmailBody = EmailBody & "Script ran this long: " & hour(ScriptEnd-ScriptStart) & " Hours, " & minute(ScriptEnd-ScriptStart) & " Minutes, " & second(ScriptEnd-ScriptStart) & " Seconds." & vbCrLf

objMessage.Subject = eSubject & "  (" & Date & ")"
objMessage.Sender = eFrom
objMessage.From = eFrom
objMessage.To = eTo
objMessage.CC = eCC
objMessage.BCC = eBCC
objMessage.TextBody = eMessage & vbCrLf & EmailBody
now, for objMessage.TextBody, I get my eMessage, The line feed, and here is the strange part. I only get the LAST 3 lines of my EmailBody variable. and these are the 3 lines in the above code. I get NOTHING from my Do Loop.

-SWarrior
 
Oh My GOD !!!! Spending TOO much time in front of the screen will BUG your eyes out!! I found the problem... I loop this array several times, and each time, I have to reset my counter.... and guess what... Yep... You guessed it, I forgot to reset the counter durring the email processing of it! I found it after I took a break and then came back to look at it again!

Kudos to the Fresh Cup of Morning Java!! (and the short break) hahaha

Thanks again guys for your VALUABLE help!!

-SWarrior
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top