Hey everbody, Merrrrry Christmas. My question is pretty straightforward, to me. I'm writing a plugin for a program I'm using which is giving me values between 0 and 320 [unless an error]. Currently the code looks like this: Code: cogx = GetVariable("cog_x") Dim fi Dim fso set fso = CreateObject("Scripting.FileSystemObject") set fi = fso.OpenTextFile("C:\Documents and Settings\The Agent\Desktop\RoboRealm_Beta\test.txt", 8, true) if err.number = 0 then fi.writeLine cogx fi.close end if set fi = nothing set fso = nothing My "problem" is that I don't need to keep a list of values. A visual basic servo control program is going to open this file ~4 times a second [probably] and check the position, then act on it [I already have it able to pull it up into a text box]. I don't care what the past values were and, honestly, don't want them adding up [plus the latest value is the 2nd to last line - the last is a white space for the new text to fall on]. I'm not _at_all_ familiar with VBscript, and I've been googling for hours but I haven't managed to find anything decent online for my weird little question. Any help? Happy Holidays Agent
hmmm - that forum is blocked to me! Must be the name I guess... How did you solve this? My only thought was to ensure you did a force overwrite the file each time, rather than append? Just interested for the sake of being interested
i would go there and copy the posts, but there's some database error. regardless, i can show you my current VBscript Code: cogx = GetVariable("cog_x") Dim fi Dim fso set fso = CreateObject("Scripting.FileSystemObject") set fi = fso.CreateTextFile("C:\Documents and Settings\The Agent\Desktop\RoboRealm_Beta\cogx.txt", true) if err.number = 0 then fi.Write cogx fi.close end if set fi = nothing set fso = nothing someone there told me i should use "CreateTextFile" instead, and gave me a link to MSDN with a lot of the... arguements? [i don't recall the proper word for phrases you use in coding at the moment] i might use. after that i guessed and checked a hell-of-a-lot of times, changed "writeline" to "write" and now i get a text file with the most recent outputted value only what are good free video hosts these days? I want to put the video of this actually causing a servo to turn [from the camera on the servo's point of view, using some visual basic 6 coding] online, but i don't have a good host for a 13 meg file. agent
Ah! CreateTextFile with the 'true' argument forces an overwrite of the file if it exists. Therefore you are essentially writing to an empty file each time, which is why your problems went away. Effectively they solved the symptoms of your problem; not the underlying reason - so "boo" to them! The real reason was the number 8 in your original code on the OpenTextFile method: The 'OpenTextFileMethod' will only create a file if it doesn't already exist and is therefore more efficient than recreating the file each time your script is executed. It opens the file in away dictated by the 'iomode' argument - that is to say the 'way in which it writes to the file'... i.e. Write, append, or read. For some reason you specifed the value 8 this means append so all other values written to the file are added to the end of the exisiting file. If you change the value from 8 to 2 your original code works just fine. 1 = Reading 2 = Writing 8 = Appending
hey thanks, i've never touched vbscript before, just for this one plugin, and was searching and searching online to find a script i wanted. i think i just found that one with the 8 and whatnot, and had no idea what 8 stood for or the correct way to overwrite a file. since this script would, in fact, output the values to a text file, i stuck with it - figuring out how to change it was all the work. -andrew