Visual Basic - como leer los option button en archivo secuencial

Life is soft - evento anual de software empresarial
 
Vista:
sin imagen de perfil

como leer los option button en archivo secuencial

Publicado por clor (5 intervenciones) el 16/05/2024 19:51:31
Hola
estoy haciendo un pequeño proyecto en visual basic 6.0

cuando guarda los datos me los guarda bien

el problema que tengo del proyecto es que no me lee los options buttons los demas valores si los lee

hay dos frame

------------------------ ----------------------------
0 option1 label7 0 option2 label9
0 option1 label8 0 option2 label10
------------------------- ------------------------------

text6.text text7.text


aqui dejo el codigo


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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
Public Sub limpiar()
Text1 = ""
Text2 = ""
Text3 = ""
Text4 = ""
Text5 = ""
Text1.SetFocus
End Sub
 
 
 
Private Sub Command1_Click()
Dim mat As String * 7
Dim nom As String * 30
Dim postnom As String * 30
Dim sexe As String * 10
Dim price As String * 10
Dim datenaiss As String * 10
Dim adresse As String * 40
mat = Text1
nom = Text2
postnom = Text3
 
datenaiss = Text4
 
adresse = Text5
 
sexe = Text6.Text
 
price = Text7.Text
 
Open App.Path & "\fichero estudiante\" & (nom + ".txt") For Output As #1
Write #1, mat, nom, postnom, Option1(0).Value, Option1(1).Value, sexe, Option2(0).Value, Option2(1).Value, price, datenaiss, adresse
Close #1
MsgBox "Guardado exitosamente !", vbInformation, "Gestion Estudiante"
limpiar
End Sub
 
Private Sub Command2_Click()
limpiar
End Sub
 
 
 
Private Sub Command4_Click()
End
End Sub
 
 
 
Private Sub Command5_Click()
 
Dim F_check1, F_check2, F_check3, F_check4 As Integer
 
 
cd1.InitDir = App.Path & "\fichero estudiante\"
    cd1.ShowOpen
 
 
 
 
 
Open cd1.FileName For Input As #1
 
 
Do While EOF(1) <> -1
Input #1, mat, nom, postnom, F_check1, F_check2, sexe, F_check3, F_check4, price, datenaiss, adresse
Text1 = mat
 Text2 = nom
 Text3 = postnom
 
 Text4 = datenaiss
 
Text5 = adresse
If Option1(Index).Value = True Then
 
Option1(0).Caption = F_check1
Text6.Text = sexe
Else
Option1(1).Caption = F_check2
Text6.Text = sexe
End If
 
Text6.Text = sexe
 
If Option2(Index).Value = True Then
 Option2(0).Caption = F_check3
Else
Option2(1).Caption = F_check4
End If
 
 Text7.Text = price
Loop
Close #1
 
 
 
End Sub
 
Private Sub Option1_Click(Index As Integer)
Select Case Index
Case 0: Text6.Text = Label7.Caption
Case 1: Text6.Text = Label8.Caption
End Select
End Sub
 
 
Private Sub Option2_Click(Index As Integer)
Select Case Index
Case 0: Text7.Text = Label9.Caption
Case 1: Text7.Text = Label10.Caption
End Select
End Sub


gracias
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: 1.259
Plata
Ha mantenido su posición en Visual Basic (en relación al último mes)
Gráfica de Visual Basic

como leer los option button en archivo secuencial

Publicado por Antoni Masana (563 intervenciones) el 18/05/2024 18:29:05
Por lo que veo no estas leyendo lo que escribes, quiero decir cuando haces el Write pones Option1(0).Value y esto escribe algo que no se exactamente que es, puede ser un True/False o un 0/1 y cuando lees ignoras lo que hay escrito.

por que vamos a ver en esta condición:

1
2
3
4
5
6
7
If Option1(Index).Value = True Then
    Option1(0).Caption = F_check1
    Text6.Text = sexe
Else
    Option1(1).Caption = F_check2
    Text6.Text = sexe
End If

¿Que tiene que ver lo que valga Option1(index) para saber que se ha leído que esta en F_chek1 y F_check2?
y por cierto
¿Que vale Index?

