Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Sam Sam is offline
external usenet poster
 
Posts: 2
Default Excel-Web Queries to Babelfish

Hi

I have tried an example that has been floating around this newsgroup

It seems to work except for the fact that it seems that the text sent back
to me is truncated??

Anyone seen this problem???

Thanks

Code
------

Enum TranslateLanguages
Eng_Fren = 1
Eng_Ger = 2
Eng_Ita = 3
Eng_Port = 4
Eng_Span = 5
Fren_Eng = 6
Fren_Ger = 7
Ger_Eng = 8
Ger_Fren = 9
Ita_Eng = 10
Port_Eng = 11
Span_Eng = 12
End Enum

Public Function gsTranslateText(rsTextToTranslate, rMode As
TranslateLanguages) As String
Dim xml As XMLHTTP30
Dim abytPostData() As Byte
Dim sMode As String
Dim sResponse As String
Dim nStartPos As Integer
Dim nEndPos As Integer


Select Case rMode
Case Eng_Fren
sMode = "en_fr"
Case Eng_Ger
sMode = "en_de"
Case Eng_Ita
sMode = "en_it"
Case Eng_Port
sMode = "en_pt"
Case Eng_Span
sMode = "en_es"
Case Fren_Eng
sMode = "fr_en"
Case Fren_Ger
sMode = "fr_de"
Case Ger_Eng
sMode = "de_en"
Case Ger_Fren
sMode = "de_fr"
Case Ita_Eng
sMode = "it_en"
Case Port_Eng
sMode = "pt_en"
Case Span_Eng
sMode = "es_en"
End Select

abytPostData = StrConv("doit=done&intl=1" _
& "&tt=urltext&lp=" & sMode & "&urltext=" _
& rsTextToTranslate, vbFromUnicode)

Set xml = New XMLHTTP30
With xml
.open "POST", "http://babelfish.altavista.com/babelfish/tr"
.setRequestHeader "Content-Type",
"application/x-www-form-urlencoded"
.send abytPostData
Do While .readyState < 4
DoEvents
Loop
sResponse = .responseText

End With

'/ find translation
nStartPos = InStr(1, sResponse, "lang=" & _
Right$(sMode, 2), vbTextCompare)
If nStartPos Then
nStartPos = nStartPos + 8
nEndPos = InStr(nStartPos, sResponse, _
"</div", vbTextCompare) - 1
If nEndPos = nStartPos Then gsTranslateText = _
Mid$(sResponse, nStartPos, nEndPos - _
nStartPos + 1)
End If

Set xml = Nothing
End Function

Text Back
---------



<html<head<titleAltaVista - Babel Fish Translation - Translated
Text</title
<meta name="description" content="AltaVista Babel Fish provides the online
text and web page language translation!"
<meta name="keywords" content="translation transl


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default Excel-Web Queries to Babelfish

What do you get if you just do

Msgbox .responseText

once the request completes? Is that truncated or is it happening in your
downstream code ?


Tim


"Sam" wrote in message
...
Hi

I have tried an example that has been floating around this newsgroup

It seems to work except for the fact that it seems that the text sent back
to me is truncated??

Anyone seen this problem???

Thanks

Code
------

Enum TranslateLanguages
Eng_Fren = 1
Eng_Ger = 2
Eng_Ita = 3
Eng_Port = 4
Eng_Span = 5
Fren_Eng = 6
Fren_Ger = 7
Ger_Eng = 8
Ger_Fren = 9
Ita_Eng = 10
Port_Eng = 11
Span_Eng = 12
End Enum

Public Function gsTranslateText(rsTextToTranslate, rMode As
TranslateLanguages) As String
Dim xml As XMLHTTP30
Dim abytPostData() As Byte
Dim sMode As String
Dim sResponse As String
Dim nStartPos As Integer
Dim nEndPos As Integer


Select Case rMode
Case Eng_Fren
sMode = "en_fr"
Case Eng_Ger
sMode = "en_de"
Case Eng_Ita
sMode = "en_it"
Case Eng_Port
sMode = "en_pt"
Case Eng_Span
sMode = "en_es"
Case Fren_Eng
sMode = "fr_en"
Case Fren_Ger
sMode = "fr_de"
Case Ger_Eng
sMode = "de_en"
Case Ger_Fren
sMode = "de_fr"
Case Ita_Eng
sMode = "it_en"
Case Port_Eng
sMode = "pt_en"
Case Span_Eng
sMode = "es_en"
End Select

