Créer des fichiers textes avec VBScript (ou autre à la limite)

K - 13 mai 2001 à 17:38
OneHacker Messages postés 1447 Date d'inscription jeudi 2 novembre 2000 Statut Membre Dernière intervention 23 septembre 2007 - 21 févr. 2005 à 09:42
Salut,

Bon, j'explique mon pb :

Je suis en terminale et je fais option informatique. On doit faire un projet sous forme de site web.
Le projet doit être fini la semaine prochaine et y a toujours un truc qui merde. En fait on doit pouvoir s'inscrire sur le site et ainsi se créer un compte avec identifiant et mot de passe. Donc j'ai fais une page d'inscription avec des champs de formulaire pour entrer le login et le mdp. Ensuite lorsqu'on valide il doit se créer dans un répertoire /inscription/membre un fichier login.txt avec le mot de passe correspondant au login à l'intérieur. En même temps il se cré un autre fichier login.txt dans /inscription/points et à l'intérieure il y a le nombre de points de l'utilisateur (10 lors de l'inscription).

Pour ça j'ai fait un truc en vbscript avec l'objet FileSystemObject qui permet de créer et de travailler sur les fichiers.

Chez moi ça ne marche que lorsque je met l'adresse entière du dossier ou doit être créé le fichier (par ex : C:\projet\inscription\membre\ mais si je met juste \inscription\membre\ alors ça marche pas.

En salle info au lycée ça a marché les 3 premières fois ou j'ai essayé (avec adresse relative et absolue) mais depuis plus rien.

Là je sais plus quoi faire donc si jamais tu pouvais demander vite fais autour de toi si personne ne voit de solution (seulement en html, pas de php, cgi, ou autre asp) ça m'arrangerai énormement.

Voila je t'envoie la partie de la page qui pose problème pour que ce soit un peu plus clair :

<script LANGUAGE="VBScript">
Sub Envoi_onClick
Dim Texte
Dim mdp
Dim mdp2
Set Texte = Formulaire.Nom
Set mdp = Formulaire.mdpasse
Set mdp2 = Formulaire.confirmation
If Texte.Value = "" or mdp.Value="" or mdp2="" Then
MsgBox "Tous les champs doivent être remplis"
Elseif (mdp.value <> mdp2.value) then
MsgBox "La confirmation de votre mot de passe n'est pas correcte"
Else
Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile("inscription\membres" & Texte.Value & ".txt", False)
a.WriteLine(mdp.value)
a.Close
Set b = fs.CreateTextFile("inscription\points" & Texte.Value & ".txt", False)
b.WriteLine("10")
b.Close
Texte.Value = ""
mdp.Value = ""
mdp2.Value = ""
end if
end Sub
</script>

Voilà si vous avez la moindre id, vraiment n'hésitez pas.

Jérémy.

PS: il faut aussi que je puisse lire les fichier créés lorsque l'utilisateur veut s'identifier, par contree pour tou ce qui est sécurité je m'en fous completement. Faut jusque que ça marche.

3 réponses

ce code "createobject("scripting.filesystemobject").getparentfoldername(WScript.ScriptFullname)" donne le chemin où se lance ton vbs. Ca pourra peut-être t'aider pour savoir où stocker tes fichiers!

@+
0
ce message set un peu tardif mais si tu continue en VBscript cela pourra t'apprendre qqc.
Tu peux procéder différamment.
Tu peux utiliser un cookies comme le fait remarquer Microsoft, le spécialiste...

'NB: ce script est créé pour 5 bouton...
'A toi d'adapter le code

'****************************************************************
'Dimension and set the NOT_FOUND constant for the entire page
Dim NOT_FOUND
NOT_FOUND = "NOT_FOUND"

'****************************************************************
' Purpose: Creates or modifies the value assigned to a given
' variable.
' Inputs: strVariableName: The name of the variable that will
' have its value set.
' varVariableValue: The value that strVariableName
' should be set to.
' Returns: Nothing
' Notes: This function could be expanded to include other
' cookie attributes, such as expire date and valid
' domains. Cookies set with this implementation expire
' at the end of the user's session. If the cookie
' should remain valid for a longer period of time,
' an expires section can be added to the string. For
' example:
' ... & varVariableName & ";expires=01-Jul-96 GMT"

'****************************************************************

Sub SetVariable(strVariableName, varVariableValue)
Document.Cookie = strVariableName & "=" & varVariableValue
End Sub

