
Public Function Replacez(a As String, c As String) As String On Error Resume Next Dim d As Long d = InStr(a, z) Replacez = Left$(a, d - 1) & c & Right$(a, Len(a) - d) End Function |
Public Function Replacez(a As String, c As String) As String On Error Resume Next Dim d As Long d = InStr(a, z) Replacez = Left$(a, d - 1) & c & Right$(a, Len(a) - d) End Function |
Public Function Replacez(a As String, c As String) As String On Error Resume Next Dim d As Long d = InStr(a, "z") Replacez = Left$(a, d - 1) & c & Right$(a, Len(a) - d) End Function |
Option Explicit
Dim re As RegExp
'riferimenti a Microsoft VBScript Regular Expressions 5.5
Public Function Replacez(a As String, c As String) As String
On Error Resume Next
Dim d As Long
d = InStr(a, "z")
Replacez = Left$(a, d - 1) & c & Right$(a, Len(a) - d)
End Function
Function replaceZ_2(a As String, b As String) As String
replaceZ_2 = VBA.Replace(a, "z", b)
End Function
Function replaceZ_3(a As String, b As String) As String
replaceZ_3 = re.Replace(a, b)
End Function
Function replaceZ_4(a As String, b As String) As String
replaceZ_4 = Join(Split(a, "z"), b)
End Function
Sub test()
Dim start As Double
Dim i As Long
Dim s As String
start = Timer
For i = 1 To 1000000
s = Replacez("paozlo", "paolo")
Next i
Debug.Print Timer - start '1,79712500000005
start = Timer
For i = 1 To 1000000
s = replaceZ_2("paozlo", "paolo")
Next i
Debug.Print Timer - start '3,42199999999957
start = Timer
Set re = New RegExp
re.Pattern = "z"
For i = 1 To 1000000
s = replaceZ_3("paozlo", "paolo")
Next i
Debug.Print Timer - start '2,62476171875005
start = Timer
For i = 1 To 1000000
s = replaceZ_4("paozlo", "paolo")
Next i
Debug.Print s
Debug.Print Timer - start '5,13989843750005
End Sub
|
Public Function Factt(a As String) As Double 'Fattoriale di a On Error Resume Next If Errr Then If (Int(a) - a) = 0 And a >= 0 Then Dim g As Long Factt = 1: For g = 2 To a: Factt = Factt * g: Next g: Errr = True: Exit Function Else Errr = False: Exit Function End If: End If End Function |
Option Explicit
Dim Fattoriale(170) As Double
Dim errr As Boolean
Sub Carica_d()
Dim i As Long
Fattoriale(0) = 0
Fattoriale(1) = 1
For i = 2 To 170
Fattoriale(i) = Fattoriale(i - 1) * i
Next
End Sub
Function Factt_2(a As String) As Double 'Fattoriale di a
On Error Resume Next
If errr Then
If (Int(a) - a) = 0 And a >= 0 Then
Factt_2 = Fattoriale(a)
errr = True
Exit Function
Else
errr = False
Exit Function
End If
End If
End Function
Sub test()
Dim start As Double
Dim i As Long, a As Long
Dim d As Double
start = Timer
For a = 1 To 100000
For i = 3 To 170
d = Factt(CStr(i))
Next
Next
Debug.Print Timer - start
start = Timer
'chiamo il caricamento del vettore fattoriale
Carica_d
For a = 1 To 100000
For i = 3 To 170
d = Factt_2(CStr(i))
Next
Next
Debug.Print Timer - start
End Sub
Public Function Factt(a As String) As Double 'Fattoriale di a
On Error Resume Next
If errr Then
If (Int(a) - a) = 0 And a >= 0 Then
Dim g As Long
Factt = 1
For g = 2 To a
Factt = Factt * g
Next g
errr = True
Exit Function
Else
errr = False
Exit Function
End If
End If
End Function |
Function Factt_2(a As String) As Double 'Fattoriale di a
On Error Resume Next
If errr Then
If (Int(a) - a) = 0 And a >= 0 Then
Factt_2 = Fattoriale(a)
Else
errr = False
End If
End If
End Function
|
Function Factt_2(a As String) As Double 'Fattoriale di a
On Error Resume Next
If errr Then
If (Int(a) - a) = 0 And a >= 0 Then
Factt_2 = Fattoriale(a)
errr = True
Else
errr = False
End If
End If
End Function
|
