| 
 
 
 |  |  |  | Version : 97 principalement | Function TInstrRev(Texte As String, cherche As String, _
Optional Start As Integer = 0, _
Optional Comparaison As integer= vbTextCompare) _
As Integer
On Error GoTo err
If Start < 1 Then Start = Len(Texte)
Texte = Right(Texte, Start)
While InStr(TInstrRev + 1, Texte, cherche, Comparaison) > 0
TInstrRev = InStr(TInstrRev + 1, Texte, cherche, Comparaison)
Wend
Exit Function
err:
MsgBox "Vérifier vos paramètres", vbCritical, "Fonction TInstrRev"
End Function | 
Utilisation : | MsgBox TInstrRev("Toto", "to", 2) | 
Cet exemple affichera : 1 
 | 
 
 | | Auteur : Shwin 
 |  | Version : 28/01/2005 |  |  |  |  | 
 |  |  | Versions : 97 principalement | Public Function ReplaceT(ByVal Expression As String, _
                         ByVal Find As String, _
                         ByVal Replace As String, _
                Optional ByVal Start As Long = 1, _
                Optional ByVal Count As Long = -1, _
                Optional ByVal Compare As Integer = vbTextCompare) _
                As String
               
Dim P As Long            
Dim L As Long            
Dim f As Long            
Dim r As Long            
 
Let L = Len(Expression)
If Start > L Then
    ' parceque "Right$" n
    Let Expression = vbNullString
ElseIf Start > 1 Then
    
    Let Expression = Right$(Expression, L - Start + 1)
    End If
ReplaceT = Expression    
 
If Find = vbNullString Then Exit Function
Let f = Len(Find)
Let r = Len(Replace)    
Let P = 1                
If Count <> 0 Then
    Do
        
        
        
        
        Let L = Len(Expression)
        
        Let P = InStr(P, Expression, Find, Compare)
        
        If P > 0 Then
            Let Expression = Left$(Expression, P - 1) + _
                             Replace + _
                             Right$(Expression, (L - P - f + 1))
            
            
            Let P = P + r
            
            
            Let Count = Count - 1
            End If
        
        
        
        Loop Until (P <= 0) Or (Count = 0)
    End If
ReplaceT = Expression        
End Function | 
 | 
 
 | | Auteur : extros 
 |  | Version : 28/01/2005 |  |  |  |  | 
 |  |  | Versions : 97 principalement 
 Voici une fonction d'arrondi (spécialement utile pour la comptabilité) : Parfois, certaines fonctions arrondissent 0,4450 a 0,44 au lieu de 0,45 comme c'est nécessaire parfois en comptabilité. 
Avec celle-ci, il est même possible de choisir le chiffre qui induit un arrondi supérieur.
 | Function RoundCost(ByVal Nbr As Double, Optional ByVal Expo As Long = 2, _
Optional ByVal NextNumSup = 5) As Double 
    If Expo < 0 Then RoundCost = RoundCost(Nbr * 10 ^ Expo, Abs(Expo)) 
    RoundCost = CLng(Nbr * 10 ^ Expo + (0.01 * (10 - NextNumSup))) / 10 ^ Expo 
End Function | 
 | 
 
 |  |  |  | Versions : 97 principalement | Public Function FctSplit(ByVal strg As String, Sep As String) As Variant 
    Dim i As Integer 
    Dim TblSplit() As String 
    i = 1 
    While InStr(1, strg, Sep) <> 0 
        ReDim Preserve TblSplit(i) 
        TblSplit(i - 1) = Left(strg, InStr(1, strg, Sep) - 1) 
        strg = Mid(strg, InStr(1, strg, Sep) + Len(Sep)) 
        i = i + 1 
    Wend 
    If Len(strg) > 0 Then 
        ReDim Preserve TblSplit(i) 
        TblSplit(i - 1) = strg 
    End If 
    FctSplit = TblSplit 
End Function | 
Utilisation :  | Dim T() as string
T=FctSplit("Bonjour Monsieur Dupont"," ") | 
Ce code renvoit un tableau contenant chaque mot de la phrase passée en paramètre. 
 | 
 
 |  |  |  | 
Versions : Antérieures à 2002
 
 
Cet exemple permet d'exporter une requête ou une table vers un fichier XML en utilisant ADO.
 
 
Pour cela vous devez ajouter la référence Microsoft ActiveX Data Object à votre projet.
 | Public Function xmlXport(ByVal strTableorQuery As String) 
Dim cnx As New ADODB.Connection 
Dim rec As New ADODB.Recordset 
cnx.Provider = "Microsoft.Jet.Oledb.4.0" 
cnx.ConnectionString = CurrentDb.name 
cnx.Open 
rec.Open "SELECT * FROM [" & strTableorQuery & "]", cnx 
    
rec.save "D:\temp\" & strTableorQuery & ".xml", adPersistXML 
rec.Close 
cnx.Close 
Set rec = Nothing 
Set cnx = Nothing 
End Function | 
Exemple d'utilisation : 
 | 
 
 
  
 |