Manejo de listas, activa y desactiva controles, pasa datos una lista a otra, los acomoda, etc.

¿Has encontrado un error? ¿Tienes la solución? Deja tu correción ;-)

Antes de comentar: Gran parte de los ejercicios propuestos no tienen librerías debido a que Wordpress las eliminó al verlas como etiquetas HTML. Si sabes/tienes/conoces las librerías que hacen falta, déjalo en los comentarios. Y lo mas importante: Todos los ejemplos fueron realizados por estudiante con únicamente conocimiento básico del lenguaje, no de programación.

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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
VERSION 5.00
Begin VB.Form Form4 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Practica 4 - Manejo de listas"
   ClientHeight    =   4980   ClientLeft      =   1380
   ClientTop       =   1230
   ClientWidth     =   6255
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False   MinButton       =   0   'False
   ScaleHeight     =   4980
   ScaleWidth      =   6255
   StartUpPosition =   2  'CenterScreen
   Begin VB.CommandButton last       Caption         =   "Final"
      Enabled         =   0   'False
      Height          =   375
      Left            =   4800
      TabIndex        =   17      Top             =   2400
      Width           =   1335
   End
   Begin VB.CommandButton first 
      Caption         =   "Inicio"      Enabled         =   0   'False
      Height          =   375
      Left            =   4800
      TabIndex        =   16
      Top             =   960      Width           =   1335
   End
   Begin VB.CommandButton down 
      Caption         =   "Down"
      Enabled         =   0   'False      Height          =   375
      Left            =   4800
      TabIndex        =   15
      Top             =   1920
      Width           =   1335   End
   Begin VB.CommandButton up 
      Caption         =   "Arriba"
      Enabled         =   0   'False
      Height          =   375      Left            =   4800
      TabIndex        =   14
      Top             =   1440
      Width           =   1335
   End   Begin VB.CommandButton clear_all 
      Caption         =   "Limpiar ambas listas"
      Height          =   375
      Left            =   120
      TabIndex        =   13      Top             =   3840
      Width           =   4455
   End
   Begin VB.CommandButton clear_2 
      Caption         =   "Limpiar lista 2"      Height          =   375
      Left            =   2640
      TabIndex        =   12
      Top             =   3360
      Width           =   1935   End
   Begin VB.CommandButton clear_1 
      Caption         =   "Limpiar lista 1"
      Height          =   375
      Left            =   120      TabIndex        =   11
      Top             =   3360
      Width           =   1935
   End
   Begin VB.OptionButton Option2       Caption         =   "lista 2"
      Height          =   255
      Left            =   1200
      TabIndex        =   9
      Top             =   480      Width           =   975
   End
   Begin VB.OptionButton Option1 
      Caption         =   "lista 1"
      Height          =   255      Left            =   120
      TabIndex        =   8
      Top             =   480
      Value           =   -1  'True
      Width           =   975   End
   Begin VB.ListBox List2 
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   9.75         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False      EndProperty
      Height          =   2460
      Left            =   2640
      TabIndex        =   7
      Top             =   840      Width           =   1935
   End
   Begin VB.CommandButton l_all 
      Caption         =   "<<"
      Height          =   375      Left            =   2160
      TabIndex        =   6
      Top             =   2400
      Width           =   375
   End   Begin VB.CommandButton l_one 
      Caption         =   "<"
      Height          =   375
      Left            =   2160
      TabIndex        =   5      Top             =   1920
      Width           =   375
   End
   Begin VB.CommandButton r_all 
      Caption         =   ">>"      Height          =   375
      Left            =   2160
      TabIndex        =   4
      Top             =   1440
      Width           =   375   End
   Begin VB.CommandButton r_one 
      Caption         =   ">"
      Height          =   375
      Left            =   2160      TabIndex        =   3
      Top             =   960
      Width           =   375
   End
   Begin VB.CommandButton Command1       Caption         =   "Agregar"
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   9.75
         Charset         =   0         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty      Height          =   375
      Left            =   4920
      TabIndex        =   2
      Top             =   120
      Width           =   1215   End
   Begin VB.TextBox Text1 
      Height          =   285
      Left            =   120
      TabIndex        =   1      Top             =   120
      Width           =   4695
   End
   Begin VB.ListBox List1 
      BeginProperty Font          Name            =   "Tahoma"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   2460
      ItemData        =   "practica4-modular.frx":0000      Left            =   120
      List            =   "practica4-modular.frx":0016
      TabIndex        =   0
      Top             =   840
      Width           =   1935   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Height          =   195
      Left            =   4920      TabIndex        =   18
      Top             =   3000
      Width           =   45
   End
   Begin VB.Label view       Alignment       =   2  'Center
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   12
         Charset         =   0         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty      ForeColor       =   &H00C00000&
      Height          =   495
      Left            =   0
      TabIndex        =   10
      Top             =   4320      Width           =   4695
   End
End
Attribute VB_Name = "Form4"
Attribute VB_GlobalNameSpace = FalseAttribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub clear_1_Click()
    List1.Clear    view.Caption = ""
    Call evaluar
End Sub
Private Sub clear_2_Click()
    List2.Clear    view.Caption = ""
    Call evaluar
End Sub
Private Sub clear_all_Click()
    List1.Clear    List2.Clear
    view.Caption = ""
    Call evaluar
