Autor
|
Tema: [SOLUCIONADO] Split (Leído 3,026 veces)
|
Miseryk
Desconectado
Mensajes: 225
SI.NU.SA U.GU.DE (2NE1 - D-Unit)
|
Hola, estaba tratando de hacer algo mientras me topé con un problema, tal vez parezca tonto o quizá nunca necesité algo así. Lo que quiero lograr, es encontrar la posición con respecto a un index de un Split. Code: Form: Option Explicit Private Sub Form_Load() Call ConfigArray Call Stuff End End Sub
Module: Option Explicit Public MyByteArray() As Byte Public Const StrByteArray As String = "255,254,253,0,252,0,0,0,251,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,250,0,0,0,0,0,0," & _ "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,249,0," & _ "0,0,3,4,248,3,0,247,246,5,6,2,245,244,5,6,243,242,7,241,8,240,9,10,239,9,11,12,8,238,11," & _ "13,13,10,237,8,236,14,8,9,235,13,8,7,13,8,7,234,233,8,12,10,232,14,231,15,15,230,229,0,0,0," & _ "0,0,0,0,228,227,226,16,5,2,17,18,5,2,17,18,5,2,17,18,225,224,4,18,223,2,17,18,222,19,18," & _ "18,20,2,17,18,21,22,221,18,220,2,17,18,21,22,219,18,23,2,17,18,5,2,218,18,16,2,17,18,21,22," & _ "217,18,19,2,17,18,21,22,216,218,23,2,17,18,21,22,215,18,20,2,17" Public MaxArray As Integer Public Sub ConfigArray() Dim i As Integer MaxArray = UBound(Split(StrByteArray, ",")) ReDim MyByteArray(0 To MaxArray) As Byte For i = 0 To MaxArray MyByteArray(i) = Split(StrByteArray, ",")(i) Next i End Sub Public Sub Stuff() Dim i As Integer Dim CurrentByte As Byte Dim found As Long Dim CurrentPos As Long For i = 0 To MaxArray If i = 5 Then 'Ejemplo, index 5 -> 255,254,253,0,252,0, CurrentByte = MyByteArray(i) CurrentPos = Aca quiero obtener la posicion del index 5 End If Next i End Sub
CurrentPos = Aca quiero obtener la posicion del index 5, que sería 19 Alguna idea o algún comando mágico que me retorne la posición según el index?
|
|
« Última modificación: 20 Julio 2013, 15:51 pm por Miseryk »
|
En línea
|
Can you see it? The worst is over The monsters in my head are scared of love Fallen people listen up! It’s never too late to change our luck So, don’t let them steal your light Don’t let them break your stride There is light on the other side And you’ll see all the raindrops falling behind Make it out tonight it’s a revolution
CL!!!
|
|
|
raul338
Desconectado
Mensajes: 2.633
La sonrisa es la mejor forma de afrontar las cosas
|
No entiendo de que queres la posicion: La posición en el string del valor que esta en el array (index 1, pos 1; index 2, pos 4; index 3, pos 8; index 4, pos 12; index 5, pos 13...) Si es así deberias sumar el length del string de cada uno de los items del array que vas recorriendo + el contador (la cantidad de separadores que pasaste)
Otra cosa, ConfigArray se puede optimizar mucho! Trata de usar una sola vez Split y trabaja con el array devuelto, ese for con el split adentro tarda mucho porque tiene hacer tantas veces split una y otra vez cuando ya lo hizo antes para obtener el ubound! Ademas de que estas duplicando el array que te devuelve el split
|
|
|
En línea
|
|
|
|
Miseryk
Desconectado
Mensajes: 225
SI.NU.SA U.GU.DE (2NE1 - D-Unit)
|
Muy cierto, no me había dado cuenta. Muchas gracias, de lo la longitud lo pude hacer, pero de otra manera a la que quería. Option Explicit Private Sub Form_Load() Call ConfigArray Call Stuff End End Sub
Option Explicit Public MyByteArray() As Byte Public Const StrByteArray As String = "255,254,253,0,252,0,0,0,251,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,250,0,0,0,0,0,0," & _ "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,249,0," & _ "0,0,3,4,248,3,0,247,246,5,6,2,245,244,5,6,243,242,7,241,8,240,9,10,239,9,11,12,8,238,11," & _ "13,13,10,237,8,236,14,8,9,235,13,8,7,13,8,7,234,233,8,12,10,232,14,231,15,15,230,229,0,0,0," & _ "0,0,0,0,228,227,226,16,5,2,17,18,5,2,17,18,5,2,17,18,225,224,4,18,223,2,17,18,222,19,18," & _ "18,20,2,17,18,21,22,221,18,220,2,17,18,21,22,219,18,23,2,17,18,5,2,218,18,16,2,17,18,21,22," & _ "217,18,19,2,17,18,21,22,216,218,23,2,17,18,21,22,215,18,20,2,17" Public MaxArray As Integer Public colObject As New Collection Public Sub ConfigArray() Dim i As Integer Dim pos As Double Dim newpos As Double Dim SplitOneTime As Variant SplitOneTime = Split(StrByteArray, ",") MaxArray = UBound(SplitOneTime) ReDim MyByteArray(0 To MaxArray) As Byte pos = 1 For i = 0 To MaxArray MyByteArray(i) = SplitOneTime(i) If i = 0 Then colObject.Add Array((i + 1), CStr(1)) Else newpos = InStr(pos, StrByteArray, ",") + 1 colObject.Add Array((i + 1), CStr(newpos)) pos = newpos End If Next i End Sub Public Sub Stuff() Dim i As Integer Dim CurrentByte As Byte Dim found As Double Dim CurrentPos As Double Dim NextPos As Double Dim FirstPattern As String Dim SecondPattern As String For i = 0 To MaxArray 'Ejemplo, index 5 -> 255,254,253,0,252,0,0,0,251,0,0,0,1,1,0,0,0 CurrentByte = MyByteArray(i) If i = 103 Then Stop CurrentPos = colObject(i + 1)(1) NextPos = colObject(i + 2)(1) found = InStr(NextPos, StrByteArray, CurrentByte) FirstPattern = Mid(StrByteArray, CurrentPos, found - CurrentPos) '= "13,8,7," SecondPattern = Mid(StrByteArray, found, found - CurrentPos) '= "13,8,7," MsgBox StrComp(FirstPattern, SecondPattern) = 0 End If Next i End Sub
Ahí obtuve el CurrentPos y el NextPos que quería para encontrar coincidencias con mid y found. PD: pero no es lo que quería, no quería usar Public colObject As New Collection
para obtener las posiciones en mid para el index del array o del split.
|
|
« Última modificación: 19 Julio 2013, 21:07 pm por Miseryk »
|
En línea
|
Can you see it? The worst is over The monsters in my head are scared of love Fallen people listen up! It’s never too late to change our luck So, don’t let them steal your light Don’t let them break your stride There is light on the other side And you’ll see all the raindrops falling behind Make it out tonight it’s a revolution
CL!!!
|
|
|
DarkMatrix
Desconectado
Mensajes: 150
Nuestro Limite es la Imaginacion
|
Y asi: Option Explicit Public MyBytePos() As Long Public MyByteArray() As Byte Public Const StrByteArray As String = "255,254,253,0,252,0,0,0,251,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,250,0,0,0,0,0,0," & _ "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,249,0," & _ "0,0,3,4,248,3,0,247,246,5,6,2,245,244,5,6,243,242,7,241,8,240,9,10,239,9,11,12,8,238,11," & _ "13,13,10,237,8,236,14,8,9,235,13,8,7,13,8,7,234,233,8,12,10,232,14,231,15,15,230,229,0,0,0," & _ "0,0,0,0,228,227,226,16,5,2,17,18,5,2,17,18,5,2,17,18,225,224,4,18,223,2,17,18,222,19,18," & _ "18,20,2,17,18,21,22,221,18,220,2,17,18,21,22,219,18,23,2,17,18,5,2,218,18,16,2,17,18,21,22," & _ "217,18,19,2,17,18,21,22,216,218,23,2,17,18,21,22,215,18,20,2,17" Public MaxArray As Integer Public Sub ConfigArray() Dim I As Integer Dim Pos As Double Dim NewPos As Double Dim SplitOneTime() As String SplitOneTime = Split(StrByteArray, ",") MaxArray = UBound(SplitOneTime) ReDim MyBytePos(0 To MaxArray) ReDim MyByteArray(0 To MaxArray) Pos = 1 For I = 0 To MaxArray MyByteArray(I) = CByte(SplitOneTime(I)) If I = 0 Then MyBytePos(I) = 1 Else MyBytePos(I) = (MyBytePos(I - 1) + Len(SplitOneTime(I - 1))) + 1 End If Next I 'MsgBox MyBytePos(5) ' = 19 'MsgBox MyBytePos(40) ' = 93 End Sub Public Sub Stuff() Dim I As Integer Dim CurrentByte As Byte Dim found As Double Dim CurrentPos As Double Dim NextPos As Double Dim FirstPattern As String Dim SecondPattern As String For I = 0 To MaxArray 'Ejemplo, index 5 -> 255,254,253,0,252,0,0,0,251,0,0,0,1,1,0,0,0 CurrentByte = MyByteArray(I) If I = 103 Then Stop CurrentPos = MyBytePos(I) NextPos = MyBytePos(I + 1) found = InStr(NextPos, StrByteArray, CurrentByte) FirstPattern = Mid(StrByteArray, CurrentPos, found - CurrentPos) '= "13,8,7," SecondPattern = Mid(StrByteArray, found, found - CurrentPos) '= "13,8,7," MsgBox StrComp(FirstPattern, SecondPattern) = 0 End If Next I End Sub
|
|
|
En línea
|
Todo aquello que no se puede hacer, es lo que no intentamos hacer. Projecto Ani-Dimension Digital Duel Masters (Juego de cartas masivo multijugador online hecho en Visual Basic 6.0) Desing by DarkMatrix
|
|
|
Miseryk
Desconectado
Mensajes: 225
SI.NU.SA U.GU.DE (2NE1 - D-Unit)
|
También, pero andaba buscando algún método o algo del split SplitOneTime = Split(StrByteArray, ",")
con el cual pueda obtener esa pocisión sin tener que declarar otra varible ya sea array o collección.
|
|
« Última modificación: 20 Julio 2013, 04:17 am por Miseryk »
|
En línea
|
Can you see it? The worst is over The monsters in my head are scared of love Fallen people listen up! It’s never too late to change our luck So, don’t let them steal your light Don’t let them break your stride There is light on the other side And you’ll see all the raindrops falling behind Make it out tonight it’s a revolution
CL!!!
|
|
|
Miseryk
Desconectado
Mensajes: 225
SI.NU.SA U.GU.DE (2NE1 - D-Unit)
|
Aunque no sea la respuesta que quiero, me ayuda a resolver mi problema, es por éso que lo pongo como SOLUCIONADO y no como RESUELTO, si quieren aportar nuevas cosas, bienvenidos sean Gracias a todos.
|
|
|
En línea
|
Can you see it? The worst is over The monsters in my head are scared of love Fallen people listen up! It’s never too late to change our luck So, don’t let them steal your light Don’t let them break your stride There is light on the other side And you’ll see all the raindrops falling behind Make it out tonight it’s a revolution
CL!!!
|
|
|
BlackZeroX
Wiki
Desconectado
Mensajes: 3.158
I'Love...!¡.
|
Esto es mas fácil que un split... y te olvidas de convertir de string a byte o integer dim MyBytePos() as Byte ' Si los numeros en el Array son mayors usa Integer en lugar de byte y si son mayores usa long y si no pss Double.... MyBytePos = Array(255,254,253,0,252,0,0,0,251,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,250,0,0,0,0,0,0, _ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,249,0, _ 0,0,3,4,248,3,0,247,246,5,6,2,245,244,5,6,243,242,7,241,8,240,9,10,239,9,11,12,8,238,11, _ 13,13,10,237,8,236,14,8,9,235,13,8,7,13,8,7,234,233,8,12,10,232,14,231,15,15,230,229,0,0,0, _ 0,0,0,0,228,227,226,16,5,2,17,18,5,2,17,18,5,2,17,18,225,224,4,18,223,2,17,18,222,19,18, _ 18,20,2,17,18,21,22,221,18,220,2,17,18,21,22,219,18,23,2,17,18,5,2,218,18,16,2,17,18,21,22, _ 217,18,19,2,17,18,21,22,216,218,23,2,17,18,21,22,215,18,20,2,17) debug.print chr(34) & Join(days(), ",") & chr(34) ' Esta linea la puedes quitar sin problemas debug.print "Posicion Numero 0:"; MyBytePos(0) debug.print "Posicion Numero 5:"; MyBytePos(5)
Dulces Lunas!¡.
|
|
« Última modificación: 21 Julio 2013, 09:43 am por BlackZeroX (Astaroth) »
|
En línea
|
The Dark Shadow is my passion.
|
|
|
|
Mensajes similares |
|
Asunto |
Iniciado por |
Respuestas |
Vistas |
Último mensaje |
|
|
No me va el split second :(
Juegos y Consolas
|
Hacker wifi
|
2
|
3,232
|
2 Octubre 2010, 15:03 pm
por Hacker wifi
|
|
|
[C] Split
Programación C/C++
|
_*p
|
3
|
3,041
|
19 Febrero 2011, 15:55 pm
por _*p
|
|
|
Split C++
Programación C/C++
|
|Apeiron|
|
0
|
2,045
|
21 Noviembre 2011, 16:18 pm
por |Apeiron|
|
|
|
[SOLUCIONADO] VB Split
Programación C/C++
|
Miseryk
|
3
|
2,935
|
24 Enero 2012, 19:29 pm
por Miseryk
|
|
|
Split en C
Programación C/C++
|
Distorsion
|
4
|
2,746
|
29 Octubre 2012, 03:18 am
por rir3760
|
|