944,085 Members | Top Members by Rank

Ad:
Jan 5th, 2007
0

What is the problem with this line of my code?

Expand Post »
Here is VB6 Code:
VB Syntax (Toggle Plain Text)
  1. Attachement = objMail.Attachments.Add("D:\message.doc.pgp")

I am trying to automatically attach a file with outlook email......objMail.Attachments.Add method is unable to read the file "message.doc.pgp" very first time when the code execute.....On second n later executions it start recognizing the file n work fine but y not the first time.

I create the file "message.doc.pgp" by using shell command as follow.
VB Syntax (Toggle Plain Text)
  1. Shell "command.com /c pgp -e " & "d:\message.doc " & "Imran Khalid"
....when this command execute....a file "D:\message.doc.pgp" is created automatically which i later wants to sends as an email attachment....but not recognized during first time code execution as mentioned above.

Thanx a lot
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ikhalid is offline Offline
3 posts
since Jan 2007
Jan 5th, 2007
0

Re: What is the problem with this line of my code?

Since VB's Shell statement starts the outside program and then passes control to the next line of code right away, the outside program probably doesn't have a chance to finish running before you try to attach the file to the email message. You'll get the error because the outside program is still writing the file when your code tries to attach it.

Luckily, the fix for this is really easy. All you have to do is put the following code after your Shell statement, and then tweak the value of the variable "waitSeconds" so that you're waiting long enough for the outside program to finish, but not so long that it looks like your program isn't doing the job:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. waitSeconds = 5 ' Wait for 5 seconds before trying to use the file
  2. startTime = Timer
  3. Do Until Timer - waitSeconds >= startTime
  4. DoEvents ' Don't want the user to think it's frozen!
  5. Loop
That should fix the problem! Good luck!

- Sen
Reputation Points: 16
Solved Threads: 1
Light Poster
sendoshin is offline Offline
39 posts
since Sep 2006
Jan 8th, 2007
0

Re: What is the problem with this line of my code?

Load of thanx
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ikhalid is offline Offline
3 posts
since Jan 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Need Time Code
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: ActiveX DLL reference





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC