我找到了几个表单的aspx代码,其中包括使用“Set”函数。当我在托管服务器上尝试它们时,我收到一条错误消息“不再支持Set”。有人知道什么取代了“Set”命令吗?
更具体地说,我该如何改变:
Dim mail
Set mail = Server.CreateObject("CDONTS.NewMail")
mail.To = EmailTo
mail.From = EmailFrom
mail.Subject = Subject
mail.Body = Body
mail.Send
与VB.NET兼容吗?
答案 0 :(得分:14)
如果你的意思是VB6语法
Set obj = new Object
然后你可以简单地删除Set
obj = new Object()
答案 1 :(得分:6)
Set是VB6中的一个关键字,随着VB.NET的引入,该关键字被删除了。
以前,Set用于表示正在分配对象引用(Let是默认值)。由于默认属性不再受支持,除非它们接受参数,否则这些语句已被删除。
Module Module1
Sub Main()
Dim person As New Person("Peter")
Dim people As New People()
people.Add(person)
'Use the default property, provided we have a parameter'
Dim p = people("Peter")
End Sub
End Module
Public Class People
Private _people As New Dictionary(Of String, Person)
Public Sub Add(ByVal person As Person)
_people.Add(person.Name, person)
End Sub
Default Public ReadOnly Property Person(ByVal name As String) As Person
Get
Return _people(name)
End Get
End Property
End Class
Public Class Person
Private _name As String
Public Sub New(ByVal name As String)
_name = name
End Sub
Public ReadOnly Property Name() As String
Get
Return _name
End Get
End Property
End Class
答案 2 :(得分:4)
要记住的一些事情.Net:
Option Infer
linq类型事实上,在.Net中你可以完全摆脱CDONTS的依赖,因为.Net有内置的邮件支持:
Dim smtp As New System.Net.SmtpClient()
Dim message As New System.Net.MailMessage(EmailFrom, EmailTo, Subject, Body)
smtp.Send(message)