abytPostData = StrConv("doit=done&intl=1" _
& "&tt=urltext&lp=" & sMode & "&urltext=" _
& rsTextToTranslate, vbFromUnicode)

Set xml = New XMLHTTP30
With xml
.open "POST", "http://babelfish.altavista.com/babelfish/tr"
.setRequestHeader "Content-Type",
"application/x-www-form-urlencoded"
.send abytPostData
Do While .readyState < 4
DoEvents
Loop
sResponse = .responseText

End With

'/ find translation
nStartPos = InStr(1, sResponse, "lang=" & _
Right$(sMode, 2), vbTextCompare)
If nStartPos Then
nStartPos = nStartPos + 8
nEndPos = InStr(nStartPos, sResponse, _
"</div", vbTextCompare) - 1
If nEndPos = nStartPos Then gsTranslateText = _
Mid$(sResponse, nStartPos, nEndPos - _
nStartPos + 1)
End If

Set xml = Nothing
End Function

Text Back
---------



<html<head<titleAltaVista - Babel Fish Translation - Translated
Text</title
<meta name="description" content="AltaVista Babel Fish provides the online
text and web page language translation!"
<meta name="keywords" content="translation transl



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Excel-Web Queries to Babelfish

Sam,
"lang=" is not (currently anyway) in the source returned from BabelFish
There's probably a better way, but this get the returned text
<Code
'First find the 2nd occurrence of "class=s"
nStartPos = InStr(1, sResponse, "class=s", vbTextCompare)
nStartPos = InStr(nStartPos + 1, sResponse, "class=s", vbTextCompare)

If nStartPos 0 Then
nStartPos = nStartPos + 33

nEndPos = InStr(nStartPos, sResponse, "</div", vbTextCompare) - 1

If nEndPos nStartPos Then
gsTranslateText = Mid$(sResponse, nStartPos, nEndPos - nStartPos
+ 1)
End If
End If
</Code

NickHK

"Sam" wrote in message
...
Hi

I have tried an example that has been floating around this newsgroup

It seems to work except for the fact that it seems that the text sent back
to me is truncated??

Anyone seen this problem???

Thanks

Code
------

Enum TranslateLanguages
Eng_Fren = 1
Eng_Ger = 2
Eng_Ita = 3
Eng_Port = 4
Eng_Span = 5
Fren_Eng = 6
Fren_Ger = 7
Ger_Eng = 8
Ger_Fren = 9
Ita_Eng = 10
Port_Eng = 11
Span_Eng = 12
End Enum

Public Function gsTranslateText(rsTextToTranslate, rMode As
TranslateLanguages) As String
Dim xml As XMLHTTP30
Dim abytPostData() As Byte
Dim sMode As String
Dim sResponse As String
Dim nStartPos As Integer
Dim nEndPos As Integer


Select Case rMode
Case Eng_Fren
sMode = "en_fr"
Case Eng_Ger
sMode = "en_de"
Case Eng_Ita
sMode = "en_it"
Case Eng_Port
sMode = "en_pt"
Case Eng_Span
sMode = "en_es"
Case Fren_Eng
sMode = "fr_en"
Case Fren_Ger
sMode = "fr_de"
Case Ger_Eng
sMode = "de_en"
Case Ger_Fren
sMode = "de_fr"
Case Ita_Eng
sMode = "it_en"
Case Port_Eng
sMode = "pt_en"
Case Span_Eng
sMode = "es_en"
End Select

abytPostData = StrConv("doit=done&intl=1" _
& "&tt=urltext&lp=" & sMode & "&urltext=" _
& rsTextToTranslate, vbFromUnicode)

Set xml = New XMLHTTP30
With xml
.open "POST", "http://babelfish.altavista.com/babelfish/tr"
.setRequestHeader "Content-Type",
"application/x-www-form-urlencoded"
.send abytPostData
Do While .readyState < 4
DoEvents
Loop
sResponse = .responseText

End With

