Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

xanburzum

[Resolvido] Tradutor

Recommended Posts

Em um banco de dados com a seguinte estrutura.

 

nome db: dicionario.mdb

nome da tabela: dicionario_English

campos:

PALAVRA - texto

TRADUCAO - texto

 

abaixo sehue um tradutor simples, traduz de português/inglês e inglês/português, lógica simples,apenas SQL usando o LIKE.

 

SELECT PALAVRA, TRADUCAO FROM dicionario_English WHERE PALAVRA LIKE '%" & strSearch & "%' " OR TRADUCAO LIKE '%" & strSearch & "%' " ORDER BY TRADUCAO

 

abaixo o codigo:

 

<%

Dim strURL	 
			 

Dim cnnSearch 
Dim rstSearch  
Dim strDBPath  

Dim strSQL	
Dim strSearch  
inicio = Timer

'#Função que tira todos os acentos das palavras
function TiraAcento(StrAcento)
 for i = 1 to len(StrAcento) 
  Letra = mid(StrAcento, i, 1)
  Select Case Letra
   Case "á","Á","à","À","ã","Ã","â","Â","â","ä","Ä"
   Letra = "A"
   Case "é","É","ê","Ê","Ë","ë","È","è"
   Letra = "E"
   Case "í","Í","ï","Ï","Ì","ì"
   Letra = "I"
   Case "ó","Ó","ô","Ô","õ","Õ","ö","Ö","ò","Ò"
   Letra = "O"
   Case "ú","Ú","Ù","ù","ú","û","ü","Ü","Û"
   Letra = "U"
   Case "ç","Ç"
   Letra = "C"
   Case "ñ"
   Letra = "N"
  End Select
  texto = texto & Letra
 next
 TiraAcento = texto
end function 


strURL = Request.ServerVariables("URL")

strSearch = Request.QueryString("search")

%>
<p> </p>
<table width="43%" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#F2FFF2">
<tr>
	<td><table width="100%" border="0" cellspacing="2" cellpadding="2">
<tr>
		  <td bgcolor="#FFFFFF"><p align="center"><FONT color=royalblue face=Tahoma size=2><STRONG><font color="#000033">:: 
			  Tradutor Inglês/Português/Português/Inglês 
			  ::</font></STRONG></FONT></p>
			<form action="<%= strURL %>" method="get">
			  <div align="center"> 
				<input name="search" value="<%= strSearch %>" />
				<input name="submit" type="submit" value="Pesquisar" />
			  </div>
			</form>
			<p align="center"> 
			  <%
If strSearch <> "" Then

	strDBPath = Server.MapPath("dic.mdb")

Const adUseClient = 3
	
	Set cnnSearch = Server.CreateObject("ADODB.Connection")
	
cnnSearch.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & ";"
cnnSearch.CursorLocation = adUseClient


	strSQL = "SELECT PALAVRA, TRADUCAO " _
		& "FROM dicionario_English " _
		& "WHERE PALAVRA LIKE '%" & TiraAcento(Replace(strSearch, "'", "''")) & "%' " _
		& "OR TRADUCAO LIKE '%" & TiraAcento(Replace(strSearch, "'", "''")) & "%' " _
		& "ORDER BY TRADUCAO;"

	Set rstSearch = cnnSearch.Execute(strSQL)
intContador = rstSearch.RecordCount
	
	%>
			</p></td>
		</tr>
	  </table>
	  <p align="center"><br>
		<font size="1" face="Verdana, Arial, Helvetica, sans-serif">[ Foram encontradas <b><%=intContador%></b> 
		ocorrências ] </font> </p>
	  <div align="center">
	<table width="312" border="0" cellpadding="4" cellspacing="1" bgcolor="#F3F3F3"><tr><th width="79" bgcolor="#FF6600"><FONT color=royalblue face=Tahoma size=2><STRONG><font color="#FFFFFF">:: 
	 Inglês ::</font></STRONG></FONT></th><th width="157" bgcolor="#FF6600"><div align="center"><FONT color=royalblue face=Tahoma size=2><STRONG><font color="#FFFFFF">::Português ::</font></STRONG></FONT></div></th></tr>
		  <%
	Do While Not rstSearch.EOF
		%>
		  <tr> 
			<td bgcolor="#FFFFE6"><font size="1" face="Verdana, Arial, Helvetica, sans-serif"><%= rstSearch.Fields("PALAVRA").Value %></font></td>
			<td bgcolor="#FFFFE6">
			  <div align="center"><font size="1" face="Verdana, Arial, Helvetica, sans-serif"><%= rstSearch.Fields("TRADUCAO").Value %></font></div></td>
		  </tr>
		  <%

		rstSearch.MoveNext
	Loop
	%>
		</table>
		<font size="1" face="Verdana, Arial, Helvetica, sans-serif"><br>
		 Sua busca foi processada em 
		<%response.write FormatNumber( Timer - inicio, 2 )%>
		segundos.</font><br>
		<%
	
	rstSearch.Close
	Set rstSearch = Nothing
	cnnSearch.Close
	Set cnnSearch = Nothing
End If

%>
	  </div></td>
  </tr>
</table>
<p> </p>

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.