End Sub
Private Sub Command1_Click()    If Option1 = False And Option2 = False Then
            'Si no se selecciono ninguna lista para meter el dato...'
            'Y ya se esta intentando ingresar, mostrar un error y regresar'
            'al formulario de nuevo'
            MsgBox "Error: No se selecciono una lista", vbCritical, "Warning"        Else
            'Cuando presionen el boton Agregar'
            If Text1.Text <> "" Then 'Evalua que no este en blanco'
                    If Option1 = True Then
                            'LISTA1'                            List1.AddItem Text1.Text 'Lo agrega a la lista'
                            Text1.Text = "" 'Regresa a blanco el cuadro de texto'
                                                             '...la cantidad de registros de la lista'
                        
                        Else                            'LISTA2'
                            List2.AddItem Text1.Text
                            Text1.Text = ""
                                                             '...la cantidad de registros de la lista'
                        End If                End If
        End If
    Call evaluar
End Sub
  
Private Sub up_Click()
MsgBox "Manda elemento posicion arriba"
End Sub
Private Sub down_Click()MsgBox "manda elemento posicion abajo"
End Sub
 
Private Sub first_Click()
MsgBox "Manda elemento al inicio"End Sub
 
Private Sub last_Click()
MsgBox "manda elemento al final"
End Sub 
Private Sub Form_Load()
    Call evaluar
End Sub
Private Sub form_click()    List1.ListIndex = -1
    List2.ListIndex = -1
    lista1 = False
    lista2 = False
    Call evaluarEnd Sub
 
Private Sub l_all_Click()
    For c = 0 To List2.ListCount - 1
            List1.AddItem List2.List(c)        Next
    For c = 0 To List2.ListCount - 1
            List2.RemoveItem 0
        Next
    Call evaluarEnd Sub
 
Private Sub l_one_Click()
    If List2.ListIndex >= 0 Then
            List1.AddItem List2.List(List2.ListIndex)            List2.RemoveItem List2.ListIndex
            view.Caption = ""
        End If
    Call evaluar
End SubPrivate Sub List1_Click()
    'Cuando le dan click a la lista1...'
    '...muestra cual registros esta seleccionado'
    view.Caption = List1.List(List1.ListIndex)
    Call evaluarEnd Sub
 
Private Sub List2_Click()
    'Cuando le dan click a la lista2...'
    '...Muestra cual regist esta seleccionado'    view.Caption = List2.List(List2.ListIndex)
    Call evaluar
End Sub
Private Sub Option1_Click()
    'Si elije opcion 1, Se envia el dato a la lista 1'    Dim lista As Integer
    If Option1 = True Then
            lista = 1
        End If
    Call evaluarEnd Sub
Private Sub Option2_Click()
    'Si elije opcion 2, Se envia el dato a la lista 2'
    Dim lista As Integer
    If Option2 = True Then            lista = 2
        End If
    Call evaluar
End Sub
 Private Sub r_all_Click()
    For c = 0 To List1.ListCount - 1
            List2.AddItem List1.List(c)
        Next
    For c = 0 To List1.ListCount - 1            List1.RemoveItem 0
        Next
    Call evaluar
End Sub
 Private Sub r_one_Click() 'Mover de lista1 a lista2 un registro'
    If List1.ListIndex >= 0 Then
            List2.AddItem List1.List(List1.ListIndex)
            List1.RemoveItem List1.ListIndex
            view.Caption = ""        End If
Call evaluar
End Sub
Function evaluar() 'Evalua el formulario'
    If List1.ListCount = 0 Then            r_one.Enabled = False
            r_all.Enabled = False
            clear_1.Enabled = False
        End If
    If List1.ListCount > 0 Then            r_all.Enabled = True
            clear_1.Enabled = True
            clear_all.Enabled = True
        End If
    If List1.ListIndex = -1 Then            r_one.Enabled = False
            lista1 = False 'lista1 desactivada
        End If
    If List1.ListIndex > -1 Then
            r_one.Enabled = True            lista1 = True
            lista2 = False
        End If
    ''''''''''''''''''''''''''
    If List2.ListCount = 0 Then            l_one.Enabled = False
            clear_2.Enabled = False
            l_all.Enabled = False
        End If
    If List2.ListCount > 0 Then            l_all.Enabled = True
            clear_2.Enabled = True
            clear_all.Enabled = True
        End If
    If List2.ListIndex = -1 Then            l_one.Enabled = False
        End If
    If List2.ListIndex > -1 Then
            l_one.Enabled = True
            lista1 = False            lista2 = True
        End If
    ''''''''''''''''''''''''''
    If List1.ListCount = 0 And List2.ListCount = 0 Then
            clear_all.Enabled = False        End If
    If lista1 = True And lista2 = False Then
                Label1.Caption = "Lista 1"
            Else
                Label1.Caption = ""        End If
    If lista2 = True And lista1 = False Then
                Label1.Caption = "Lista 2"
            Else
                Label1.Caption = ""        End If
 
End Function
 
Private Sub Text1_Change()    Command1.Enabled = True
    Call evaluar
End Sub

Punto importante: Si vas a sugerir un segmento de código en algún lenguaje debes hacerlo así:

  • Si es lenguaje C <code lang="c">Código en C</code>
  • Si es lenguaje Pascal <code lang="pascal">Aquí dentro el código de Pascal</code>.

De esta manera el código coloreas el código.

Deja un comentario

Suscribirse a los comentarios.