Visual Basic - Recorrer array bidimencional

Life is soft - evento anual de software empresarial
 
Vista:

Recorrer array bidimencional

Publicado por promovi2 (1 intervención) el 26/02/2016 21:22:26
Hola!, estoy programando una especie de juego y bueno para una determinada función necesito recorrer una array bidimencional en una dirección no convencional y la verdad que llevo unos cuantos dias pensandolo y no puedo resolverlo bien. dejo una imagen de como seria si a alguien se le ocurre algo y me da una mano le agradezco!, Saludos!

25hd21g
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
sin imagen de perfil

Recorrer array bidimencional

Publicado por Marcelo (226 intervenciones) el 09/03/2016 07:45:24
Hola,
Revisa el código adjunto. Dale un vistazo y a ver si te ayuda en algo. Si tienes preguntas no dudes en consultar. Suerte!

25hd21g-2

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
Option Explicit
'First Set
Dim helldivers(0 To 3, 0 To 3) As String
Dim xTop, xBottom, yTop, yBottom As Integer
'Counters
Dim x1, x2 As Integer
'Position Holders
Dim x1h, x2h As Integer
'Iteration
Dim iLoops As Integer
 
Private Sub Command1_Click()
 
Debug.Print "X Top: " & UBound(helldivers, 1)
Debug.Print "X Bottom: " & LBound(helldivers, 1)
xTop = UBound(helldivers, 1)
xBottom = LBound(helldivers, 1)
 
Debug.Print "Y Top: " & UBound(helldivers, 2)
Debug.Print "Y Bottom: " & LBound(helldivers, 2)
yTop = UBound(helldivers, 1)
yBottom = LBound(helldivers, 1)
 
'Number of iterations - From 0 to Array(Max)
iLoops = (UBound(helldivers, 1) * 2) - 1
 
'Start - First Item in the Array
x1 = xTop
x2 = xBottom
 
Debug.Print "START-----------------------------------"
Debug.Print helldivers(x1, x2)
Debug.Print "END-----------------------------------"
 
Dim i As Integer
Dim iStop As Integer
 
'Main Loop
For i = 0 To iLoops
 
    Debug.Print "START-----------------------------------"
    If x1 >= 1 Then
        x1 = x1 - 1
    Else
        x2 = x2 + 1
    End If
    Debug.Print helldivers(x1, x2)
 
    If i >= xTop Then
        'Reverse - backwards
        iStop = iStop - 1
    Else
        'Normal - forward
        iStop = i + 1
    End If
 
    Dim h As Integer
    For h = 1 To iStop
        x1h = x1 + h
        x2h = x2 + h
        Debug.Print helldivers(x1h, x2h)
    Next h
 
    Debug.Print "END-----------------------------------"
 
Next i
 
End Sub
 
Private Sub Form_Load()
'First Set - Comment this out along with the Array definition at the top.
helldivers(0, 0) = "0,0"
helldivers(0, 1) = "1,0"
helldivers(0, 2) = "2,0"
helldivers(0, 3) = "3,0"
 
helldivers(1, 0) = "0,1"
helldivers(1, 1) = "1,1"
helldivers(1, 2) = "2,1"
helldivers(1, 3) = "3,1"
 
helldivers(2, 0) = "0,2"
helldivers(2, 1) = "1,2"
helldivers(2, 2) = "2,2"
helldivers(2, 3) = "3,2"
 
helldivers(3, 0) = "0,3"
helldivers(3, 1) = "1,3"
helldivers(3, 2) = "2,3"
helldivers(3, 3) = "3,3"
 
End Sub
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
Val: 147
Ha disminuido 1 puesto en Visual Basic (en relación al último mes)
Gráfica de Visual Basic

Recorrer array bidimencional

Publicado por Juan Gilberto (323 intervenciones) el 09/03/2016 17:07:56
Si es VB6 , es pertinente aclarar las siguientes lineas de codigo

1
2
3
Dim xTop, xBottom, yTop, yBottom As Integer
Dim x1, x2 As Integer
Dim x1h, x2h As Integer

Lo correcto es
1
2
3
Dim xTop As Integer ,  xBottom As Integer ,  yTop, yBottom As Integer
Dim x1 As Integer ,  x2 As Integer
Dim x1h As Integer ,  x2h As Integer

Cuando se declaran varias varables en una sola linea de DIM es necesario definir su tipo de datos a cada varable, de otra manera esta se declaran como tipo Variant

A veces no es muy importante como en este caso, pero si lo debemos de tener en cuenta
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