Jump to content
Fórum Script Brasil
  • 0

Rotina para buscar CEP


marcos espanhol

Question

Pessoal, sou novo por aqui, E Estou com uma rotina para buscar CEP que está dando pau na linha VB_Result....Alguém pode me ajudar??? ABS

 

Private Sub cbBusca_Click()
    
    Dim obj As MSXML2.ServerXMLHTTP
    Dim objLerXml As MSXML2.DOMDocument
    
    
    Set obj = New MSXML2.ServerXMLHTTP
    Set objLerXml = New MSXML2.DOMDocument
    'query_string
    url = "http://republicavirtual.com.br/web_cep.php?cep=" & txtCEP & "&formato=XML"
    
    obj.open "GET", url
    obj.send
        
    'se ocorreu um erro HTTP
    If obj.Status >= 400 And obj.Status <= 505 Then
      MsgBox "Erro Ocorrido : " & obj.Status & " - " & obj.statusText
      Exit Sub
    Else
        objLerXml.loadXML (obj.responseText)
    End If
        
    Set VB_RESULT = objLerXml.selectSingleNode("//resultado")
    
    If VB_RESULT.Text <> 0 Then
    
        Set VB_UF = objLerXml.selectSingleNode("//uf")
        Set VB_CIDADE = objLerXml.selectSingleNode("//cidade")
        Set VB_BAIRRO = objLerXml.selectSingleNode("//bairro")
        Set VB_RUA = objLerXml.selectSingleNode("//tipo_logradouro")
        Set VB_LOGRADOURO = objLerXml.selectSingleNode("//logradouro")
    
        txtUf.Text = VB_UF.Text
        txtCidade.Text = VB_CIDADE.Text
        txtBairro.Text = VB_BAIRRO.Text
        txtLogradouro.Text = VB_RUA.Text & " " & VB_LOGRADOURO.Text
    Else
        MsgBox "Serviço indisponível - cep inválido"
    End If
        
        
End Sub
Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.1k
    • Total Posts
      651.8k
×
×
  • Create New...