Results 1 to 9 of 9

Thread: [RESOLVED] Open Routine Problems...

  1. #1

    Thread Starter
    Frenzied Member thegreatone's Avatar
    Join Date
    Aug 2003
    Location
    Oslo, Norway. Mhz:4800 x12
    Posts
    1,333

    Resolved [RESOLVED] Open Routine Problems...

    Hey, i've just encountered a very strange problem with my open routine in one of my programs.

    All its meant to do is open the given FileName, simply by putting it into Text1

    Here is my routine, can anyone see where i have gone wrong ?

    VB Code:
    1. Private Function Open_File(Filename As String)
    2. On Error GoTo Hell
    3.     Dim lFileLength As Long
    4.     Dim iFileNum As Integer
    5. 'Get a free file number and open the file
    6.     iFileNum = FreeFile
    7.     Open Filename For Input As iFileNum
    8.     'Get the length of the file and
    9.     'read it into the text box
    10.     lFileLength = LOF(iFileNum)
    11.     Text1.Text = Input(lFileLength, iFileNum)
    12.  
    13.     Close iFileNum
    14. Hell:
    15. End Function
    Zeegnahtuer?

  2. #2
    Frenzied Member Jmacp's Avatar
    Join Date
    Jul 2003
    Location
    UK
    Posts
    1,959

    Re: Open Routine Problems...

    don't have vb right now but i use

    intfile = freefile()

    essentially creating an array of possible freefiles to use, i dont know if this is the problem, are there any errors?

  3. #3

    Thread Starter
    Frenzied Member thegreatone's Avatar
    Join Date
    Aug 2003
    Location
    Oslo, Norway. Mhz:4800 x12
    Posts
    1,333

    Re: Open Routine Problems...

    Actually just done this...

    VB Code:
    1. Private Function Open_File(Filename As String)
    2. On Error GoTo Hell
    3.     Dim lFileLength As Long
    4.     Dim iFileNum As Integer
    5. 'Get a free file number and open the file
    6.     iFileNum = FreeFile
    7.     Open Filename For Input As iFileNum
    8.     'Get the length of the file and
    9.     'read it into the text box
    10.     lFileLength = LOF(iFileNum)
    11.     Text1.Text = Input(lFileLength, iFileNum)
    12.  
    13.     Close iFileNum
    14. Hell:
    15. MsgBox Err.Number & " : " & Err.Description
    16. End Function

    And i get Error 62: Input past end of file
    Any help ?
    Zeegnahtuer?

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Open Routine Problems...

    try iFileLength - 1

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    Frenzied Member thegreatone's Avatar
    Join Date
    Aug 2003
    Location
    Oslo, Norway. Mhz:4800 x12
    Posts
    1,333

    Re: Open Routine Problems...

    Quote Originally Posted by techgnome
    try iFileLength - 1

    -tg
    Still gives the same eror, oh... and this uses the Command$ passed form Sub Main() in a module... Thats where it usually gets its filename from, but i also have it passed from a comman dialog too.

    With the Command$ i get "Error 52: Bad file Name or Number"
    So, is there a way to strip out the filename passed by Command$ ? Like maybe it has blank space or something ?
    Zeegnahtuer?

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Open Routine Problems...

    Check the value of Command$ before passing it... see if it's really what you expect... as far as spaces go, it shouldn't matter. I've opened files before where there were spaces in the folder names, so I doubt that has any affect.

    I'm still caught up on why you are getting the Input past end of time error...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7

    Thread Starter
    Frenzied Member thegreatone's Avatar
    Join Date
    Aug 2003
    Location
    Oslo, Norway. Mhz:4800 x12
    Posts
    1,333

    Re: Open Routine Problems...

    Quote Originally Posted by techgnome
    Check the value of Command$ before passing it... see if it's really what you expect... as far as spaces go, it shouldn't matter. I've opened files before where there were spaces in the folder names, so I doubt that has any affect.

    I'm still caught up on why you are getting the Input past end of time error...

    -tg
    Checked Command$ and the Filename thats being passed, they are both exactly what i expect them to be, so, in theory they should work. But still, i get Bad File Name Or Number (Error 52).
    So, that is a little strange.

    I still get error 62 as well.
    Not liking this one bit.
    Zeegnahtuer?

  8. #8
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Open Routine Problems...

    Don't know what to tell you... I don't use command parameters so I've never had issues with it.... it is strange though....

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  9. #9

    Thread Starter
    Frenzied Member thegreatone's Avatar
    Join Date
    Aug 2003
    Location
    Oslo, Norway. Mhz:4800 x12
    Posts
    1,333

    Re: Open Routine Problems...

    Ok, i have modified how i make my command$ string be sent into my routine.
    It now works like that, but, i know whats causing the Input past end of file error occur.
    Just un-handled characters in files, i really didn't think of this.
    So far it works perfectly on text files like its meant too

    I'll update this post if anything else goes wrong.
    Zeegnahtuer?

Posting Permissions

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



Click Here to Expand Forum to Full Width