SPONSORS:






User Tag List

Thanks Thanks:  0
Likes Likes:  0
Dislikes Dislikes:  0
Results 1 to 2 of 2
  1. #1
    Member
    Join Date
    Nov 2001
    Location
    Houston, Tx, USA
    Posts
    59
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    How to convert VB code to VT...

    Okay, long time listener - first time caller! [img]images/icons/smile.gif[/img]

    I am needing some help with converting the following VB script (sends email) to VT:

    'SEND MAIL AND OUTPUT THANK YOU RESPONSE
    Const cdoSendUsingPort = 2
    Const strSMTPHost = "1.2.3.4"

    Dim iMsg
    Dim iConf
    Dim Flds

    'Create the message object
    Set iMsg = CreateObject("CDO.Message")

    'Create the configuration object
    Set iConf = iMsg.Configuration

    'Set the fields of the configuration object to send using SMTP via port 25.
    With iConf.Fields
    .item("http://schemas.microsoft.com/cdo/configuration/sendusing") =
    cdoSendUsingPort
    .item("http://schemas.microsoft.com/cdo/configuration/smtpserver") =
    strSMTPHost
    .Update
    End With

    'Set the message to,from,subject,body properties.
    With iMsg
    .To = "someone@s..."
    .From = "someone@h..."
    .Subject = "Test message using CDOEx and cdoSendUsingPort, sent on: " &
    now()
    .TextBody = "This is a test using CDOEx and cdoSendUsingPort, sent on: "
    & now()
    .Send
    End With

    'test for success/failure
    If Err.Number <> 0 Then
    'an error occurred so output error message
    MsgBox "Sorry, the following error occurred: " & Err.Description

    Else
    'success!
    MsgBox "Your email message has been sent successfully."
    End If

    'release objects
    Set iConf = Nothing
    Set iMsg = Nothing

    Now so far I have coded the following function for use in Visual Test but I am
    getting an invalid object error message from this line of code: iConf =
    OleCreateObject ("CDO.Configuration")


    Function SendCDOMail& (sFrom$, sTo$, sCc$, sSubject$, sBody$, sHTMLBody$,
    sAttach$)

    Dim iMsg As Variant, iConf As Variant, Flds As Variant
    Dim sSMTPServer$, iPort$, iSMTP$, iTimeout$

    sSMTPServer$ = "1.2.3.4"
    iPort$ = "Item(" + Chr(34) +
    "http://schemas.microsoft.com/cdo/configuration/sendusing" + Chr(34) + ")"
    iSMTP$ = "Item(" + Chr(34) +
    "http://schemas.microsoft.com/cdo/configuration/smtpserver" + Chr(34) + ")"
    iTimeout$ = "Item(" + Chr(34) +
    "http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout" +
    Chr(34) + ")"

    ' Set iMsg = CreateObject("CDO.Message")
    iMsg = OleCreateObject ("CDO.Message")

    ' Set iConf = CreateObject("CDO.Configuration")
    iConf = OleCreateObject ("CDO.Configuration")

    ' Set Flds = iConf.Fields
    Flds = OleCreateObject (iConf, "Fields") ' I have also tried using
    OleSetProperty (Flds, iConf, "Fields") but this also returns an OLE error!

    ' Set the CDOSYS configuration fields to use port 25 on the SMTP server.
    OleSetProperty (Flds, iPort, cdoSendUsingPort)
    OleSetProperty (Flds, iSMTP, cdoSMTPServer)
    OleSetProperty (Flds, iTimeout, 10)
    OleDispatch (Flds, "Update")


    ' Apply the settings to the message.
    OleSetProperty (iMsg, "Configuration", iConf)
    OleSetProperty (iMsg, "To", sTo)
    OleSetProperty (iMsg, "CC", sCc)
    OleSetProperty (iMsg, "From", sFrom)
    OleSetProperty (iMsg, "Subject", sSubject)
    OleSetProperty (iMsg, "HTMLBody", sHTMLBody)

    If sAttach$ <> "" Then
    OleSetProperty (iMsg, "AddAttachment", sAttach)
    End If

    OleDispatch (iMsg, "Send")
    Release_Objects (Flds, iConf, iMsg)
    SendCDOMail = TRUE

    End Function


    Michael Shepherd
    Senior Quality Assurance Specialist
    Michael - Armageddon was yesterday, today we have a serious problem!

  2. #2
    SQA Knight
    Join Date
    Sep 2001
    Location
    Bangalore,India
    Posts
    2,549
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: How to convert VB code to VT...

    Hi,
    You have used DLLs. You can convert entire code into VT. Two yrs back, I have used MS XML Parser(DOM).
    Original code(VB) is,
    'Create the configuration object
    Set iConf = iMsg.Configuration

    But your VT code is.
    ' Set iConf = CreateObject("CDO.Configuration")
    iConf = OleCreateObject ("CDO.Configuration")

    You are not using iMsg variable. This is the pbm.....You have to use OleDispatch with iMsg...
    Thanks & Regards,
    Palani.
    http://tips-testing.blogspot.com/index.html
    Quote: Donít hesitate to initiate!

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Resources saved on this page: MySQL 12.50%
vBulletin Optimisation provided by vB Optimise v2.6.4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.2.8 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominate (Lite) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 10:05 AM.

Copyright BetaSoft Inc.