R
Ricardo Furtado
I have a big problem concerning arrays.
I have an array of structs that is deply implemented in the code. If i
change this implementation then i have to change everything, so after
searching google and a lot of newsgroups i came up with this question:
With the following array, how can i make a search without having to use a
loop to seek for a certain "thing" in the array of structs?
(i've tryed to use array.find(), but because its an array of structs i just
wasn't able to make it work)
Friend Sub AdicionaPontosAImagem(ByVal ValorX As Long, ByVal ValorY As Long,
ByVal strNomePonto As String, _
ByVal lngHwnd As Long, ByVal strNomeAnalise As String, _
Optional ByRef myGraphics As System.Drawing.Graphics = Nothing)
Dim lngContador As Long
Dim bolFlag As Boolean
bolFlag = False
If ArrayPontos(0).bolInicializacao = True Then
ArrayPontos(0).bolInicializacao = False
ArrayPontos(0).strNomePonto = strNomePonto
ArrayPontos(0).lngValorX = ValorX
ArrayPontos(0).lngValorY = ValorY
ArrayPontos(0).strAbreviatura =
BD.retornaAbreviaturaDeDeterminadoPonto(strNomePonto)
ArrayPontos(0).Posicoes.intPreenchidas = 0
ArrayPontosImg(0).bolInicializacao = False
ArrayPontosImg(0).lngValorX = ValorX
ArrayPontosImg(0).lngValorY = ValorY
ReDim ArrayPontosImg(0).ptnPontos(5)
ArrayPontosImg(0).ptnPontos(0).X = ValorX
ArrayPontosImg(0).ptnPontos(0).Y = ValorY - 1
ArrayPontosImg(0).ptnPontos(1).X = ValorX
ArrayPontosImg(0).ptnPontos(1).Y = ValorY
ArrayPontosImg(0).ptnPontos(2).X = ValorX
ArrayPontosImg(0).ptnPontos(2).Y = ValorY + 1
ArrayPontosImg(0).ptnPontos(3).X = ValorX - 1
ArrayPontosImg(0).ptnPontos(3).Y = ValorY
ArrayPontosImg(0).ptnPontos(4).X = ValorX + 1
ArrayPontosImg(0).ptnPontos(4).Y = ValorY
If (defPerfilGlobal = DefinicaoPerfil.pontosFulcrais) AndAlso (Not
IsNothing(myGraphics)) Then
identificaPerfilAutomaticamente(myGraphics)
End If
Else
For lngContador = 0 To UBound(ArrayPontos) - 1
If ArrayPontos(lngContador).strNomePonto = strNomePonto Then
ArrayPontos(lngContador).lngValorX = ValorX
ArrayPontos(lngContador).lngValorY = ValorY
ArrayPontos(lngContador).strAbreviatura =
BD.retornaAbreviaturaDeDeterminadoPonto(strNomePonto)
ArrayPontosImg(lngContador).bolInicializacao = False
ArrayPontosImg(lngContador).lngValorX = ValorX
ArrayPontosImg(lngContador).lngValorY = ValorY
ReDim ArrayPontosImg(lngContador).ptnPontos(5)
ArrayPontosImg(lngContador).ptnPontos(0).X = ValorX
ArrayPontosImg(lngContador).ptnPontos(0).Y = ValorY - 1
ArrayPontosImg(lngContador).ptnPontos(1).X = ValorX
ArrayPontosImg(lngContador).ptnPontos(1).Y = ValorY
ArrayPontosImg(lngContador).ptnPontos(2).X = ValorX
ArrayPontosImg(lngContador).ptnPontos(2).Y = ValorY + 1
ArrayPontosImg(lngContador).ptnPontos(3).X = ValorX - 1
ArrayPontosImg(lngContador).ptnPontos(3).Y = ValorY
ArrayPontosImg(lngContador).ptnPontos(4).X = ValorX + 1
ArrayPontosImg(lngContador).ptnPontos(4).Y = ValorY
bolFlag = True
Exit For
End If
Next
If Not bolFlag Then
ReDim Preserve ArrayPontos(UBound(ArrayPontos) + 1)
ArrayPontos(UBound(ArrayPontos) - 1).bolInicializacao = False
ArrayPontos(UBound(ArrayPontos) - 1).strNomePonto = strNomePonto
ArrayPontos(UBound(ArrayPontos) - 1).lngValorX = ValorX
ArrayPontos(UBound(ArrayPontos) - 1).lngValorY = ValorY
ArrayPontos(UBound(ArrayPontos) - 1).strAbreviatura =
BD.retornaAbreviaturaDeDeterminadoPonto(strNomePonto)
ArrayPontos(UBound(ArrayPontos) - 1).Posicoes.intPreenchidas = 0
ReDim Preserve ArrayPontosImg(UBound(ArrayPontosImg) + 1)
ArrayPontosImg(UBound(ArrayPontosImg) - 1).bolInicializacao = False
ArrayPontosImg(UBound(ArrayPontosImg) - 1).lngValorX = ValorX
ArrayPontosImg(UBound(ArrayPontosImg) - 1).lngValorY = ValorY
ReDim ArrayPontosImg(UBound(ArrayPontosImg) - 1).ptnPontos(5)
ArrayPontosImg(UBound(ArrayPontosImg) - 1).ptnPontos(0).X = ValorX
ArrayPontosImg(UBound(ArrayPontosImg) - 1).ptnPontos(0).Y = ValorY - 1
ArrayPontosImg(UBound(ArrayPontosImg) - 1).ptnPontos(1).X = ValorX
ArrayPontosImg(UBound(ArrayPontosImg) - 1).ptnPontos(1).Y = ValorY
ArrayPontosImg(UBound(ArrayPontosImg) - 1).ptnPontos(2).X = ValorX
ArrayPontosImg(UBound(ArrayPontosImg) - 1).ptnPontos(2).Y = ValorY + 1
ArrayPontosImg(UBound(ArrayPontosImg) - 1).ptnPontos(3).X = ValorX - 1
ArrayPontosImg(UBound(ArrayPontosImg) - 1).ptnPontos(3).Y = ValorY
ArrayPontosImg(UBound(ArrayPontosImg) - 1).ptnPontos(4).X = ValorX + 1
ArrayPontosImg(UBound(ArrayPontosImg) - 1).ptnPontos(4).Y = ValorY
If (defPerfilGlobal = DefinicaoPerfil.pontosFulcrais) AndAlso (Not
IsNothing(myGraphics)) Then
identificaPerfilAutomaticamente(myGraphics)
End If
End If
End If
TracaRectas(lngHwnd, strNomeAnalise)
RaiseEvent registaPontoNaListagem(strNomePonto)
End Sub
I have an array of structs that is deply implemented in the code. If i
change this implementation then i have to change everything, so after
searching google and a lot of newsgroups i came up with this question:
With the following array, how can i make a search without having to use a
loop to seek for a certain "thing" in the array of structs?
(i've tryed to use array.find(), but because its an array of structs i just
wasn't able to make it work)
Friend Sub AdicionaPontosAImagem(ByVal ValorX As Long, ByVal ValorY As Long,
ByVal strNomePonto As String, _
ByVal lngHwnd As Long, ByVal strNomeAnalise As String, _
Optional ByRef myGraphics As System.Drawing.Graphics = Nothing)
Dim lngContador As Long
Dim bolFlag As Boolean
bolFlag = False
If ArrayPontos(0).bolInicializacao = True Then
ArrayPontos(0).bolInicializacao = False
ArrayPontos(0).strNomePonto = strNomePonto
ArrayPontos(0).lngValorX = ValorX
ArrayPontos(0).lngValorY = ValorY
ArrayPontos(0).strAbreviatura =
BD.retornaAbreviaturaDeDeterminadoPonto(strNomePonto)
ArrayPontos(0).Posicoes.intPreenchidas = 0
ArrayPontosImg(0).bolInicializacao = False
ArrayPontosImg(0).lngValorX = ValorX
ArrayPontosImg(0).lngValorY = ValorY
ReDim ArrayPontosImg(0).ptnPontos(5)
ArrayPontosImg(0).ptnPontos(0).X = ValorX
ArrayPontosImg(0).ptnPontos(0).Y = ValorY - 1
ArrayPontosImg(0).ptnPontos(1).X = ValorX
ArrayPontosImg(0).ptnPontos(1).Y = ValorY
ArrayPontosImg(0).ptnPontos(2).X = ValorX
ArrayPontosImg(0).ptnPontos(2).Y = ValorY + 1
ArrayPontosImg(0).ptnPontos(3).X = ValorX - 1
ArrayPontosImg(0).ptnPontos(3).Y = ValorY
ArrayPontosImg(0).ptnPontos(4).X = ValorX + 1
ArrayPontosImg(0).ptnPontos(4).Y = ValorY
If (defPerfilGlobal = DefinicaoPerfil.pontosFulcrais) AndAlso (Not
IsNothing(myGraphics)) Then
identificaPerfilAutomaticamente(myGraphics)
End If
Else
For lngContador = 0 To UBound(ArrayPontos) - 1
If ArrayPontos(lngContador).strNomePonto = strNomePonto Then
ArrayPontos(lngContador).lngValorX = ValorX
ArrayPontos(lngContador).lngValorY = ValorY
ArrayPontos(lngContador).strAbreviatura =
BD.retornaAbreviaturaDeDeterminadoPonto(strNomePonto)
ArrayPontosImg(lngContador).bolInicializacao = False
ArrayPontosImg(lngContador).lngValorX = ValorX
ArrayPontosImg(lngContador).lngValorY = ValorY
ReDim ArrayPontosImg(lngContador).ptnPontos(5)
ArrayPontosImg(lngContador).ptnPontos(0).X = ValorX
ArrayPontosImg(lngContador).ptnPontos(0).Y = ValorY - 1
ArrayPontosImg(lngContador).ptnPontos(1).X = ValorX
ArrayPontosImg(lngContador).ptnPontos(1).Y = ValorY
ArrayPontosImg(lngContador).ptnPontos(2).X = ValorX
ArrayPontosImg(lngContador).ptnPontos(2).Y = ValorY + 1
ArrayPontosImg(lngContador).ptnPontos(3).X = ValorX - 1
ArrayPontosImg(lngContador).ptnPontos(3).Y = ValorY
ArrayPontosImg(lngContador).ptnPontos(4).X = ValorX + 1
ArrayPontosImg(lngContador).ptnPontos(4).Y = ValorY
bolFlag = True
Exit For
End If
Next
If Not bolFlag Then
ReDim Preserve ArrayPontos(UBound(ArrayPontos) + 1)
ArrayPontos(UBound(ArrayPontos) - 1).bolInicializacao = False
ArrayPontos(UBound(ArrayPontos) - 1).strNomePonto = strNomePonto
ArrayPontos(UBound(ArrayPontos) - 1).lngValorX = ValorX
ArrayPontos(UBound(ArrayPontos) - 1).lngValorY = ValorY
ArrayPontos(UBound(ArrayPontos) - 1).strAbreviatura =
BD.retornaAbreviaturaDeDeterminadoPonto(strNomePonto)
ArrayPontos(UBound(ArrayPontos) - 1).Posicoes.intPreenchidas = 0
ReDim Preserve ArrayPontosImg(UBound(ArrayPontosImg) + 1)
ArrayPontosImg(UBound(ArrayPontosImg) - 1).bolInicializacao = False
ArrayPontosImg(UBound(ArrayPontosImg) - 1).lngValorX = ValorX
ArrayPontosImg(UBound(ArrayPontosImg) - 1).lngValorY = ValorY
ReDim ArrayPontosImg(UBound(ArrayPontosImg) - 1).ptnPontos(5)
ArrayPontosImg(UBound(ArrayPontosImg) - 1).ptnPontos(0).X = ValorX
ArrayPontosImg(UBound(ArrayPontosImg) - 1).ptnPontos(0).Y = ValorY - 1
ArrayPontosImg(UBound(ArrayPontosImg) - 1).ptnPontos(1).X = ValorX
ArrayPontosImg(UBound(ArrayPontosImg) - 1).ptnPontos(1).Y = ValorY
ArrayPontosImg(UBound(ArrayPontosImg) - 1).ptnPontos(2).X = ValorX
ArrayPontosImg(UBound(ArrayPontosImg) - 1).ptnPontos(2).Y = ValorY + 1
ArrayPontosImg(UBound(ArrayPontosImg) - 1).ptnPontos(3).X = ValorX - 1
ArrayPontosImg(UBound(ArrayPontosImg) - 1).ptnPontos(3).Y = ValorY
ArrayPontosImg(UBound(ArrayPontosImg) - 1).ptnPontos(4).X = ValorX + 1
ArrayPontosImg(UBound(ArrayPontosImg) - 1).ptnPontos(4).Y = ValorY
If (defPerfilGlobal = DefinicaoPerfil.pontosFulcrais) AndAlso (Not
IsNothing(myGraphics)) Then
identificaPerfilAutomaticamente(myGraphics)
End If
End If
End If
TracaRectas(lngHwnd, strNomeAnalise)
RaiseEvent registaPontoNaListagem(strNomePonto)
End Sub