Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account

why won't my vbscript work?

  • Please log in to reply



    New Member

  • Member
  • Pip
  • 1 posts
Hi. I'm a complete newbie in vbscript, and I actually do not intend to learn a lot of it, unless I really need. I am developing an application that runs an html file offline. I need this html file to get the content of a txt file, transform each line of this text into a variable that javascript can handle and send this value to a flash file loaded in the same html. The only part I can work out succesfuly is the one of sending a js variable to a flash file. To do the rest I'm trying to use a vbscript code that reads the content of an external text file and send to an html 'select' object (I don't know if object is the term). However it fails everytime I run the html outside the desktop directory. By desktop directory I mean 'C:\Users\Nakkao\Desktop'. If the html is not located there it won't work. Why?

My code is:

<script Language="VBScript">

sCurPath = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".")

	Sub Window_OnLoad
		ForReading = 1
		Set objFSO = CreateObject("Scripting.FileSystemObject")
		Set objFile = objFSO.OpenTextFile _
			(sCurPath+"\lol.txt", ForReading)
		Do Until objFile.AtEndOfStream
			strLine = objFile.ReadLine
			Set objOption = Document.createElement("OPTION")
			objOption.Text = strLine
			objOption.Value = strLine
	End Sub

	<select size="5" name="FileContent" style="width:250"></select>


  • 0





  • Member
  • PipPip
  • 53 posts
EDIT: Never mind, didn't read your code fully...

sCurPath = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".")

In that line, try replacing the period with your C drive, and see if it will run there. New line to copy:

sCurPath = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName("C:\")

Then try putting a file in your C drive, and not your Desktop, and it might work. You can modify the path accordingly.

A path is complete and unambiguous if it provides a complete reference from the root of the specified drive. A complete path can only end with a path separator character (\) if it specifies the root folder of a mapped drive.

- Quoted from MSDN

Edited by xBPM07x, 27 January 2009 - 10:23 PM.

  • 0

Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP