Ask a questionAsk a question
 

AnswerDoes this API support VB6 or is there any alternative way?

  • Tuesday, November 03, 2009 9:56 AMRoy.Liu Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi, Everyone

    I'm writing a vb6 program, and I need to Integrate the translator feature of Bing into my code.

    I've searched the web and can't find anything about Integrating Bing Translator into VB6.

    So, here is my questions:
     
    Does this API support VB6, or is there any alternative way to use Bing Translator in VB6 without an AppID, for example, using Microsoft.XMLHTTP?

    Any answer is appreciated.

Answers

  • Friday, November 20, 2009 9:36 PMPhil Jollans Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     AnswerHas Code
    Hi,

    I have used the Microsoft Translator from VB6.

    I am not an expert on using Web Services in VB6 (or using Web Services at all), but this is what I did.
    I installed "Web Service References Tool 2.0 for Visual Basic for Applications", which works in VBA (in office applications). Using this tool, in Word VBA, I generated a class, which I then copied (with cut and paste) into a VB6 project. I have copied the complete class into the code block below.

    You will need to add a reference to MSSOAP30.dll to your project. If you distribute it, you will have to add this and a bunch of dependencies to your installation.

    Phil


    Option Explicit
    
    '*****************************************************************
    'This class was created by the Web Service References Tool 2.0.
    '
    'Created: 11/13/2009 09:11:43 PM
    '
    'Description:
    'This class is a Visual Basic for Applications class representation of the Web service
    'as defined by http://api.microsofttranslator.com/V1/SOAP.svc.
    '
    'To Use:
    'Dimension a variable as new clsws_Soap, and then write code to
    'use the methods provided by the class.
    'Example:
    ' Dim ExampleVar as New clsws_Soap
    ' debug.print ExampleVar.wsm_GetLanguages("Sample Input")
    '
    'For more information, see Complex Types in Web Service References
    'Tool 2.0 Help.
    '
    'Changes to the code in this class may result in incorrect behavior.
    '
    '*****************************************************************
    
    'Dimensioning private class variables.
    Private sc_Soap As SoapClient30
    Private Const c_WSDL_URL As String = "http://api.microsofttranslator.com/V1/SOAP.svc"
    Private Const c_SERVICE As String = "Soap"
    Private Const c_PORT As String = "BasicHttpBinding_LanguageService"
    Private Const c_SERVICE_NAMESPACE As String = "http://api.microsofttranslator.com/v1/soap.svc"
    
    Private Sub Class_Initialize()
      '*****************************************************************
      'This subroutine will be called each time the class is instantiated.
      'Creates sc_ComplexTypes as new SoapClient30, and then
      'initializes sc_ComplexTypes.mssoapinit2 with WSDL file found in
      'http://api.microsofttranslator.com/V1/SOAP.svc.
      '*****************************************************************
    
      Dim str_WSML As String
      str_WSML = ""
    
      Set sc_Soap = New SoapClient30
    
      sc_Soap.MSSoapInit2 c_WSDL_URL, str_WSML, c_SERVICE, c_PORT, c_SERVICE_NAMESPACE
      'Use the proxy server defined in Internet Explorer's LAN settings by
      'setting ProxyServer to <CURRENT_USER>
      sc_Soap.ConnectorProperty("ProxyServer") = "<CURRENT_USER>"
      'Autodetect proxy settings if Internet Explorer is set to autodetect
      'by setting EnableAutoProxy to True
      sc_Soap.ConnectorProperty("EnableAutoProxy") = True
    
    
    End Sub
    
    Private Sub Class_Terminate()
      '*****************************************************************
      'This subroutine will be called each time the class is destructed.
      'Sets sc_ComplexTypes to Nothing.
      '*****************************************************************
    
      'Error Trap
      On Error GoTo Class_TerminateTrap
    
      Set sc_Soap = Nothing
    
    Exit Sub
    
    Class_TerminateTrap:
      SoapErrorHandler ("Class_Terminate")
    End Sub
    
    Private Sub SoapErrorHandler(str_Function As String)
      '*****************************************************************
      'This subroutine is the class error handler. It can be called from any class subroutine or function
      'when that subroutine or function encounters an error. Then, it will raise the error along with the
      'name of the calling subroutine or function.
      '*****************************************************************
    
      'SOAP Error
      If sc_Soap.FaultCode <> "" Then
        Err.Raise vbObjectError, str_Function, sc_Soap.FaultString
      'Non SOAP Error
      Else
        Err.Raise Err.Number, str_Function, Err.Description
      End If
    
    End Sub
    
    Public Function wsm_GetLanguages(ByVal str_appId As String) As Variant
      '*****************************************************************
      'Proxy function created from http://api.microsofttranslator.com/V1/SOAP.svc.
      '
      '"wsm_GetLanguages" is an array with elements defined as String
      'See Complex Types: Arrays in Web Service References Tool 2.0 Help
      'for details on implementing arrays.
      '*****************************************************************
    
      'Error Trap
      On Error GoTo wsm_GetLanguagesTrap
    
      wsm_GetLanguages = sc_Soap.GetLanguages(str_appId)
    
    Exit Function
    wsm_GetLanguagesTrap:
      SoapErrorHandler "wsm_GetLanguages"
    End Function
    
    Public Function wsm_GetLanguageNames(ByVal str_appId As String, ByVal str_locale As String) As Variant
      '*****************************************************************
      'Proxy function created from http://api.microsofttranslator.com/V1/SOAP.svc.
      '
      '"wsm_GetLanguageNames" is an array with elements defined as String
      'See Complex Types: Arrays in Web Service References Tool 2.0 Help
      'for details on implementing arrays.
      '*****************************************************************
    
      'Error Trap
      On Error GoTo wsm_GetLanguageNamesTrap
    
      wsm_GetLanguageNames = sc_Soap.GetLanguageNames(str_appId, str_locale)
    
    Exit Function
    wsm_GetLanguageNamesTrap:
      SoapErrorHandler "wsm_GetLanguageNames"
    End Function
    
    Public Function wsm_Detect(ByVal str_appId As String, ByVal str_text As String) As String
      '*****************************************************************
      'Proxy function created from http://api.microsofttranslator.com/V1/SOAP.svc.
      '*****************************************************************
    
      'Error Trap
      On Error GoTo wsm_DetectTrap
    
      wsm_Detect = sc_Soap.Detect(str_appId, str_text)
    
    Exit Function
    wsm_DetectTrap:
      SoapErrorHandler "wsm_Detect"
    End Function
    
    Public Function wsm_Translate(ByVal str_appId As String, ByVal str_text As String, ByVal str_from As String, ByVal str_to As String) As String
      '*****************************************************************
      'Proxy function created from http://api.microsofttranslator.com/V1/SOAP.svc.
      '*****************************************************************
    
      'Error Trap
      On Error GoTo wsm_TranslateTrap
    
      wsm_Translate = sc_Soap.Translate(str_appId, str_text, str_from, str_to)
    
    Exit Function
    wsm_TranslateTrap:
      SoapErrorHandler "wsm_Translate"
    End Function
    
    
    
    
    

