Click here to Skip to main content
15,896,408 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Change mac address by vba Pin
Gerry Schmitz24-Dec-20 5:14
mveGerry Schmitz24-Dec-20 5:14 
GeneralRe: Change mac address by vba Pin
Dave Kreskowiak24-Dec-20 5:21
mveDave Kreskowiak24-Dec-20 5:21 
AnswerRe: Change mac address by vba Pin
Richard MacCutchan23-Dec-20 21:54
mveRichard MacCutchan23-Dec-20 21:54 
AnswerRe: Change mac address by vba Pin
Gerry Schmitz24-Dec-20 5:07
mveGerry Schmitz24-Dec-20 5:07 
QuestionIs there Access VBA method of translating text in a textbox? Pin
Member 1181158314-Dec-20 3:18
Member 1181158314-Dec-20 3:18 
AnswerRe: Is there Access VBA method of translating text in a textbox? Pin
Richard Deeming14-Dec-20 4:02
mveRichard Deeming14-Dec-20 4:02 
GeneralRe: Is there Access VBA method of translating text in a textbox? Pin
Member 1181158314-Dec-20 4:56
Member 1181158314-Dec-20 4:56 
GeneralRe: Is there Access VBA method of translating text in a textbox? Pin
Member 1181158314-Dec-20 11:41
Member 1181158314-Dec-20 11:41 
' The following code is working for me.
' I have adapted, and converted to Access VBA, some Excel VBA code suggested at https://www.mrexcel.com/board/threads/google-translate-excel-vba.1079457/
' Thanks to Dossfm0q on July 24th 2020 This seems to be executing an instance of Mozilla Firefox.
' I do have Firefox installed and it's my default browser. Not sure if this is relevant.
' While I could not get Dossfm0q's code to work, I noticed that the text in objHTTP.ResponseText DID in his code in fact contain the translated text,
' and that this occurred between the string div class="result-container" just before it and /div just after it.
' so I altered his function to strResponseText() and wrote a function GetTranslatedTextFrom(ResponseText As String) As String to obtain the translated text.
' I am sure that this is less elegant than Dossfm0q's use of objHTML.getElementsByTagName("div") ,
' but since that did not work for me, I had no choice.
VB
<pre lang="vb">



VB
'Access VBA Code

'--- Public Function SiftResponseText()
Public Function GetTranslatedTextFrom(TextToTranslate As String, FromLangCode As String, ToLangCode As String) As String    'input text maximum seems to be 2048 characters
' REQUIRED: Set a reference to Microsoft Internet Controls from Tools/References in VBA interface
'[This Function:]  Identifies the translated output text by seeking the prefix     <div class="result-container"> just before it and </div> just after it.
'[Called by:]    ' [Calls:] strResponseText()
'[Example Call:]  GetTranslatedTextFrom("Hello World! Are you ready for us?","en","fr")  This returns : "Bonjour le monde! Êtes-vous prêt pour nous?"
'[Notes:] Here are some language codes: English en, French fr, Italian it, German de , Spanish es .
' Other language codes here: https://www.labnol.org/code/19899-google-translate-languages
' Created: 12/14/2020   Modifications History:
On Error GoTo Get_Err
Dim ResponseText As String
Dim GotAnError As Boolean, PosPrefix As Long, PosAfterPrefix As Long, LenPrefix As Long, PosSuffix As Long, lenSuffix As Long
Dim Prefix As String, Suffix As String
    GotAnError = False
    
    '[] Get the response text from the Google translate website by calling strResponseText()
    ResponseText = strResponseText(TextToTranslate, FromLangCode, ToLangCode)
    
    '[] Establish the looked-for Prefix and Suffix and their lengths
    Prefix = "<div class=""result-container"">"
    LenPrefix = Len(Prefix)
    Suffix = "</div"   ' the first occurring after the Prefix
    lenSuffix = Len(Suffix)
    
    '[] Find the Prefix and the Suffix
    PosPrefix = InStr(1, ResponseText, Prefix)
    If PosPrefix = 0 Then MsgBox "Failed!": GoTo PreExit
    PosAfterPrefix = PosPrefix + LenPrefix
    PosSuffix = InStr(PosPrefix, ResponseText, Suffix)
    
    '[] Get the translated text as the function's return value
    GetTranslatedTextFrom = Mid(ResponseText, PosAfterPrefix, PosSuffix - PosAfterPrefix)

PreExit:
    'If Not GotAnError then MsgBox  "Success." , vbokonly , " Sub: SiftResponseText"
Exit Function
' ---------------------
Get_Err:
    GotAnError = True
    MsgBox str(Err) & " " & Err.Description, vbOKOnly, "Error in Sub: [SiftResponseText]"
    Resume PreExit
    'Resume Next  'for diagnostic purposes only
End Function
' ==============================================


