##### http://www.lawebdelprogramador.com ##### ##### RESPUESTA A LA PREGUNTA 45331 - POWER BUILDER ##### // Valida un R.U.T. // // Sintaxis: ValidaRut( cRut, lValeVacio, lSayMensaje ) // // : R.U.T. a validar. (string) // : (TRUE/FALSE).Indica si un R.U.T. vacío es Ok. // : (TRUE/FALSE). Indica si en caso de fallar la validación, // se muestra al usuario un mensaje de error por defecto. // String cDig, xNum, cResto Integer nSuma = 0, nFactor = 2, nResto, i Boolean lOk = True, lCont = True If IsNull( lValeVacio ) Then lValeVacio = False End if If IsNull( lSayMensaje ) Then lSayMensaje = False End if string Rut2 Int rut3 Rut2 = mid(cRut,1,1) Rut3 = Integer(Rut2) cRut = f_CHARREM( ".-" , RightTrim(LeftTrim(cRut)) ) If Len( cRut ) = 0 Then If lValeVacio Then lCont = False Else lOk = False lCont = False End if End if if len(cRut) = 1 and crut= '0' then lOk = False lCont = False end if cDig = Right( cRut, 1 ) cRut = MID( cRut , 1 , Len( cRut ) - 1 ) if long(crut)= 0 then lOk = False lCont = False end if if cdig= 'k' then lOk = False lCont = False end if If lCont Then For i = Len( cRut ) To 1 STEP -1 xNum = MID( cRut , i , 1 ) If Pos( "0123456789" , xNum ) = 0 Then lOk = False lCont = False Exit End If nSuma = nSuma + INTEGER( xNum ) * nFactor If nFactor = 7 Then nFactor = 2 Else nFactor = nFactor + 1 End If Next If lCont Then nResto = MOD( nSuma , 11 ) If nResto = 0 Then cResto = "0" ElseIf nResto = 1 Then cResto = "K" Else cResto = STRING( 11 - nResto , "0" ) End If If cResto <> UPPER( cDig ) Then lOk = False lCont = False End If End if End If If lOk = False Then If lSayMensaje Then MessageBox( "Error" , "Rut Ingresado no es válido" , Exclamation! ) End If End If Return ( lOk ) Hay un f_CHARREM Que es para eliminar un carater de una cadena // Elimina caracteres de un string. // // Sintaxis : cStr = fcharrem( cELiminar, cEnEsteString ) // // : String conteniendo los caracteres a eliminar... // : ...en este string. // // Retorna string con los caracteres eliminados. // // Ej : Test = "Ayer fué 13 de Abril de 1995" // Test = CHARREM( "0123456789" , Test ) // Test se transforma en: "Ayer fué de Abril de" Integer i String cNewStr = "" For i = 1 To Len( cEnEsteString ) If Pos( cEliminar, MID( cEnEsteString , i , 1 ) ) = 0 Then cNewStr = cNewStr + MID( cEnEsteString, i, 1 ) End if Next Return ( cNewStr ) ##### mario rojas mario_rojas_10@hotmail.com #####