All Replies

  • Friday, November 20, 2009 9:36 PMPhil Jollans Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     AnswerHas Code
    Hi,

    I have used the Microsoft Translator from VB6.

    I am not an expert on using Web Services in VB6 (or using Web Services at all), but this is what I did.
    I installed "Web Service References Tool 2.0 for Visual Basic for Applications", which works in VBA (in office applications). Using this tool, in Word VBA, I generated a class, which I then copied (with cut and paste) into a VB6 project. I have copied the complete class into the code block below.

    You will need to add a reference to MSSOAP30.dll to your project. If you distribute it, you will have to add this and a bunch of dependencies to your installation.

    Phil


    Option Explicit
    
    '*****************************************************************
    'This class was created by the Web Service References Tool 2.0.
    '
    'Created: 11/13/2009 09:11:43 PM
    '
    'Description:
    'This class is a Visual Basic for Applications class representation of the Web service
    'as defined by http://api.microsofttranslator.com/V1/SOAP.svc.
    '
    'To Use:
    'Dimension a variable as new clsws_Soap, and then write code to
    'use the methods provided by the class.
    'Example:
    ' Dim ExampleVar as New clsws_Soap
    ' debug.print ExampleVar.wsm_GetLanguages("Sample Input")
    '
    'For more information, see Complex Types in Web Service References
    'Tool 2.0 Help.
    '
    'Changes to the code in this class may result in incorrect behavior.
    '
    '*****************************************************************
    
    'Dimensioning private class variables.
    Private sc_Soap As SoapClient30
    Private Const c_WSDL_URL As String = "http://api.microsofttranslator.com/V1/SOAP.svc"
    Private Const c_SERVICE As String = "Soap"
    Private Const c_PORT As String = "BasicHttpBinding_LanguageService"
    Private Const c_SERVICE_NAMESPACE As String = "http://api.microsofttranslator.com/v1/soap.svc"
    
    Private Sub Class_Initialize()
      '*****************************************************************
      'This subroutine will be called each time the class is instantiated.
      'Creates sc_ComplexTypes as new SoapClient30, and then
      'initializes sc_ComplexTypes.mssoapinit2 with WSDL file found in
      'http://api.microsofttranslator.com/V1/SOAP.svc.
      '*****************************************************************
    
      Dim str_WSML As String
      str_WSML = ""
    
      Set sc_Soap = New SoapClient30
    
      sc_Soap.MSSoapInit2 c_WSDL_URL, str_WSML, c_SERVICE, c_PORT, c_SERVICE_NAMESPACE
      'Use the proxy server defined in Internet Explorer's LAN settings by
      'setting ProxyServer to <CURRENT_USER>
      sc_Soap.ConnectorProperty("ProxyServer") = "<CURRENT_USER>"
      'Autodetect proxy settings if Internet Explorer is set to autodetect
      'by setting EnableAutoProxy to True
      sc_Soap.ConnectorProperty("EnableAutoProxy") = True
    
    
    End Sub
    
    Private Sub Class_Terminate()
      '*****************************************************************
      'This subroutine will be called each time the class is destructed.
      'Sets sc_ComplexTypes to Nothing.
      '*****************************************************************
    
      'Error Trap
      On Error GoTo Class_TerminateTrap
    
      Set sc_Soap = Nothing
    
    Exit Sub
    
    Class_TerminateTrap:
      SoapErrorHandler ("Class_Terminate")
    End Sub
    
    Private Sub SoapErrorHandler(str_Function As String)
      '*****************************************************************
      'This subroutine is the class error handler. It can be called from any class subroutine or function
      'when that subroutine or function encounters an error. Then, it will raise the error along with the
      'name of the calling subroutine or function.
      '*****************************************************************
    
      'SOAP Error
      If sc_Soap.FaultCode <> "" Then
        Err.Raise vbObjectError, str_Function, sc_Soap.FaultString
      'Non SOAP Error
      Else
        Err.Raise Err.Number, str_Function, Err.Description
      End If
    
    End Sub
    
    Public Function wsm_GetLanguages(ByVal str_appId As String) As Variant
      '*****************************************************************
      'Proxy function created from http://api.microsofttranslator.com/V1/SOAP.svc.
      '
      '"wsm_GetLanguages" is an array with elements defined as String
      'See Complex Types: Arrays in Web Service References Tool 2.0 Help
      'for details on implementing arrays.
      '*****************************************************************
    
      'Error Trap
      On Error GoTo wsm_GetLanguagesTrap
    
      wsm_GetLanguages = sc_Soap.GetLanguages(str_appId)
    
    Exit Function
    wsm_GetLanguagesTrap:
      SoapErrorHandler "wsm_GetLanguages"
    End Function
    
    Public Function wsm_GetLanguageNames(ByVal str_appId As String, ByVal str_locale As String) As Variant
      '*****************************************************************
      'Proxy function created from http://api.microsofttranslator.com/V1/SOAP.svc.
      '
      '"wsm_GetLanguageNames" is an array with elements defined as String
      'See Complex Types: Arrays in Web Service References Tool 2.0 Help
      'for details on implementing arrays.
      '*****************************************************************
    
      'Error Trap
      On Error GoTo wsm_GetLanguageNamesTrap
    
      wsm_GetLanguageNames = sc_Soap.GetLanguageNames(str_appId, str_locale)
    
    Exit Function
    wsm_GetLanguageNamesTrap:
      SoapErrorHandler "wsm_GetLanguageNames"
    End Function
    
    Public Function wsm_Detect(ByVal str_appId As String, ByVal str_text As String) As String
      '*****************************************************************
      'Proxy function created from http://api.microsofttranslator.com/V1/SOAP.svc.
      '*****************************************************************
    
      'Error Trap
      On Error GoTo wsm_DetectTrap
    
      wsm_Detect = sc_Soap.Detect(str_appId, str_text)
    
    Exit Function
    wsm_DetectTrap:
      SoapErrorHandler "wsm_Detect"
    End Function
    
    Public Function wsm_Translate(ByVal str_appId As String, ByVal str_text As String, ByVal str_from As String, ByVal str_to As String) As String
      '*****************************************************************
      'Proxy function created from http://api.microsofttranslator.com/V1/SOAP.svc.
      '*****************************************************************
    
      'Error Trap
      On Error GoTo wsm_TranslateTrap
    
      wsm_Translate = sc_Soap.Translate(str_appId, str_text, str_from, str_to)
    
    Exit Function
    wsm_TranslateTrap:
      SoapErrorHandler "wsm_Translate"
    End Function