'****************************************************************
' Purpose: Delete the variable with the name held in
' strVariableName
' Inputs: strVariableName: The name of the variable to delete
' Returns: Nothing
' Notes: The cookie is deleted by setting the expires attribute
' to a date that has already occurred. If one went back
' time, this method would break, so be sure to take that
' into account.
'****************************************************************

Sub KillVariable(strVariableName)
SetVariable strVariableName, "NULL;expires=Monday, 01-Jan-95 12:00:00 GMT"
End Sub

'****************************************************************
' Purpose: Finds and returns the value of of the variable with
' the name held in strVariableName
' Inputs: strVariableName: The name of the variable to return
' the value of.
' Returns: The value of the variable with the name of
' strVariableName.
' If the variable is not found, returns NOT_FOUND.
' Notes: This function could be greatly simplified if the
' bounds-checking code was removed.
' The NOT_FOUND constant should be set
' once for the entire page.
'****************************************************************

Function ReadVariable(strVariableName)
'these five variables are used in the string manipulation
'code that finds the variable in the cookie.
Dim intLocation
Dim intNameLength
Dim intValueLength
Dim intNextSemicolon
Dim strTemp

'calculate length and location of variable name
intNameLength = Len(strVariableName)
intLocation = Instr(Document.Cookie, strVariableName)

'check for existence of variable name
If intLocation = 0 Then
'variable not found, so it can't be read
ReadVariable = NOT_FOUND
Else
'get a smaller substring to work with
strTemp = Right(Document.Cookie, Len(Document.Cookie) - intLocation + 1)

'check to make sure we found the full string, not just a substring
If Mid(strTemp, intNameLength + 1, 1) <> "=" Then
'oops, only found substring, not good enough
ReadVariable = NOT_FOUND

'note that this will incorrectly give a not found result if and only if
'a search for a variable whose name is a substring of a preceding
'variable is undertaken. For example, this will fail:
'
'search for: MyVar
'cookie contains: MyVariable=2;MyVar=1
Else
'found full string
intNextSemicolon = Instr(strTemp, ";")

'if not found, then we need the last element of the cookie If intNextSemicolon 0 Then intNextSemicolon Len(strTemp) + 1

'check for empty variable (Var1=;)
If intNextSemicolon = (intNameLength + 2) Then
'variable is empty
ReadVariable = ""
Else
'calculate value normally
intValueLength = intNextSemicolon - intNameLength - 2
ReadVariable = Mid(strTemp, intNameLength + 2, intValueLength)
End If
End If
End if
End Function

' ***********************************************
' Code behind buttons
' ***********************************************

Sub btnSaveVariable_onClick
Dim strVariableName
Dim varVariableValue

strVariableName = InputBox("Entrez un nom de variable")
varVariableValue = InputBox("Entrez une valeur pour '" & strVariableName & "'")

SetVariable strVariableName, varVariableValue
End Sub

Sub btnReadVariable_onClick
Dim strVariableName
Dim varVariableValue

strVariableName = InputBox("Entrez un nom de variable à lire")
varVariableValue = ReadVariable(strVariableName)

If varVariableValue = NOT_FOUND Then
MsgBox "'" & strVariableName & "' introuvable."
Else
MsgBox "'" & strVariableName & "' a pour valeur '" & varVariableValue & "'."
End If
End sub

Sub btnShowCookie_onClick
MsgBox Document.Cookie
End Sub

Sub btnNextPage_onClick
location.href = "/france/msdn/technologies/scripting/info/info.asp?mar=vbcookie2.htm"
End Sub

Sub btnKillVariable_onClick
Dim strVariableName
Dim varVariableValue

strVariableName = InputBox("Entrez un nom de variable à supprimer")
varVariableValue = ReadVariable(strVariableName)

If varVariableValue = NOT_FOUND Then
MsgBox "'" & strVariableName & "' introuvable."
Else
KillVariable(strVariableName)
MsgBox "Variable supprimée."
End If
0
OneHacker Messages postés 1447 Date d'inscription jeudi 2 novembre 2000 Statut Membre Dernière intervention 23 septembre 2007 2
21 févr. 2005 à 09:42
Salut, je vois où est le problème ! Le voici : Set a = fs.CreateTextFile("inscription\membres" & Texte.Value & ".txt", False)

Essaye plutôt : Set a = fs.CreateTextFile("inscription\\membres\" & Texte.Value & ".txt", False)

Redman
0
Rejoignez-nous