A falta de más información creo que la solución más correcta es esta:

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
Private Sub Command5_Click()
    Dim F_check1, F_check2, F_check3, F_check4 As Integer
 
    cd1.InitDir = App.Path & "\fichero estudiante\"
    cd1.ShowOpen
 
    Open cd1.FileName For Input As #1
 
    Do While EOF(1) <> -1
        Input #1, mat, nom, postnom, F_check1, F_check2, sexe, F_check3, F_check4, price, datenaiss, adresse
        Text1 = mat
        Text2 = nom
        Text3 = postnom
        Text4 = datenaiss
        Text5 = adresse
        Text6.Text = sexe
        Text7.Text = price
 
        Option1(0).Caption = F_check1
        Option1(1).Caption = F_check2
        Option2(0).Caption = F_check3
        Option2(1).Caption = F_check4
    Loop
    Close #1
End Sub

La macro:

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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
Public Sub limpiar()
    Text1 = ""
    Text2 = ""
    Text3 = ""
    Text4 = ""
    Text5 = ""
    Text1.SetFocus
End Sub
 
 
Private Sub Command1_Click()
    Dim mat As String * 7
    Dim nom As String * 30
    Dim postnom As String * 30
    Dim sexe As String * 10
    Dim price As String * 10
    Dim datenaiss As String * 10
    Dim adresse As String * 40
 
    mat = Text1
    nom = Text2
    postnom = Text3
    datenaiss = Text4
    adresse = Text5
    sexe = Text6.Text
    price = Text7.Text
 
    Open App.Path & "\fichero estudiante\" & (nom + ".txt") For Output As #1
    Write #1, mat, nom, postnom, Option1(0).Value, Option1(1).Value, sexe, _
                                 Option2(0).Value, Option2(1).Value, price, _
                                 datenaiss, adresse
    Close #1
    MsgBox "Guardado exitosamente !", vbInformation, "Gestion Estudiante"
    limpiar
End Sub
 
 
Private Sub Command2_Click()
    limpiar
End Sub
 
 
Private Sub Command4_Click()
    End
End Sub
 
 
Private Sub Command5_Click()
    Dim F_check1, F_check2, F_check3, F_check4 As Integer
 
    cd1.InitDir = App.Path & "\fichero estudiante\"
    cd1.ShowOpen
 
    Open cd1.FileName For Input As #1
 
    Do While EOF(1) <> -1
        Input #1, mat, nom, postnom, F_check1, F_check2, sexe, F_check3, F_check4, price, datenaiss, adresse
        Text1 = mat
        Text2 = nom
        Text3 = postnom
        Text4 = datenaiss
        Text5 = adresse
 
        If Option1(Index).Value = True Then
            Option1(0).Caption = F_check1
            Text6.Text = sexe
        Else
            Option1(1).Caption = F_check2
            Text6.Text = sexe
        End If
 
        Text6.Text = sexe
 
        If Option2(Index).Value = True Then
            Option2(0).Caption = F_check3
        Else
            Option2(1).Caption = F_check4
        End If
 
        Text7.Text = price
    Loop
    Close #1
End Sub
 
 
Private Sub Option1_Click(Index As Integer)
    Select Case Index
        Case 0: Text6.Text = Label7.Caption
        Case 1: Text6.Text = Label8.Caption
    End Select
End Sub
 
 
Private Sub Option2_Click(Index As Integer)
    Select Case Index
        Case 0: Text7.Text = Label9.Caption
        Case 1: Text7.Text = Label10.Caption
    End Select
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
sin imagen de perfil

como leer los option button en archivo secuencial

Publicado por clor (5 intervenciones) el 18/05/2024 22:55:56
Hola Antoni
la instruccion Option1(Index).Value = True, o sea el index era el valor 0 y 1, no era la instruccion correcta
al final lo consegui haciendo esto:

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
Private Sub Command5_Click()
 
Dim F_check1, F_check2, F_check3, F_check4 As Integer
 
 
cd1.InitDir = App.Path & "\fichero estudiante\"
    cd1.ShowOpen
 
Open cd1.Filename For Input As #1
 
 
Do While EOF(1) <> -1
 
   Input #1, mat, nom, postnom, F_check1, F_check2, sexe, F_check3, F_check4, price, datenaiss, adresse
 
   Text1 = mat
   Text2 = nom
   Text3 = postnom
   Text4 = datenaiss
   Text5 = adresse
 
   If F_check1= True Then
      Option1(0).value = True
   Else
      Option1(1).value = True
   End If
 
 
   Text6.Text = sexe
 
   If F_check3 = True Then
      Option2(0).value = True
   Else
      Option2(1).value = True
   End If
 
   Text7.Text = price
 
Loop
 
Close #1
 
End Sub


Ahora tengo un problema
pongo 4 option button en un frame y el otro frame con dos option button ¿como seria para leer la informacion?
gracias
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