No os parece que ha pasado muchisimo desde el ultimo reto? :rolleyes: :xD
Pues este es bien simple... la forma mas rapida de pasar de numero a cadena...
Ej:
1337 -> "1337"
Por asi decirlo es un reemplazo a Str()
Ha de recibir Long y devolver String.
Ha de aceptar numeros negativos.
Venga, a codear!
Aqui esta, como siempre, la forma logica:
Public Function ItoA01(ByVal lNumb As Long) As String
ItoA01 = Str$(lNumb)
End Function
Mira el mio:
Public Function ItoA02(ByVal lNumber As Long) As String
ItoA02 = CStr(lNumber)
End Function
:xD :xD :laugh: :laugh:
PD: Si soy sincero no se ni por donde empezar... :-( :silbar:
DoEvents¡! :P
Pues la verdad dudo que se pueda hacer una funcion taan rapida como la CStr o Str$... pero bueno, ya hare la mia :P
Este es mi primer intento, no es mas rapido que CStr() ni Str(), pero he tenido una idea a ver si me sale, luego intento >:D
Public Static Function ItoA02(ByVal lNumb As Long) As String
Dim sTable(9) As String
Dim b As Boolean
Dim x As Boolean
x = CBool(lNumb And &H80000000)
If x Then lNumb = (lNumb Xor x) - x
If b = False Then
sTable(0) = "0": sTable(1) = "1"
sTable(2) = "2": sTable(3) = "3"
sTable(4) = "4": sTable(5) = "5"
sTable(6) = "6": sTable(7) = "7"
sTable(8) = "8": sTable(9) = "9"
b = True
End If
Do
ItoA02 = sTable(lNumb Mod 10) & ItoA02
lNumb = lNumb \ 10
Loop While lNumb
If x Then x = False: ItoA02 = "-" & ItoA02
End Function
Public Function ItoA03(ByVal lNumb As Long) As String
Dim bvRet(10) As Byte
Dim i As Long
Dim b As Boolean
b = lNumb < 0
If b Then lNumb = -lNumb
i = 10
Do
bvRet(i) = 48 + (lNumb Mod 10)
lNumb = lNumb \ 10
i = i - 1
Loop While lNumb
If b Then bvRet(i) = 45
ItoA03 = SysAllocStringLen(bvRet(i), 10 - i)
End Function
http://www.xbeat.net/vbspeed/download/TLB_string.zip
Mas rapido que Str(), pero no mas que CStr() :-\
Hola y no es valido asi?
Private Function ItoA03(lNumb As Long) As String
ItoA03 = lNumb
End Function
Cita de: LeandroA en 30 Agosto 2010, 23:37 PM
Hola y no es valido asi?
Private Function ItoA03(lNumb As Long) As String
ItoA03 = lNumb
End Function
Jajajajajajaja :xD
Aun mas rapido que el mio!!
LeandroA > PsYkE1 > Karcrack :laugh:
DoEvents¡! :P
Naaa karcrack, yo tenia una idea parecida, pero me tuve que ir :¬¬ aver...si se me ocurre algo.....
Cita de: LeandroA en 30 Agosto 2010, 23:37 PM
Hola y no es valido asi?
Private Function ItoA03(lNumb As Long) As String
ItoA03 = lNumb
End Function
No, no vale :¬¬ :¬¬ Eso es trampa! :xD No se porque pero cuando yo lo prove era mas lento :¬¬
Ale, pues otra cosa mas a la que superar :laugh:
MOD: Hace lo mismo que CStr internamente, asi que realmente es lo mismo :P
::) ::)
Public Function ItoA05(ByVal lNumb As Long) As String
Call VarBstrFromI4(lNumb, 0, 0, ItoA05)
End Function
http://www.box.net/shared/51biuct9cd
Creo que mas rapido o corto imposible :P
Saludos :D
Esto se llama perder el tiempo reiventando el casting :xD
Public Function StrRaul01(ByVal Number As Long) As String
If Number And &H80000000 Then
StrRaul01 = "-"
Number = Number * -1
End If
If Number = 0 Then StrRaul01 = "0": Exit Function
If Number = 1 Then StrRaul01 = "1": Exit Function
Dim i As Byte
Do While True
i = Fix(Number Mod 10)
Select Case i
Case 1: StrRaul01 = StrRaul01 & "1"
Case 2: StrRaul01 = StrRaul01 & "2"
Case 3: StrRaul01 = StrRaul01 & "3"
Case 4: StrRaul01 = StrRaul01 & "4"
Case 5: StrRaul01 = StrRaul01 & "5"
Case 6: StrRaul01 = StrRaul01 & "6"
Case 7: StrRaul01 = StrRaul01 & "7"
Case 8: StrRaul01 = StrRaul01 & "8"
Case 9: StrRaul01 = StrRaul01 & "9"
Case 0: StrRaul01 = StrRaul01 & "0"
End Select
Select Case Number
Case Is > 10: Number = Number \ 10
Case Is = 10
StrRaul01 = StrRaul01 & "10"
GoTo Final
Case Is < 10
GoTo Final
End Select
Loop
Final:
StrRaul01 = StrReverse(StrRaul01)
Dim s As String
Dim t As Integer
Dim l As Integer
t = 1
l = Len(StrRaul01)
If l = 1 Then Exit Function
For i = 1 To l
If Mid$(StrRaul01, i, 1) = "0" Then
t = t + 1
Else
StrRaul01 = Mid(StrRaul01, t)
Exit Function
End If
Next
End Function
Al menos es mas rapido que el primer intento de karcrack xDDD
Voy a ver si logro agilizarlo
.
Para mi LeandroA gano!¡.
P.D.: solo postee para decir, Que ojasos el de tu Gallo xP
Dulces Lunas!¡.
@Karcrack: Lo de LeandroA es lo que se conoce como "evil type convertion" (lo que salto en el otro post)
Por las dudas, pongo el mio, aunque es muy parecido:
Private Function ItoA03(lNumb As Long) As String
ItoA03 = "" & lNumb
End Function
Una duda:
Como mido el tiempo?
Cita de: ignorantev1.1 en 1 Septiembre 2010, 20:17 PM
Una duda:
Como mido el tiempo?
Con:
cTiming.cls (http://www.xbeat.net/vbspeed/download/CTiming.zip)
o con:
Private Declare Function GetTickCount Lib "kernel32" () As LongDoEvents¡! :P
Pues si use el mentado "GetTickCount" pero me da 0, a lo mejor lo estoy haciendo mal, por eso pregunte:
dim x as long
x=GetTickCount
****llamo funcion****
msgbox GetTickCount-x
Un ej:
Option Explicit
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Sub Form_Load()
Dim t1 As Long
Dim t2 As Long
t1 = GetTickCount '1ª marca
'Call Function
t2 = GetTickCount '2ª marca
MsgBox t2 - t1 'Resultado = diferencia entre marcas.
End Sub
DoEvents¡! :P
Option Explicit
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Sub Form_Load()
Dim t1 As Long
Dim t2 As Long
t1 = GetTickCount '1ª marca
Me.Print StrRaul01(-99999)
t2 = GetTickCount '2ª marca
MsgBox t2 - t1 'Resultado = diferencia entre marcas.
End Sub
Renuncio! siempre me da 0...
Ah, es que es tan poco tiempo que no se aprecia con
GetTickCount... :silbar:
Mira prueba con
cTiming.cls (http://www.xbeat.net/vbspeed/download/CTiming.zip) :
Un ej:
Option Explicit
Dim tmr As CTiming
Private Sub Form_Load()
Set tmr = New CTiming
tmr.Reset
Debug.Print StrRaul01(-99999)
MsgBox tmr.Elapsed
End SubResultado:
Citar0,28903007248116
Ahora si... :xD
DoEvents¡! :P