You are on page 1of 5

Dim xDat As String

Dim xRazSoc As String, xEst As String, xCon As String, xDir As String


Dim xRazSocX As Long, xEstX As Long, xConX As Long, xDirX As Long
Dim xRazSocY As Long, xEstY As Long, xConY As Long, xDirY As Long
Private Sub btnbuscar_Click(sender As System.Object, e As System.EventArgs)
Handles btnbuscar.Click
If Trim(txtruc.Text) = "" Then
MsgBox("Ingrese nmero del RUC", vbInformation, "Softae - Software de
Administracion Empresarial")
txtruc.Focus()
Exit Sub
End If
If IsNumeric(txtruc.Text) = True Then
If Len(txtruc.Text) < 11 Then
Limpiar()
MsgBox("Ingrese los 11 nmeros del RUC", vbInformation, "Softae Software de Administracion Empresarial")
txtruc.Focus()
Exit Sub
End If
If Val(Mid(Trim(txtruc.Text), 2, 9)) = 0 Or Trim(txtruc.Text) = "233
33333333" Then
Limpiar()
MsgBox("Verificar nmero del RUC", vbInformation, "Softae - Softwa
re de Administracion Empresarial")
txtruc.Focus()
Exit Sub
End If
If Verificar_ruc(txtruc.Text) = False Then
Limpiar()
MsgBox("El nmero del RUC no es vlido", vbInformation, "Softae - So
ftware de Administracion Empresarial")
txtruc.Focus()
Exit Sub
End If
RUC(txtruc.Text)
OTRO(txtruc.Text)
Else
Limpiar()
MsgBox("Solo se aceptan nmeros", vbInformation, "Softae - Software de
Administracion Empresarial")
txtruc.Focus()
End If
End Sub
Private Sub RUC(ByVal xNum As String)
On Error Resume Next
Dim xWml As New XMLHTTPRequest
xWml.open("POST", "http://http://www.sunat.gob.pe/cl-ti-itmrconsruc/jcrS
00Alias?ruc=" & xNum, False)
'xWml.open("POST", "http://www.sunat.gob.pe/w/wapS01Alias?ruc=" & xNum,
False)
xWml.send()
If xWml.status = 200 Then
Limpiar()
xDat = xWml.responseText
If Len(xDat)
MsgBox("El numero Ruc ingresado no existe en la Base de datos de
la SUNAT", vbInformation, "Softae - Software de Administracion Empresarial")
xWml = Nothing

txtruc.Focus()
Exit Sub
End If
xDat
xDat
xDat
xDat
xDat
", "Direccion:")
xDat
xDat
xDat
xDat
xDat
xDat

=
=
=
=
=

Replace(xDat,
Replace(xDat,
Replace(xDat,
Replace(xDat,
Replace(xDat,

"Nmero Ruc. " & xNum & " - ", "RazonSocial:")


"Estado.", "Estado:")
"Agente Retencin IGV.", "ARIGV:")
"Situacin. ", "Situacion:")
"Direccin.

=
=
=
=
=
=

Replace(xDat,
Replace(xDat,
Replace(xDat,
Replace(xDat,
Replace(xDat,
Replace(xDat,

"
", " ")
"
", " ")
" ", " ")
" ", " ")
"( ", "(")
" )", ")")

xRazSocX = InStr(1,
xRazSocY = InStr(1,
", vbTextCompare)
xRazSocX = xRazSocX
xRazSoc = Mid(xDat,

xDat, "RazonSocial:", vbTextCompare)


xDat, "
+ 12
xRazSocX, (xRazSocY - xRazSocX))

xEstX = InStr(1, xDat, "Estado:", vbTextCompare)


xEstY = InStr(1, xDat, "ARIGV:", vbTextCompare)
xEstX = xEstX + 7
xEst = Mid(xDat, xEstX, ((xEstY - 34) - xEstX))
xConX = InStr(1, xDat, "Situacion:", vbTextCompare)
xConY = InStr(1, xDat, "
", vbTextCompare)
xDirY = xConX - 23
xConX = xConX + 10
xCon = Mid(xDat, xConX, (xConY - xConX))
xDirX = InStr(1, xDat, "Direccion:", vbTextCompare)
xDirX = xDirX + 10
xDir = Mid(xDat, xDirX, (xDirY - xDirX))
xRazSoc
xRazSoc
xRazSoc
xRazSoc
xRazSoc
xRazSoc
xRazSoc
xRazSoc
xRazSoc
xRazSoc
xRazSoc
xRazSoc
xDir
xDir
xDir
xDir
xDir
xDir
xDir
xDir

=
=
=
=
=
=
=
=

=
=
=
=
=
=
=
=
=
=
=
=

Replace(xRazSoc,
Replace(xRazSoc,
Replace(xRazSoc,
Replace(xRazSoc,
Replace(xRazSoc,
Replace(xRazSoc,
Replace(xRazSoc,
Replace(xRazSoc,
Replace(xRazSoc,
Replace(xRazSoc,
Replace(xRazSoc,
Replace(xRazSoc,

Replace(xDir,
Replace(xDir,
Replace(xDir,
Replace(xDir,
Replace(xDir,
Replace(xDir,
Replace(xDir,
Replace(xDir,

"",
"",
"",
"",
"",
"",
"",
"",

"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"")
"")
"")
"")
"")
"")
"")
"")

"")
"")
"")
"")
"")
"")
"")
"")
"")
"")
"")
"")

xDir
xDir
xDir
xDir

=
=
=
=

Replace(xDir,
Replace(xDir,
Replace(xDir,
Replace(xDir,

"",
"",
"",
"",

"")
"")
"")
"")

Txtrazsoc.Text = xRazSoc
txtest.Text = xEst
txtcon.Text = xCon
txtdir.Text = xDir
Else
Limpiar()
MsgBox("No responde el servicio de la SUNAT", vbInformation, "Softae
- Software de Administracion Empresarial")
End If
xWml = Nothing
End Sub
Private Sub OTRO(ByVal xNum As String)
On Error Resume Next
Dim xWml As New XMLHTTPRequest
xWml.open("POST", "http://http://www.sunat.gob.pe/cl-ti-itmrconsruc/jcrS
00Alias?ruc=" & xNum, False)
xWml.send()
If xWml.Status = 200 Then
Limpiar()
xDat = xWml.responseText
If Len(xDat)
MsgBox("El numero Ruc ingresado no existe en la Base de datos de
la SUNAT", vbInformation, "Softae - Software de Administracion Empresarial")
xWml = Nothing
txtruc.Focus()
Exit Sub
End If
Dim xTabla() As String
xDat
xDat
xDat
xDat
xDat
xDat

=
=
=
=
=
=

Replace(xDat,
Replace(xDat,
Replace(xDat,
Replace(xDat,
Replace(xDat,
Replace(xDat,

"
", " ")
"
", " ")
" ", " ")
" ", " ")
"( ", "(")
" )", ")")

xTabla = Split(xDat, "")


xTabla(1) = Replace(xTabla(1), "Nmero Ruc. " & xNum & " - ", "")
xTabla(1) = Replace(xTabla(1), "
", "")
xTabla(4) = Replace(xTabla(4), "Estado.", "")
xTabla(4) = Replace(xTabla(4), "
", "")
xTabla(7) = Replace(xTabla(7), "Direccin.
", "")
xTabla(7) = Replace(xTabla(7), "
", "")

xTabla(8) = Replace(xTabla(8), "Situacin. ", "")


xTabla(8) = Replace(xTabla(8), "
", "")
xRazSoc = CStr(xTabla(1))
xEst = CStr(xTabla(4))
xDir = CStr(xTabla(7))
xCon = CStr(xTabla(8))
xRazSoc
xRazSoc
xRazSoc
xRazSoc
xRazSoc
xRazSoc
xRazSoc
xRazSoc
xRazSoc
xRazSoc
xRazSoc
xRazSoc

=
=
=
=
=
=
=
=
=
=
=
=

Replace(xRazSoc,
Replace(xRazSoc,
Replace(xRazSoc,
Replace(xRazSoc,
Replace(xRazSoc,
Replace(xRazSoc,
Replace(xRazSoc,
Replace(xRazSoc,
Replace(xRazSoc,
Replace(xRazSoc,
Replace(xRazSoc,
Replace(xRazSoc,

"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",

"")
"")
"")
"")
"")
"")
"")
"")
"")
"")
"")
"")

xRazSoc = Mid(xRazSoc, 1, Len(xRazSoc) - 3)


xDir
xDir
xDir
xDir
xDir
xDir
xDir
xDir
xDir
xDir
xDir
xDir

=
=
=
=
=
=
=
=
=
=
=
=

Replace(xDir,
Replace(xDir,
Replace(xDir,
Replace(xDir,
Replace(xDir,
Replace(xDir,
Replace(xDir,
Replace(xDir,
Replace(xDir,
Replace(xDir,
Replace(xDir,
Replace(xDir,

"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",

"")
"")
"")
"")
"")
"")
"")
"")
"")
"")
"")
"")

xEst = Mid(xEst, 1, Len(xEst) - 6)


xCon = Mid(xCon, 1, Len(xCon) - 3)
xDir = Mid(xDir, 1, Len(xDir) - 3)
Txtrazsoc.Text = xRazSoc
txtest.Text = xEst
txtcon.Text = xCon
txtdir.Text = xDir
Else
Limpiar()
MsgBox("No responde el servicio de la SUNAT", vbInformation, "Softae
- Software de Administracion Empresarial")
End If
xWml = Nothing
End Sub
Private Sub Limpiar()
xRazSoc = ""
xEst = ""
xCon = ""
xDir = ""
Txtrazsoc.Text = ""
txtest.Text = ""

txtcon.Text = ""
txtdir.Text = ""
End Sub
Function Verificar_ruc(ByVal xNum As String) As Boolean
Dim li_suma, li_residuo, li_diferencia, li_compara As Integer
li_suma = (CInt(Mid(xNum, 1, 1)) * 5) + (CInt(Mid(xNum, 2, 1)) * 4) + (C
Int(Mid(xNum, 3, 1)) * 3) + (CInt(Mid(xNum, 4, 1)) * 2) + (CInt(Mid(xNum, 5, 1))
* 7) + (CInt(Mid(xNum, 6, 1)) * 6) + (CInt(Mid(xNum, 7, 1)) * 5) + (CInt(Mid(xN
um, 8, 1)) * 4) + (CInt(Mid(xNum, 9, 1)) * 3) + (CInt(Mid(xNum, 10, 1)) * 2)
li_compara = CInt(Mid(xNum, 11, 1))
li_residuo = li_suma Mod 11
li_diferencia = Int(11 - li_residuo)
If li_diferencia > 9 Then li_diferencia = li_diferencia - 10
If li_diferencia li_compara Then
Verificar_ruc = False
Else
Verificar_ruc = True
End If
End Function
Private Sub txtruc_KeyPress(sender As Object, e As System.Windows.Forms.KeyP
ressEventArgs) Handles txtruc.KeyPress
Dim Cadena = "0123456789"
If InStr(Cadena, e.KeyChar) Then
e.Handled = False
ElseIf Char.IsControl(e.KeyChar) Then
e.Handled = False
Else
e.Handled = True
End If
If e.KeyChar = ChrW(Keys.Enter) Then
e.Handled = True
SendKeys.Send("{TAB}")
End If
End Sub

You might also like