1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| Private Sub btnConvertir_Click()
Dim Tableau() As String
Dim Tableau2() As String
Dim intCount As Integer
Dim intCount2 As Integer
Dim strSQL As String
'découpe la chaine en fonction des espaces " "
'le résultat de la fonction Split est stocké dans un tableau
Tableau = Split(UserForm1.TextBox1.Value, " ")
'boucle sur le tableau pour visualiser le résultat
For intCount = 0 To UBound(Tableau)
Tableau2 = Split(Tableau(intCount), ",")
For intCount2 = 0 To UBound(Tableau2)
'conditions sur les éléments de syntaxe du langage SQL
Select Case Tableau2(intCount2)
Case Is = "SELECT", "UPDATE", "DELETE", "DISTINCT", "DISTINCTROW", "TOP", "PERCENT"
strSQL = strSQL + Tableau2(intCount2) & vbCrLf
Case Is = "INSERT"
strSQL = strSQL + Tableau(intCount) & " " & Tableau(intCount + 1) & vbCrLf
intCount = intCount + 1
Case Is = "FROM", "WHERE", "HAVING", "AS", "IN", "In"
strSQL = strSQL + vbCrLf & Tableau2(intCount2) & vbCrLf
Case Is = "ORDER", "GROUP", "INNER", "LEFT", "RIGHT"
strSQL = strSQL + vbCrLf & Tableau(intCount) & " " & Tableau(intCount + 1) & vbCrLf
intCount = intCount + 1
Case Is = "And", "Or", "AND", "OR"
strSQL = strSQL + Chr(9) & vbCrLf & Chr(9) & Tableau2(intCount2)
Case Else
strSQL = strSQL + " " & Tableau(intCount) & vbCrLf
End Select
Next intCount2
Next intCount
strSQL = Replace(strSQL, "(", " " + "(" + " ")
strSQL = Replace(strSQL, ")", " " + ")")
UserForm1.TextBox2.Value = strSQL
End Sub |