|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Junior Member
Iscritto dal: Aug 2003
Messaggi: 25
|
[VBA] HELP
volevo fare una funzione che passatagli una stringa e un separatore mi restituisse una collection con le sub-stringhe che il separatore delimita
Sub passastr() Dim j As New Collection stringa = "a;Bcdefg;ghek;ehsie;" sep = ";" Set j = DS(stringa, sep) End Sub Function DS(ByVal stringa As String, ByVal sep As String) As Collection Dim substr As New Collection k = 1 'posini y = 0 'posfina Do y = InStr(k, stringa, sep, vbTextCompare) 'si becca il valore della posiozne del separatore If y > 0 Then substr.Add Mid(stringa, k, y - k) k = y + 1 End If Loop While y > 0 DS = substr End Function ho un errore di compilazione in : DS1 = substr dove mi dice "Argomento non facoltativo" , ma non ho capito quale elemento vuole qualche suggerimento? |
|
|
|
|
|
#2 |
|
Member
Iscritto dal: Aug 2001
Città: Gerenzano
Messaggi: 129
|
Se invece di una collection ti basta un'array puoi usare direttamente il metodo SPLIT, oppure creare una routine di questo tipo.
Codice:
Function DS(ByVal sStringa As String, ByVal sSep As String) As Collection
Dim collRet As Collection
Dim sSplit() As String
Dim lUBound As Long
Dim lLowBound As Long
Dim l As Long
Set collRet = New Collection
sSplit() = Split(sStringa, sSep)
lUBound = UBound(sSplit())
lLowBound = LBound(sSplit())
For l = 1 To lUBound
collRet.Add sSplit(l)
Next l
Set DS = collRet
End Function
__________________
E' quasi tutto relativo! |
|
|
|
|
|
#3 |
|
Member
Iscritto dal: Aug 2001
Città: Gerenzano
Messaggi: 129
|
Ops, riguardo al tuo problema "Argomento non facoltativo" è perchè devi usare la parola chiave SET per impostare il valore di ritorno della funzione.
Non: DS = substr ma: SET DS = substr Ciao!
__________________
E' quasi tutto relativo! |
|
|
|
|
|
#4 |
|
Junior Member
Iscritto dal: Aug 2003
Messaggi: 25
|
Tnx a lot
|
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 04:46.



















