SupportTeam Report post Posted 05/19/2003 12:44 AM Nira wrote: My vb script: Sub random() Randomize Dim cond As String If Rnd() <= 0.25 Then cond = "music" ElseIf 0.25 < Rnd() And Rnd() <= 0.5 Then cond = "apology_cond" ElseIf 0.5 < Rnd() And Rnd() <= 0.75 Then cond = "no_8" Else cond = "birth_year" End If Open "c:\Program Files\ivg\data\SHRESULT.txt" For Output As 1 Write #1, cond Close 1 End Sub The error message is: Windows Script Host Script: C:\Program Files\ivg\data\vbs_0.vbs Char: 10 Error: Expected end of statement Code: 800A0401 Source: Microsoft VBScript compilation error What I have done wrong? Many thanks in advance, Nira Share this post Link to post
SupportTeam Report post Posted 05/19/2003 12:46 AM VB Script does not reqire you to specify variable types, and you're better off using the FileSystemObject for any file I/O. Try using this script instead: Randomize Dim cond If Rnd() <= 0.25 Then cond = "music" ElseIf 0.25 < Rnd() And Rnd() <= 0.5 Then cond = "apology_cond" ElseIf 0.5 < Rnd() And Rnd() <= 0.75 Then cond = "no_8" Else cond = "birth_year" End If WriteResultFile cond function WriteResultFile(strResult) const ForReading=1, ForWriting=2, ForAppending=8 Dim filename, fso, ts, outdata, outdata2, outdata3 filename = "c:\Program Files\ivg\data\SHRESULT.txt" set fso = CreateObject("Scripting.FileSystemObject") set ts = fso.OpenTextFile(filename, ForWriting, True) ts.WriteLine(strResult) ts.Close WriteResultFile = 0 end function I've tried it and it worked fine for me - creating the file and writing appropriate result into it. Share this post Link to post