Results 1 to 9 of 9
  1. #1
    Star Lounger
    Join Date
    Apr 2004
    Posts
    66
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Portability (VB6)

    Hi

    I am accessing an external text file using FileSystemObject

    Set Retroword = File.GetFile("F:retroword.txt") This works fine sitting on my PC but how do I get it work on someone elses when the project is made .exe? Do I have to create an input box for the user to enter the path name to retroword and have this feed to the code? Ideally I'd like to 'hard wire' the project and the retroword file together.

    All suggestions gratefully received.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Portability (VB6)

    If the file will always be F:Retroword.txt, you can "hard-code" the path+filename. If it will always be in the same path as the .exe, you can use that. If it could be in a different path or have a different name, you should use a variable. How exactly this variable should be specified depends on what you want - you could prompt each time (preferably using the FileOpen dialog, not using an input box!), or just once and store the path+filename in the registry (for example).

  3. #3
    New Lounger
    Join Date
    Nov 2004
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Portability (VB6)

    Hi Hans

    Sorry to take time to come back to you. I wanted to check this out on someone else's PC. Although the .exe and retroword are in the same folder I got a file not found error when I tried to run the code on a different PC. This occurred even when I tried to run the file off my flash pen. I guess because the path is set to G: for my flash pen while the flash pen sits on E: on the other machine. I will have a go at using the FileOpen dialog and see if this resolves.

  4. #4
    Star Lounger
    Join Date
    Apr 2004
    Posts
    66
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Portability (VB6)

    Sorry

    I'm doing something wrong. I get a Run Time error 5 - Invalid procedure call or argument whether I try to run within VB or as an .exe file.

    De###### is highlighting
    Set Retroword = File.GetFile(strFile)


    The code now looks like this

    General Declarations
    Dim File As New FileSystemObject
    Dim Retroword As File
    Dim txtStream As TextStream

    On Form Load Event

    Dim strPath As String
    Dim strFile As String

    strPath = App.Path
    If Not Right(strPath, 1) = "" Then
    strPath = strPath & ""
    End If

    Set Retroword = File.GetFile(strFile)
    strFile = strPath & "Retroword.txt"


    'Open Text stream for reading from the file
    Set txtStream = Retroword.OpenAsTextStream(ForReading)

    Now I can't see the difference between
    Set Retroword = File.GetFile(strFile)
    and the original
    Retroword = File.GetFile("F:retroword.txt")

    So what am I missing please?

    Do I need to check anything in Project References to use the App Object? Like I needed to check Microsoft Scripting Runtime to use FileSystemObject.

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Portability (VB6)

    App is general VB6, no special references needed. You have the instructions in the wrong order:

    Set Retroword = File.GetFile(strFile)
    strFile = strPath & "Retroword.txt"

    You use strFile before you assign it a value.

  6. #6
    Star Lounger
    Join Date
    Apr 2004
    Posts
    66
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Portability (VB6)

    Hi

    So far so good. Tomorrow I will test it on a different PC.

    Fingers crossed.

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Portability (VB6)

    Edited by HansV to correct order of instructions - strFile was used before it was assigned a value. Sorry.

    The Path property of the App object returns the path of the application (=the exe file you create), so you could use this:

    Dim strPath As String
    Dim strFile As String

    strPath = App.Path
    If Not Right(strPath, 1) = "" Then
    strPath = strPath & ""
    End If

    strFile = strPath & "RetroWord.txt"
    Set Retroword = File.GetFile(strFile)

    Note: App.Path will only work correctly if you run the compiled .exe; if you run your program from within VB6, App.Path will return the path of VB6.exe!

  8. #8
    New Lounger
    Join Date
    Nov 2004
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Portability (VB6)

    Hi Hans

    Works fine now. Once again thanks for your help. Very much appreciated.

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Portability (VB6)

    Glad it works. Sorry about the goof-up with the order of the instructions yesterday.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •