Status pour opentextfiles

dduvignau Messages postés 1 Date d'inscription jeudi 26 septembre 2013 Statut Membre Dernière intervention 26 septembre 2013 - 26 sept. 2013 à 15:27
jordane45 Messages postés 38170 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 10 mai 2024 - 27 sept. 2013 à 04:22
Bonjour ,
j'utilise un script (vbs) pour ecrire un fichier text à partir de variables wincc (supervision siemens).Mon script fonctione mais pas tous le temp par moment mon fichier n'ai pas crée et je suis quasiment sur que ma procedure à été effectué, pour palier à cela je fini par faire un test d'existance du fichier puis re-executé le script d'ecriture et malgré cela j'ai des ratés.
Mon hypotese est que le pc est occupé a faire qq choses et il ne crée pas le fichier.......
Existe il un moyen (status variable d'erreur) qui me permetrait d'avoir un code erreur?




Release = HMIRuntime.Tags("BM_X120_1").read <= variable automate me lancant la procedure

DateiSchreibenBD1 <= procedure ecriture fichier

StartTime = Timer
Do While EndTime < (StartTime + 1) <= tempo 1 seconde
EndTime = Timer
Loop

Set fso = CreateObject("Scripting.FileSystemObject")
If Not (fso.FileExists("C:\BMB\BD1.txt")) Then
DateiSchreibenBD1
Else
Exit Function
End If


End Function


Procedure


Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fso, f, i, inhalt, State,TypOF, NoOf, GrpLigne, NoLigne, NoRoll, Dest, Gram, Sorte, NoSplice, NoMachOF
Dim VarState, strTimestamp, strTimeStampRaw


Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("c:\bmb\bd1.txt", ForWriting, True)


State=" "
TypOF=AddNull(HMIRuntime.Tags("DerTypOFDe").read,2)
NoOf=AddNull(HMIRuntime.Tags("DerNoOFDe").read,8)
GrpLigne=HMIRuntime.Tags("DerGrpLineDe").read
NoLigne=AddNull(HMIRuntime.Tags("DerNoLineDe").read,2)
NoRoll=AddNull(HMIRuntime.Tags("DerNoRollDe").read,8)
Gram=AddNull(HMIRuntime.Tags("DerGramDe").read,6)
Sorte=AddNull(HMIRuntime.Tags("DerSorteDe").read,10)
NoSplice=HMIRuntime.Tags("DerNoSpliceDe").read
strTimestamp = Date & " " & Time
HMIRuntime.Tags("DerTimeStampDe").write(strTimestamp)
strTimestampRaw=TimStampConv(strTimestamp)

inhalt = State & strTimestampRaw & TypOF & NoOf & GrpLigne & NoLigne & NoRoll & Sorte & Gram & NoSplice
HMIRuntime.Tags("AuftragsdatenDe").write("BD1: " & inhalt)
f.Write(inhalt)
f.Close

Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("c:\bmb\bd1\BD1 " & strTimestampRaw & ".txt", ForWriting, True)
f.Write(inhalt)
f.Close

HMIRuntime.Tags("BM_X120_1").write("False")

End Sub

1 réponse

jordane45 Messages postés 38170 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 10 mai 2024 344
27 sept. 2013 à 04:22
Bonjour,

quelque chose de ce genre peut être ?
On Error Resume Next 
Set f = fso.OpenTextFile("c:bmbbd1BD1 " & strTimestampRaw & ".txt", ForWriting, True) 
If Err.Number = 0 Then 
    ' Successfully opened file 
    f.Write(inhalt) 
    f.Close 

Else 
    ' Open file failed 
    WScript.Echo Err.Number & Chr(32) & Err.Description 
End If 



PS: lors de vos prochaines interventions sur le forum, merci d'utiliser la coloration syntaxique pour poster vos CODE.
'Ceci est du code
Msgbox("Merci")


1
Rejoignez-nous