What did VB replace the install function?

I found several aspx codes for forms that include the use of the "Set" function. When I test them on the hosting server, the error message "Set is no longer supported." Does anyone know what replaced the "Set" command?

In particular, how can I change this:

Dim mail 
Set mail = Server.CreateObject("CDONTS.NewMail") 
mail.To = EmailTo 
mail.From = EmailFrom 
mail.Subject = Subject 
mail.Body = Body 
mail.Send

compatible with vb.net?

+5
source share
3 answers

If you mean the syntax of VB6

Set obj = new Object

then you can just delete Set

obj = new Object()
+13
source

Set is a keyword in VB6, with the introduction of VB.NET, the keyword used in this context has been removed.

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
+6

Some things to remember .Net:

  • NEVER use Server.CreateObject () in .Net code. Someday.
  • NEVER reduce a variable without explicitly specifying it. Except for new Option Inferlinq types
  • NEVER use the Set keyword. Save property definition.

In fact, in .Net you can completely get rid of the CDONTS dependency, since .NET has built-in mail support:

Dim smtp As New System.Net.SmtpClient()
Dim message As New System.Net.MailMessage(EmailFrom, EmailTo, Subject, Body)
smtp.Send(message)
+3
source

All Articles