Public Function strResponseText(strInput As String, FrmLng As String, ToLng As String) As String
'[This Function:]    Inputs a text, probable maximum 2048 characters, with the From-Language and the To-Language codes,
' Sends a request to https://translate.google.com,  and returns a response text; and returns a response text from the website.
' There is probably a limit to how much use is made of this operation without Google requiring payment
'  Outputs a ResponseText that can be used by GetTranslatedTextFrom() to find the translated text.
'[Called by:]  GetTranslatedTextFrom()  ' [Calls:] ' [Example Call:]   RespText = strResponseText("Hello World! Are you ready for us?","en","fr")
'[Notes:]
'Created: 12/14/2020   Modifications History: Adapted from GgTranslate() in https://www.mrexcel.com/board/threads/google-translate-excel-vba.1079457/ originally by Dossfm0q of July 24th 2020

On Error GoTo Goo_Err
Dim GotAnError As Boolean
    GotAnError = False
    
    Dim strURL As String
    Dim objHTTP As Object
    Dim objHTML As Object
    Dim objDivs As Object, objDiv As Object
    Dim strTranslated As String
    
    '[] Send query to web page
    strURL = "https://translate.google.com/m?hl=" & FrmLng & _
            "&sl=" & FrmLng & _
            "&tl=" & ToLng & _
            "&ie=UTF-8&prev=_m&q=" & strInput

    Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP") 'late binding
    objHTTP.Open "GET", strURL, False
    objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
    objHTTP.send ""
    
    '[] Create an html document
    Set objHTML = CreateObject("htmlfile")
    With objHTML
            .Open
            .Write objHTTP.ResponseText
            strResponseText = objHTTP.ResponseText
            .Close
    End With
    
' The following text was commented out by me from Dossfm0q's code as I could not get it to work
'    Set objDivs = objHTML.getElementsByTagName("div")    'This looks like a div-block parsing function for objHTTP
'    For Each objDiv In objDivs
'        If objDiv.className = "t0" Then
'            strTranslated = objDiv.innerText
'            If strTranslated <> "" Then GoogTranslate = strTranslated
'            Msgbox "GoogTranslate="; GoogTranslate           'This never happened
'        End If
'    Next objDiv

    Set objHTML = Nothing
    Set objHTTP = Nothing
    
PreExit:
    'If Not GotAnError then MsgBox  "Success." , vbokonly , " Sub: GoogTranslate"
Exit Function
' ---------------------
Goo_Err:
    GotAnError = True
    MsgBox str(Err) & " " & Err.Description, vbOKOnly, "Error in Sub: [GoogTranslate]"
    Resume PreExit
    Resume Next
End Function
' ==============================================

QuestionVisual Studio RDLC expression editor in the report designer and help with expressions Pin
jkirkerx5-Dec-20 10:26
professionaljkirkerx5-Dec-20 10:26 
AnswerRe: Visual Studio RDLC expression editor in the report designer and help with expressions Pin
jkirkerx5-Dec-20 13:10
professionaljkirkerx5-Dec-20 13:10 
AnswerRe: Visual Studio RDLC expression editor in the report designer and help with expressions [solved] Pin
jkirkerx6-Dec-20 9:35
professionaljkirkerx6-Dec-20 9:35 
QuestionCall a method inside a Task.Run and return the value Pin
Mc_Topaz2-Dec-20 3:03
Mc_Topaz2-Dec-20 3:03 
AnswerRe: Call a method inside a Task.Run and return the value Pin
Richard MacCutchan2-Dec-20 3:23
mveRichard MacCutchan2-Dec-20 3:23 
AnswerRe: Call a method inside a Task.Run and return the value Pin
Gerry Schmitz2-Dec-20 5:23
mveGerry Schmitz2-Dec-20 5:23 
Questionvb.net addin won't run in release mode Pin
JR21230-Nov-20 23:53
JR21230-Nov-20 23:53 
AnswerRe: vb.net addin won't run in release mode Pin
BabyYoda1-Dec-20 5:53
BabyYoda1-Dec-20 5:53 
GeneralRe: vb.net addin won't run in release mode Pin
JR2121-Dec-20 6:22
JR2121-Dec-20 6:22 
QuestionRe: vb.net addin won't run in release mode Pin
Richard MacCutchan1-Dec-20 6:36
mveRichard MacCutchan1-Dec-20 6:36 
QuestionCreate Multi Series Chart in VB.net Pin
Member 1500024122-Nov-20 21:46
Member 1500024122-Nov-20 21:46 
AnswerRe: Create Multi Series Chart in VB.net Pin
Richard Deeming22-Nov-20 22:22
mveRichard Deeming22-Nov-20 22:22 
Questionneed some guidance and advice to build a questionnaire system similar to Google forms in vb.net or c# and sql server Pin
albasheer210019-Nov-20 18:05
albasheer210019-Nov-20 18:05 
AnswerRe: need some guidance and advice to build a questionnaire system similar to Google forms in vb.net or c# and sql server Pin
Richard MacCutchan19-Nov-20 22:14
mveRichard MacCutchan19-Nov-20 22:14 
AnswerRe: need some guidance and advice to build a questionnaire system similar to Google forms in vb.net or c# and sql server Pin
CHill6020-Nov-20 1:59
mveCHill6020-Nov-20 1:59 
QuestionSend a file via a bot telegram vb.net Pin
Member 1496222414-Nov-20 11:33
Member 1496222414-Nov-20 11:33 
AnswerRe: Send a file via a bot telegram vb.net Pin
Dave Kreskowiak14-Nov-20 12:14
mveDave Kreskowiak14-Nov-20 12:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.