jaymz69
asked on
subscript outside of defined range
I am wonder if it happens when the call to the SendEmail.prg
I never see this error on debug, but I never try and Email either on debug
the SendEmail.prg code
so it is taking the array I am passing and giving the 1294 error.
this code usually was set up in the program as
Store "me@myDomain.com" to to (1)
....
When I got to this program for SendEmail
I never see this error on debug, but I never try and Email either on debug
the SendEmail.prg code
so it is taking the array I am passing and giving the 1294 error.
this code usually was set up in the program as
Store "me@myDomain.com" to to (1)
....
When I got to this program for SendEmail
Program to send email using "TO", "CC", and "BCC" public arrays
Parameters strFrom, strSubject, strBodyText, strAttachmentPath
Private x, SMTP
SMTP = Createobject("EasyMail.SMTP")
SMTP.MailServer = "blah4.blah.com"
SMTP.FromAddr = strFrom
SMTP.Subject = strSubject
SMTP.BodyText = strBodyText
SMTP.AddAttachment(strAttachmentPath,0)
SMTP.LicenseKey = "Blah (Single Developer)/00106202107999000A88"
*SMTP.LogFile=1
* Add all 'TO','CC', and 'BCC' addresses
For i=1 To 20
IF TYPE("To(i)") = "C"
SMTP.AddRecipient("", To(i), 1)
Endif
IF TYPE("CC(i)") = "C"
SMTP.AddRecipient("", CC(i), 2)
Endif
IF TYPE("BCC(i)") = "C"
SMTP.AddRecipient("", BCC(i), 3)
Endif
Endfor
x = SMTP.Send()
If x = 0 Then
*MessageBox("Message sent successfully.")
? "Sent"
Else
*MessageBox("There was an error sending your message. Error: " + AllTrim(Str(x)))
? "Not sent!"
Endif
Release SMTP
instead of
IF TYPE("To(i)") = "C"
give
IF ALEN(to)<=i and TYPE("To(i)") = "C"
similarly for cc and bcc
IF TYPE("To(i)") = "C"
give
IF ALEN(to)<=i and TYPE("To(i)") = "C"
similarly for cc and bcc
it should be
IF ALEN(to)>=i and TYPE("To(i)") = "C"
IF ALEN(to)>=i and TYPE("To(i)") = "C"
ALEN(to) is not necessary because TYPE() does not raise error when the array dimension is outside of defined range.
The only problem could be NULL value, so the test should be:
IF TYPE("To(i)") = "C" AND VARTYPE(To(i)) = "C"
or maybe better
IF TYPE("To(i)") = "C" AND VARTYPE(To(i)) <> "X"
which better explains the reason of double testing...
But it all means the error source is somewhere else.
BTW, it should be sufficient to ask admin or moderator to remove the Code snippet from this question instead of deletion. (It is even faster than deletion itself.)
The only problem could be NULL value, so the test should be:
IF TYPE("To(i)") = "C" AND VARTYPE(To(i)) = "C"
or maybe better
IF TYPE("To(i)") = "C" AND VARTYPE(To(i)) <> "X"
which better explains the reason of double testing...
But it all means the error source is somewhere else.
BTW, it should be sufficient to ask admin or moderator to remove the Code snippet from this question instead of deletion. (It is even faster than deletion itself.)
ASKER
Today I had it run with the code IF TYPE("To(i)") = "C" AND VARTYPE(To(i)) = "C"
but still had therror.
BUT when it ran and there was no attachments to email just the email with text it never had the subsript error.
I think it's happening when it has to attach and send the Email
here is the do for the email..
but still had therror.
BUT when it ran and there was no attachments to email just the email with text it never had the subsript error.
I think it's happening when it has to attach and send the Email
here is the do for the email..
Do SendeMail_v2.prg With "JamesT@tasupply.com", "Bin Adjustments"+lcLoc, "Attached is your excel report with the Bin Adjustments for "+lcLoc+" made.", "c:\bin_adjustments"+lcLoc+".xls"
Else
Do SendeMail.prg With "JamesT@tasupply.com", "*** No Bin Adjustment"+lcLoc+" Records Found ***", "No Bin Adjustment Records Found."
? "No records found"
? Time()
Endif
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You seem to have 2 different programs for attachment and not attacment. SendeMail_v2 and SendeMail. Are you sure you are sending us the correct program.
It would be better to have
if not empty(strAttachmentPath)
SMTP.AddAttachment(strAtta chmentPath ,0)
endif
It would be better to have
if not empty(strAttachmentPath)
SMTP.AddAttachment(strAtta
endif
ASKER
V2 is the copy with the update code I was seeing how it would do.
ASKER
So when I run a debug on the whole .exe
and run the prg that uses the demsion for Email Array it works
the that program ends and does another ,prg
well the array from the last email is still loaded, the three for the "TO" field.
I need to reset it back to the to(20) again....
and run the prg that uses the demsion for Email Array it works
the that program ends and does another ,prg
well the array from the last email is still loaded, the three for the "TO" field.
I need to reset it back to the to(20) again....
ASKER
I figured out what I needed to do....
Dimension to(20) &&when the main prg fires off it has" Public arrary to (20) this will set it back to 20
to = .F. && Now set all the to arrays back to False
Dimension to(20) &&when the main prg fires off it has" Public arrary to (20) this will set it back to 20
to = .F. && Now set all the to arrays back to False
Great. Sometimes it is useful to read the code from beginning and imagine what it does, if it has all necessary data available, what could cause some missing value or undeclared variable etc.
ASKER
Yes the wonderful debug on the main prg. The I seen what it started with and after it called another prg mine I could see how it wasn't being set back as from the main prg
So the others failed after the third email.
So the others failed after the third email.
If the error number is 1294 then it has nothing to do with array dimensions.
Error descriptions and codes:
1294: "name" is not a valid resource file
1234: Subscript is outside defined range.
My recommendation: Look at calling program code.