1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

VBScript problem

Discussion in 'Software Development' started by TomTom2000, Jul 16, 2007.

Thread Status:
Not open for further replies.
  1. TomTom2000

    TomTom2000 Thread Starter

    Joined:
    Jul 16, 2007
    Messages:
    1
    Hi,

    I have written a script that normalises a text file, with one column being a code column and another being a code result column, and as part of the process the script maps a new code to the existing code, which it does by looping through a look-up file. The looping through is done in a Function that is called from the main Sub. Now, the problem is, too which I am sure there is a very easy solution, I am having to open this look-up text file every time I want to loop through it. Is there a way in which I can open the text file once in the Main Sub or somewhere else, rather than open it at the beginning of the mapCode Function (see code below)? I have tried putting the following line in Sub Main: Set objCodesFile=objFSO.OpenTextFile("C:\File1.csv", ForReading)"), which doesn’t work.

    Sub Main()
    …
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    …
    mapCode(codeToMap)
    …
    End Sub

    Function mapCode(codeToMap)
    Set objCodesFile=objFSO.OpenTextFile("C:\File1.csv", ForReading)
    Do Until objCodesFile.AtEndOfStream
    strContents = objCodesFile.Readline
    …
    Loop
    End Function
     
  2. Rollin_Again

    Rollin_Again

    Joined:
    Sep 4, 2003
    Messages:
    4,912
    What exactly is happening? Do you receive a specific error?

    Try changing the following line

    Set objCodesFile=objFSO.OpenTextFile("C:\File1.csv", ForReading)

    to

    Set objCodesFile=objFSO.OpenTextFile("C:\File1.csv", 1)

    Regards,
    Rollin
     
  3. ghostdog74

    ghostdog74

    Joined:
    Dec 7, 2005
    Messages:
    146
    your "Set objFSO = CreateObject("Scripting.FileSystemObject") " must be global. (Or passed into the function as parameter...try that.
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Similar Threads - VBScript problem
  1. n00e
    Replies:
    2
    Views:
    286
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/596402

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice