473,394 Members | 1,759 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

What is the Option Strict On replacement for CreateItem?

There are two statements below marked 'ERROR that I would like to recode to
be acceptable to Option Strict On. I tried the two statements at the
bottom, but that was not acceptable. Can anyone Help?

Dim outlook As Outlook.Application

Dim olns As Outlook.NameSpace

Dim apptItem As Outlook.AppointmentItem

Dim mailItem As Outlook.MailItem

outlook = New Outlook.ApplicationClass

olns = outlook.GetNamespace("MAPI")

mailItem = outlook.CreateItem(olMailItem) 'ERROR

apptItem = outlook.CreateItem(olAppointmentItem) 'ERROR

Cannot use statements below because Sub New() is Private:

Dim apptItem As New Outlook.AppointmentItem

Dim mailItem As New Outlook.MailItem

Thanks,

Dean Slindee
Nov 21 '05 #1
4 2459
I think you may have a name space imports problem.

'Assuming:
Imports Microsoft.Office.Core
Imports Microsoft.Office.Interop

'Then:
mailItem = outlook.CreateItem(Outlook.olMailItem)
apptItem = outlook.CreateItem(Outlook.olAppointmentItem)

//I also would suggest changing the variable name (and references to it)
below to something besides outlook to avoid confusion between the variable
name and the Outlook namespace.

Dim outlook As Outlook.Application
"Dean Slindee" <sl*****@charter.net> wrote in message
news:eb*******************@fe04.lga...
There are two statements below marked 'ERROR that I would like to recode
to
be acceptable to Option Strict On. I tried the two statements at the
bottom, but that was not acceptable. Can anyone Help?

Dim outlook As Outlook.Application

Dim olns As Outlook.NameSpace

Dim apptItem As Outlook.AppointmentItem

Dim mailItem As Outlook.MailItem

outlook = New Outlook.ApplicationClass

olns = outlook.GetNamespace("MAPI")

mailItem = outlook.CreateItem(olMailItem) 'ERROR

apptItem = outlook.CreateItem(olAppointmentItem) 'ERROR

Cannot use statements below because Sub New() is Private:

Dim apptItem As New Outlook.AppointmentItem

Dim mailItem As New Outlook.MailItem

Thanks,

Dean Slindee

Nov 21 '05 #2
For Options Strict on, try:

mailItem = CType(outlook.CreateItem(Global.Outlook.OlItemType .olMailItem),
Global.Outlook.MailItem)
apptItem =
CType(outlook.CreateItem(Global.Outlook.OlItemType .olAppointmentItem),
Global.Outlook.AppointmentItem)

HTH
Lee

"Dean Slindee" <sl*****@charter.net> wrote in message
news:eb*******************@fe04.lga...
There are two statements below marked 'ERROR that I would like to recode
to
be acceptable to Option Strict On. I tried the two statements at the
bottom, but that was not acceptable. Can anyone Help?

Dim outlook As Outlook.Application

Dim olns As Outlook.NameSpace

Dim apptItem As Outlook.AppointmentItem

Dim mailItem As Outlook.MailItem

outlook = New Outlook.ApplicationClass

olns = outlook.GetNamespace("MAPI")

mailItem = outlook.CreateItem(olMailItem) 'ERROR

apptItem = outlook.CreateItem(olAppointmentItem) 'ERROR

Cannot use statements below because Sub New() is Private:

Dim apptItem As New Outlook.AppointmentItem

Dim mailItem As New Outlook.MailItem

Thanks,

Dean Slindee

Nov 21 '05 #3
"Dean Slindee" <sl*****@charter.net> schrieb:
There are two statements below marked 'ERROR that I would like to recode
to
be acceptable to Option Strict On. I tried the two statements at the
bottom, but that was not acceptable. Can anyone Help?

Dim outlook As Outlook.Application

Dim olns As Outlook.NameSpace

Dim apptItem As Outlook.AppointmentItem

Dim mailItem As Outlook.MailItem

outlook = New Outlook.ApplicationClass

olns = outlook.GetNamespace("MAPI")

mailItem = outlook.CreateItem(olMailItem) 'ERROR
\\\
mailItem = DirectCast(outlook.CreateItem(...), Outlook.AppointmentItem)
///
apptItem = outlook.CreateItem(olAppointmentItem) 'ERROR


\\\
.... = DirectCast(..., Outlook.MailItem)
///

In addition to that, I suggest to import the 'Outlook' namespace.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #4
Herfried,
| In addition to that, I suggest to import the 'Outlook' namespace.

With Outlook (and other Office apps) I normally use an Import Alias, to
avoid conflicts between System.Windows.Forms.Application and the Application
type in the respective office app.

For example with Outlook I normally use:

Imports Outlook = Microsoft.Office.Interop.Outlook

Then my code looks similiar to Dean's...

Hope this helps
Jay

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:OT**************@TK2MSFTNGP15.phx.gbl...
| "Dean Slindee" <sl*****@charter.net> schrieb:
| > There are two statements below marked 'ERROR that I would like to recode
| > to
| > be acceptable to Option Strict On. I tried the two statements at the
| > bottom, but that was not acceptable. Can anyone Help?
| >
| > Dim outlook As Outlook.Application
| >
| > Dim olns As Outlook.NameSpace
| >
| > Dim apptItem As Outlook.AppointmentItem
| >
| > Dim mailItem As Outlook.MailItem
| >
| > outlook = New Outlook.ApplicationClass
| >
| > olns = outlook.GetNamespace("MAPI")
| >
| > mailItem = outlook.CreateItem(olMailItem) 'ERROR
|
| \\\
| mailItem = DirectCast(outlook.CreateItem(...), Outlook.AppointmentItem)
| ///
|
| > apptItem = outlook.CreateItem(olAppointmentItem) 'ERROR
|
| \\\
| ... = DirectCast(..., Outlook.MailItem)
| ///
|
| In addition to that, I suggest to import the 'Outlook' namespace.
|
| --
| M S Herfried K. Wagner
| M V P <URL:http://dotnet.mvps.org/>
| V B <URL:http://classicvb.org/petition/>
|
Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: droope | last post by:
I have a routine that does a standard comparison that I pass two objects to Private Function ColumnEqual(ByVal A As Object, ByVal B As Object) As Boolea ' Compares two values to determine if...
2
by: Showjumper | last post by:
By turning Option Strict on, is there extra overhead? For example w/o it on the following doesnt get flagged: validxhtml.Attributes.Add("height", 22) but with it on the 22 is underlined and the...
13
by: Cor | last post by:
Hi Option Strict gurus, Because of the so much given advises here to use Option Strict I did try to use that. But it gives an error and I don't know how to resolve that. The message is that...
8
by: Clark Stevens | last post by:
I've always used Option Strict in my code. However, I was wondering if it is really necessary. Coding seems a lot easier when you don't use it, but does it really make a difference? What are the...
15
by: Marcel | last post by:
Hi, I've found some sample code to put some text into Word. I'm testing this code to learn from it, but I can't find an explanation for the use of CType in the following code. Can someone...
17
by: David | last post by:
Hi all, I have the following problem: my program works fine, but when I add option strict at the top of the form, the following sub fails with an error that option strict does not allow late...
15
by: guy | last post by:
when i first started using .net (beta 1) i came across option strict and thought hey this could be really good, and since then have always turned it on, most people here seem to agree that this is...
13
by: C. Moya | last post by:
I fully expected the lack of a way to set Option Strict globally to be fixed in SP1. I can't seem to figure out if it has been fixed or not. It still seems we have to add the declaration at the top...
1
by: Jerad Rose | last post by:
I believe this issue is specific to ASP.NET. Why does VB.NET (2.0) ignore the project-level setting for Option Strict? I have the setting turned on in web.config: <compilation debug="true"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.