dni con textbox

31/07/2003 - 15:16 por Juan Pedro | Informe spam
hola compañeros/as me dirigo a ustedes porque no se como capturar que cuando
paso de un textbox a otro me calcule el dni o nif
es decir tengo un textbox en el cual introducco el dni o el nif y cuando
pulso el tabular para entrar los datos en el otro textbox ya me calcule el
resultado y lo muestre en el texbox del dni o nif

alguna ayuda gracias juan pedro
 

Leer las respuestas

#1 jfcc
31/07/2003 - 15:57 | Informe spam
Hola Juan Pedro,
En un modulo pones
Function NIF(DNI As Long) As String
Dim strLetra As String
strLetra = "TRWAGMYFPDXBNJZSQVHLCKE"
NIF = Mid(strLetra, (DNI Mod 23) + 1, 1)

End Function
Function ValidarTarjeta(strTarjeta As String) As Boolean
Dim ValorInd, ValorAcum As Integer
Dim intPar As Integer
Dim ind As Integer

ValorAcum = 0

For ind = 1 To 16
ValorInd = Val(Mid(strTarjeta, ind, 1))
intPar = ind Mod 2
If intPar = 0 Then
ValorAcum = ValorAcum + ValorInd
Else
ValorInd = ValorInd * 2
If ValorInd > 9 Then ValorInd = ValorInd - 9
ValorAcum = ValorAcum + ValorInd
End If
Next ind
intPar = ValorAcum Mod 10
If ValorAcum < 150 And intPar = 0 Then
ValidarTarjeta = True
Else
ValidarTarjeta = False
End If


End Function

Function TipoTarjeta(strTarjeta As String) As String
Dim ValPrimerDigito As String

ValPrimerDigito = Left(strTarjeta, 1)
Select Case ValPrimerDigito
Case 3
TipoTarjeta = "AMERICAN EXPRESS"
Case 4
TipoTarjeta = "VISA"
Case 5
TipoTarjeta = "MASTER CARD"
Case 6
TipoTarjeta = "DISCOVER"
Case Else
TipoTarjeta = "DESCONOCIDA"
End Select


End Function

Function DigCon(ByVal strEntidad As String, ByVal strOficina As String,
ByVal strCuenta As String) As Integer
Dim mtrFactor1, mtrFactor2
Dim Datos1(7) As Integer
Dim Datos2(9) As Integer
Dim strEntOfi As String
Dim PrimerDigito, SegundoDigito As Byte
Dim intContador As Integer
Dim SumaAcum1, SumaAcum2 As Integer

mtrFactor1 = Array(4, 8, 5, 10, 9, 7, 3, 6)
mtrFactor2 = Array(1, 2, 4, 8, 5, 10, 9, 7, 3, 6)

strEntOfi = strEntidad & strOficina
For intContador = 0 To 7
Datos1(intContador) = Val(Mid(strEntOfi, intContador + 1, 1))
Next intContador

For intContador = 0 To 9
Datos2(intContador) = Val(Mid(strCuenta, intContador + 1, 1))
Next intContador

For intContador = 0 To 7
SumaAcum1 = SumaAcum1 + (mtrFactor1(intContador) *
Datos1(intContador))
Next intContador

For intContador = 0 To 9
SumaAcum2 = SumaAcum2 + (mtrFactor2(intContador) *
Datos2(intContador))
Next intContador



SumaAcum1 = SumaAcum1 Mod 11
SumaAcum1 = 11 - SumaAcum1
If SumaAcum1 = 11 Then
PrimerDigito = 0
ElseIf SumaAcum1 = 10 Then
PrimerDigito = 1
Else
PrimerDigito = SumaAcum1
End If

SumaAcum2 = SumaAcum2 Mod 11
SumaAcum2 = 11 - SumaAcum2
If SumaAcum2 = 11 Then
SegundoDigito = 0
ElseIf SumaAcum2 = 10 Then
SegundoDigito = 1
Else
SegundoDigito = SumaAcum2
End If

DigCon = (PrimerDigito * 10) + SegundoDigito

End Function


En el formulario colocas un textbox para DNI , tres mas de cuenta bancaria y
tres botones con el siguiente codigo:
Private Sub cmdDC_Click()
MsgBox DigCon(Me.txtEntidad, Me.txtOficina, Me.txtCuenta)
End Sub

Private Sub cmdDNI_Click()

MsgBox NIF(Val(Me.txtNumero))

End Sub

Private Sub cmdTarjeta_Click()
Dim strSINO As String

If ValidarTarjeta(Me.txtNumero) = True Then
strSINO = "Esta tarjeta es correcta," & vbCrLf & "del tipo " &
TipoTarjeta(Me.txtNumero)
Else
strSINO = "No se fie de esta tarjeta"
End If
MsgBox strSINO, vbInformation, "Mensaje"

End Sub


Espero haberte ayudado
Un saludo
Juan

"Juan Pedro" escribió en el mensaje
news:
hola compañeros/as me dirigo a ustedes porque no se como capturar que


cuando
paso de un textbox a otro me calcule el dni o nif
es decir tengo un textbox en el cual introducco el dni o el nif y cuando
pulso el tabular para entrar los datos en el otro textbox ya me calcule el
resultado y lo muestre en el texbox del dni o nif

alguna ayuda gracias juan pedro


Preguntas similares