Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

subscript outside of defined range

Posted on 2010-01-06
12
Medium Priority
?
422 Views
Last Modified: 2012-05-08
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
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

Open in new window

0
Comment
Question by:jaymz69
  • 5
  • 4
  • 3
12 Comments
 
LVL 43

Expert Comment

by:pcelba
ID: 26195137
If the error says "subscript is outside the defined range" then it occurs in different program most probably. (Your tests are almost bulletproof here.)

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.
0
 
LVL 14

Expert Comment

by:tusharkanvinde
ID: 26197039
instead of

IF TYPE("To(i)") = "C"

give

IF ALEN(to)<=i and TYPE("To(i)") = "C"

similarly for cc and bcc

0
 
LVL 14

Expert Comment

by:tusharkanvinde
ID: 26197041
it should be

IF ALEN(to)>=i and TYPE("To(i)") = "C"
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 43

Expert Comment

by:pcelba
ID: 26198076
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.)
0
 

Author Comment

by:jaymz69
ID: 26219386
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..



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

Open in new window

0
 
LVL 43

Accepted Solution

by:
pcelba earned 2000 total points
ID: 26224220
First of all you should tell the line number at which the error appears. You can simply set the error handler this way:

ON ERROR WAIT WINDOW "Error: " + ALLTRIM(STR(ERROR())) + " " + MESSAGE() + CHR(13) + ;
   "Line: " + ALLTRIM(STR(LINENO())) + " in " + SYS(16) + "  " + MESSAGE(1)

and compile your program with debug info. The source code returned by MESSAGE(1) works in development environment only.
0
 
LVL 14

Expert Comment

by:tusharkanvinde
ID: 26252476
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(strAttachmentPath,0)
endif
0
 

Author Comment

by:jaymz69
ID: 26255206
V2 is the copy with the update code I was seeing how it would do.
0
 

Author Comment

by:jaymz69
ID: 26343301
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....
0
 

Author Comment

by:jaymz69
ID: 26345416
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
0
 
LVL 43

Expert Comment

by:pcelba
ID: 26346052
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.
0
 

Author Comment

by:jaymz69
ID: 26347000
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.  
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Visual FoxPro (short VFP) is a programming language with it’s own IDE and database, ranking somewhat between Access and VB.NET + SQL Server (Express). Product Description: http://msdn.microsoft.com/en-us/vfoxpro/default.aspx (http://msd…
How does storytelling impact the web? What goes into a great story on the web? And how can it be used for marketing purposes? All of these questions will be answered.
Integration Management Part 2
Loops Section Overview

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question