Article View: chile.comp.programacion
Article #546Re: ayuda con validar rut
From: Rickoj
Date: Wed, 12 Mar 2008 03:23
Date: Wed, 12 Mar 2008 03:23
112 lines
4141 bytes
4141 bytes
vale pero no me sirve en vb :( "gato2008chile" <gato2008chileSINESTO@gmail.com> escribi� en el mensaje news:fr7ao1$d1s$1@news.nivel5.cl... > En VB hice uso de dos eventos y funciones, una validaba el formato y otra > el digito. > chRut valida el formato, debe ser de la forma 123456-7,solo permite el > ingreso de numeros y "-", verifica que si el caracter es ingresado es "-" > este en la posicion largo-1,etc. > > En el evento change > txtRut.Text = chRut(txtRut.Text) > txtRut.SelStart = Len(txtRut.Text) > > En el evento keypress > > txtRut.Text = chRut(txtRut.Text) > If KeyAscii = 13 Then > ValRut(texto1.text) > End If > > > > Public Function ValRut(ByVal cadena As String) As Boolean > Dim ln As Integer, tp As Integer, i As Integer, _ > j As Integer, sum As Integer, ctemp As String > > ln = Len(cadena) > If ln < 3 Then > ValRut = False > ElseIf ln >= 3 Then > tp = InStr(1, cadena, "-", vbTextCompare) > If tp = 0 Then > ValRut = False > ElseIf tp <> (ln - 1) Then > ValRut = False > Else > sum = 0 > j = 2 > For i = (tp - 1) To 1 Step -1 > st = Val(Mid(cadena, i, 1)) > If st >= 0 And st <= 9 Then > sum = sum + st * j > j = j + 1 > If j = 8 Then > j = 2 > End If > Else > ValRut = False > Exit Function > End If > Next > dv = sum Mod 11 > ctemp = Mid(cadena, ln, 1) > If dv = 0 Then > If ctemp = "k" Or ctemp = "K" Then > ValRut = True > Else > ValRut = False > End If > Else > > If (11 - dv) = Val(ctemp) Then > ValRut = True > Else > ValRut = False > End If > End If > End If > End If > End Function > > > Public Function chRut(ByVal cadena As String) As String > Dim ln As Integer > Dim pos As Integer > Dim cs As Integer > Dim cadt As String > > ln = Len(cadena) > pos = InStr(cadena, "-") > If pos = 0 Then > chRut = IIf(Val(cadena) = 0, "", Format(Val(cadena))) > ElseIf pos <= 4 Then > chRut = "" > ElseIf pos = ln Then > chRut = Format(Val(Left(cadena, ln - 1))) & "-" > ElseIf pos <= (ln - 1) Then > cadt = Left(cadena, pos + 1) > cs = Asc(Right(cadt, 1)) > If ((cs < 48 Or cs > 57) And cs <> 13) _ > And cs <> 45 Then > chRut = Left(cadt, ln - 1) > Else > chRut = cadt > End If > End If > End Function > > > Rick_oj escribi�: >> >> "Rick_oj" <rick_oj[sin-esto]@tutopia.com> escribi� en el mensaje >> news:fqq6gv$uj2$1@news.nivel5.cl... >>> necesito validar el dichoso rut en un mismo campo de texto con el guion, >>> he encontrado varios script qu ehacen lo mismo, pero al aplicarlo no me >>> funciona, encontre este que es mas sencillo, pero lo hace en dos campos >>> de textos, y lo hace automatico (el digito verificador) >> >> nadie? >> :(
Technical Details
Message-ID:
<fr7eq4$diq$1@news.nivel5.cl>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.glorb.com!news.kjsl.com!news.nivel5.cl!not-for-mailReferences:
<fqq6gv$uj2$1@news.nivel5.cl> <fr62f0$80a$1@news.nivel5.cl> <fr7ao1$d1s$1@news.nivel5.cl>Show Full Headers
Complete Article Headers
X-Google-Thread: 1593cb,80adbb2b571c3e5b X-Google-Attributes: gid1593cb,public,usenet X-Google-Language: ENGLISH,ASCII Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.glorb.com!news.kjsl.com!news.nivel5.cl!not-for-mail From: "Rick_oj" <rick_oj[sin-esto]@tutopia.com> Newsgroups: chile.comp.programacion Subject: Re: ayuda con validar rut Date: Tue, 11 Mar 2008 23:23:00 -0400 Organization: Varios Lines: 114 Message-ID: <fr7eq4$diq$1@news.nivel5.cl> References: <fqq6gv$uj2$1@news.nivel5.cl> <fr62f0$80a$1@news.nivel5.cl> <fr7ao1$d1s$1@news.nivel5.cl> NNTP-Posting-Host: 190.160.68.32 X-Trace: news.nivel5.cl 1205288580 13914 190.160.68.32 (12 Mar 2008 02:23:00 GMT) X-Complaints-To: news@news.nivel5.cl NNTP-Posting-Date: Wed, 12 Mar 2008 02:23:00 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3138 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198 X-RFC2646: Format=Flowed; Response