'/ find translation
nStartPos = InStr(1, sResponse, "lang=" & _
Right$(sMode, 2), vbTextCompare)
If nStartPos Then
nStartPos = nStartPos + 8
nEndPos = InStr(nStartPos, sResponse, _
"</div", vbTextCompare) - 1
If nEndPos = nStartPos Then gsTranslateText = _
Mid$(sResponse, nStartPos, nEndPos - _
nStartPos + 1)
End If

Set xml = Nothing
End Function

Text Back
---------



<html<head<titleAltaVista - Babel Fish Translation - Translated
Text</title
<meta name="description" content="AltaVista Babel Fish provides the online
text and web page language translation!"
<meta name="keywords" content="translation transl




  #4   Report Post  
Posted to microsoft.public.excel.programming
Sam Sam is offline
external usenet poster
 
Posts: 2
Default Excel-Web Queries to Babelfish

Hi thanks for your reply

The text I get back in
sResponse = .responseText

Is at the end of my post - It looks like I am only getting only part of the
data???

"Tim Williams" <saxifrax at pacbell dot net wrote in message
...
What do you get if you just do

Msgbox .responseText

once the request completes? Is that truncated or is it happening in your
downstream code ?


Tim


"Sam" wrote in message
...
Hi

I have tried an example that has been floating around this newsgroup

It seems to work except for the fact that it seems that the text sent
back to me is truncated??

Anyone seen this problem???

Thanks

Code
------

Enum TranslateLanguages
Eng_Fren = 1
Eng_Ger = 2
Eng_Ita = 3
Eng_Port = 4
Eng_Span = 5
Fren_Eng = 6
Fren_Ger = 7
Ger_Eng = 8
Ger_Fren = 9
Ita_Eng = 10
Port_Eng = 11
Span_Eng = 12
End Enum

Public Function gsTranslateText(rsTextToTranslate, rMode As
TranslateLanguages) As String
Dim xml As XMLHTTP30
Dim abytPostData() As Byte
Dim sMode As String
Dim sResponse As String
Dim nStartPos As Integer
Dim nEndPos As Integer


Select Case rMode
Case Eng_Fren
sMode = "en_fr"
Case Eng_Ger
sMode = "en_de"
Case Eng_Ita
sMode = "en_it"
Case Eng_Port
sMode = "en_pt"
Case Eng_Span
sMode = "en_es"
Case Fren_Eng
sMode = "fr_en"
Case Fren_Ger
sMode = "fr_de"
Case Ger_Eng
sMode = "de_en"
Case Ger_Fren
sMode = "de_fr"
Case Ita_Eng
sMode = "it_en"
Case Port_Eng
sMode = "pt_en"
Case Span_Eng
sMode = "es_en"
End Select

abytPostData = StrConv("doit=done&intl=1" _
& "&tt=urltext&lp=" & sMode & "&urltext=" _
& rsTextToTranslate, vbFromUnicode)

Set xml = New XMLHTTP30
With xml
.open "POST", "http://babelfish.altavista.com/babelfish/tr"
.setRequestHeader "Content-Type",
"application/x-www-form-urlencoded"
.send abytPostData
Do While .readyState < 4
DoEvents
Loop
sResponse = .responseText

End With

'/ find translation
nStartPos = InStr(1, sResponse, "lang=" & _
Right$(sMode, 2), vbTextCompare)
If nStartPos Then
nStartPos = nStartPos + 8
nEndPos = InStr(nStartPos, sResponse, _
"</div", vbTextCompare) - 1
If nEndPos = nStartPos Then gsTranslateText = _
Mid$(sResponse, nStartPos, nEndPos - _
nStartPos + 1)
End If

Set xml = Nothing
End Function

Text Back
---------



<html<head<titleAltaVista - Babel Fish Translation - Translated
Text</title
<meta name="description" content="AltaVista Babel Fish provides the
online text and web page language translation!"
<meta name="keywords" content="translation transl





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
queries in excel gaby elia Excel Discussion (Misc queries) 2 June 2nd 08 01:37 PM
Excel Queries Anselmo Links and Linking in Excel 4 July 14th 06 11:45 PM
excel queries vivitz Excel Programming 1 June 24th 04 12:27 PM
Excel-Web Queries M Excel Programming 5 February 6th 04 03:44 PM
Excel Queries. Dinesh[_2_] Excel Programming 5 September 24th 03 06:18 PM


All times are GMT +1. The time now is 03:42 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"