Access - no comprendo por que cuando f = 10 me muestra el msgbox 10

 
Vista:
sin imagen de perfil

no comprendo por que cuando f = 10 me muestra el msgbox 10

Publicado por Ronnie (3 intervenciones) el 12/04/2018 00:22:32
Estimados tengo el siguiente codigo pero no comprendo por que cuando f = 10 me muestra el msgbox 10 siendo que cambio el balor de la variable a un string K

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
Dim i As Integer, c As Integer, f As String, d As String, suma As Integer, a As String, h As Integer, j As Integer
   Dim l As Integer, g As String, rut As String, calcula_digito As String
    rut = InputBox("ingresa tu rut sin puntos ni guiones ")
      a = 32765432
 
    If Len(rut) = 7 Then
     a = 2765432
     End If
     For i = Len(rut) To 1 Step -1
        c = Mid(rut, i, 1)
        d = Mid(a, i, 1)
        h = CInt(d)
        j = CInt(c)
        l = h * j
        suma = suma + l
 
    Next
 
   suma = suma Mod 11
 
   f = 11 - suma
 
   If f = 10 Then
 
     f = "K"
 
   If f >= 1 Or f <= 9 Then
        calcula_digito = f
 
   Else
        calcula_digito = 0
 
   End If
 
     MsgBox f
End Sub
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Antoni Masana
Val: 78
Ha mantenido su posición en Access (en relación al último mes)
Gráfica de Access

no comprendo por que cuando f = 10 me muestra el msgbox 10

Publicado por Antoni Masana (32 intervenciones) el 12/04/2018 07:30:05
Respuesta:

Resaltadas todas las líneas que están mal, la lógica del proceso no tiene sentido si esta mal la sintaxis.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
Sub Macro1()  ' --- Mal Falta Inicio proceso
    Dim i As Integer, _
        c As Integer, _
        h As Integer, _
        j As Integer, _
        l As Integer, suma As Integer, _
 
    Dim f As String, _
        d As String, _
        a As String, _
        g As String, _
        rut As String, calcula_digito As String
 
    rut = InputBox("ingresa tu rut sin puntos ni guiones ")
      a = 32765432        ' -- Mal - A es un Srtring
 
    If Len(rut) = 7 Then
       a = 2765432        ' -- Mal - A es un Srtring
    End If
 
    For i = Len(rut) To 1 Step -1
        c = Mid(rut, i, 1)
        d = Mid(a, i, 1)
        h = CInt(d)
        j = CInt(c)
        l = h * j
        suma = suma + l
    Next
 
    suma = suma Mod 11
 
    f = 11 - suma             ' --- Mal - F es un Srtring
 
    If f = 10 Then            ' --- Mal - F es un Srtring
       f = "K"                ' --- ¿Que sentido tiene asignar la letra "K" y preguntar si es un número
    End If                    ' --- Falta End If
 
    If f >= 1 Or f <= 9 Then  ' --- Mal - F es un Srtring
       calcula_digito = f     ' --- ¿Esto esta bien?
    Else
       calcula_digito = 0     ' --- Mal - CALCULA_DIGITO es un Srtring
    End If
    MsgBox f
End Sub

Saludos.
\\//_
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Norberto
Val: 1.094
Oro
Ha mantenido su posición en Access (en relación al último mes)
Gráfica de Access

no comprendo por que cuando f = 10 me muestra el msgbox 10

Publicado por Norberto (753 intervenciones) el 12/04/2018 14:41:15
Hola.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
Public Sub CalcularDigitoRUT() 'Se entiende mejor
 
    Dim i As Integer, _
        c As Integer, _
        h As Integer, _
        j As Integer, _
        l As Integer, _
        suma As Integer, _
        f As Integer
 
    Dim d As String, _
        a As String, _
        g As String, _
        rut As String, _
        calcula_digito As String
 
    rut = InputBox("ingresa tu rut sin puntos ni guiones ")
      a = "32765432"
 
    If Len(rut) = 7 Then
       a = "2765432"
    End If
 
    For i = Len(rut) To 1 Step -1
        c = Mid(rut, i, 1)
        d = Mid(a, i, 1)
        h = CInt(d)
        j = CInt(c)
        l = h * j
        suma = suma + l
    Next
 
    suma = suma Mod 11
 
    f = 11 - suma
 
    If f = 10 Then
       calcula_digito = "K"
    ElseIf f >= 1 And f <= 9 Then   'And no Or. Todos los números del mundo mundial 
                                    'son >= 1 Or <= 9 y, solo algunos (del 1 al 9), ambas dos (And)
       calcula_digito = Trim(Str(f))
    Else
       calcula_digito = "0"
    End If
 
    MsgBox calcula_digito
 
End Sub

Un saludo,

Norberto.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar