Results 1 to 4 of 4

Thread: file path problem

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2001
    Location
    Ca
    Posts
    124

    file path problem

    Hey all

    I have this code that worked fine until i changed the file path name to allow the user to enter a input file name and an output file name. I get an error that says file not found.

    Any help?


    Vb Code++++++++++++++++++

    Private Sub Command1_Click()
    Dim sContent As String
    Dim iInputFile As Integer
    Dim iOutputFile As Integer
    Dim iFirstSpace As Long
    Dim iLineNumber As Long
    'Dim Firstfile As String
    'Dim OutputfileA As String


    iInputFile = FreeFile()
    D = Text1.Text
    'Open App.Path & "\UCUT2.T" For Input As #iInputFile ' This will open your input file in whatever
    Open App.Path & "\D" For Input As #iInputFile ' This will open your input file in whatever
    ' directory your App is in.
    'Outputfile = Text2.Text
    iOutputFile = FreeFile()
    'Open App.Path & "\UCUT3.T" For Output As #iOutputFile ' This will open your output file in whatever
    Open App.Path & "\TEXT2.TEXT" For Output As #iOutputFile ' This will open your output file in whatever
    ' directory your App is in.



    Do While Not EOF(iInputFile)
    Line Input #iInputFile, sContent
    Print #iOutputFile, sContent

    Mystr = Left(sContent, 5) = "O0000" ' Find the position of the first space

    If Mystr = True Then ' Check the first character
    Print #iOutputFile, "M00"
    Print #iOutputFile, "(New File "; "U-CUT3.T"; " Created on )"
    Print #iOutputFile, "("; Format(Now, "dddd, mmmm dd, yyyy"); ")"
    Print #iOutputFile, "("; Format(Now, "hh:mm AM/PM"); ")"
    Print #iOutputFile, "(File Name Below)"
    End If

    iFirstSpace = InStr(sContent, " ") ' Find the position of the first space
    If Mid$(sContent, iFirstSpace + 1, 1) = "X" Then ' Check the first character after the first space
    iLineNumber = CLng(Mid$(sContent, 2, iFirstSpace - 2)) + 1 ' Get the line number, then add 1
    Print #iOutputFile, "N" & iLineNumber & " G04 P1000" ' Create and print the new line

    End If
    iFirstSpace = InStr(sContent, " ") ' Find the position of the first space
    If Mid$(sContent, iFirstSpace + 1, 1) = "Z" Then ' Check the first character after the first space
    iLineNumber = CLng(Mid$(sContent, 2, iFirstSpace - 2)) + 1 ' Get the line number, then add 1
    Print #iOutputFile, "N" & iLineNumber & " G04 P1000" ' Create and print the new line


    End If
    Loop
    Close #iInputFile
    Close #iOutputFile

    End Sub
    Last edited by tiguy; Jun 17th, 2007 at 11:37 PM.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: file path problem

    Assuming you want the value in a textbox (rather than the text "TEXT2.TEXT") you need to append it to the string, eg:
    Code:
     Open App.Path & "\" & TEXT2.TEXT For ...

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2001
    Location
    Ca
    Posts
    124

    Re: file path problem

    Man that was fast.

    Thanks

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: file path problem

    If the application is installed in the root directory of any drive then App.Path will end with a "\" so instead of App.Path use this AppPath function

    vb Code:
    1. Private Function AppPath() As String
    2.  
    3.     If Right$(App.Path, 1) = "\" Then
    4.         AppPath = App.Path
    5.     Else
    6.         AppPath = App.Path & "\"
    7.     End If
    8.  
    9. End Function

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