donny3 | salut,
J'essai de creer un script vbs qui me permette à partir d'un fichier csv d'en creer un autre qui contienne un script sql pour creer des tables;
un exemple
fichier.csv
Citation :
champ1 table1 type taille
champ2 table1 type taille
champ1 table2 type taille
champ2 table2 type taille
|
et je voudrais en sortie
Citation :
create table table1 (champ1 type(taille),champ2 type(taille));
create table table2 (champ1 type(taille),champ2 type(taille));
|
voici mon code
Code :
- 'déclaration file system object
- Dim fso
- 'déclaration file system object
- Dim fso1
- 'instanciation
- Set FSO = CreateObject("Scripting.FileSystemObject" )
- 'instanciation
- Set FSO1 = CreateObject("Scripting.FileSystemObject" )
- 'on instance le fichier texte
- Set Ftxt = FSO.OpenTextFile("C:\Documents and Settings\1.txt" )
- 'on instance le fichier texte dans lequel on veut ecrire
- Set Ftxt1 = FSO1.createTextFile("C:\Documents and Settings\2.txt",true) 'true=ecrase
- MaVariable2="a"
- t=""
- 'on parcours chaque ligne du fichier texte
- Do While Not Ftxt.AtEndOfStream
- MaVariable = Ftxt.Readline
-
- if (MaVariable2 = mid(MaVariable,19,18)) then
-
- '....... <- votre code ici pour traiter chaque ligne
- 'On ecrit ce que l'on veut dans le fichier
- 'Ftxt1.writeline (left(MaVariable,18)+left(MaVariable,18)+mid(MaVariable,50,13)+mid(MaVariable,63,5))
- champ=trim(left(MaVariable,18))
- types=trim(mid(MaVariable,50,13))
- taille=trim(mid(MaVariable,63,5))
- t= t +champ+" "+types+"("+taille+" ), "
- MaVariable2= mid(MaVariable,19,18)
- bool="true"
-
- else
-
- nomtable=trim(mid(MaVariable,19,18))
- champ=trim(left(MaVariable,18))
- types=trim(mid(MaVariable,50,13))
- taille=trim(mid(MaVariable,63,5))
- t= t +champ+" "+types+"("+taille+" ), "
- MaVariable2= mid(MaVariable,19,18)
- end if
- 'MaVariable2= mid(MaVariable,19,18)
-
- Loop
- t1=left(t,len(t)-2)
- Ftxt.Close
- Ftxt1.writeline ("create table "+nomtable+"("+t1+" )" )
- Ftxt1.Close
|
Le probleme est qu'en resultat, j'ai cela
create table2 (champ1 type(taille),champ2 type(taille),champ1 type(taille),champ2 type(taille))
il ne me met pas les nom de table à la suite en faite il les ecrase et accumule tout les champs des tables.
Comment pourrai je eviter cela
Merci |