Results 1 to 11 of 11

Thread: I Need Help With Reading Current Dir

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2000
    Posts
    344

    Angry

    Ok, this is my situation. I have a textbox(Which only reads #'s) and a command button on form1.

    What i want to do is that when the command button is clicked it checks to see if the numbers written in the text box are files that exist in the current dir. If not then msgbox "Files do not exist in current dir" If they do then form2.visible = true

    Note: the file names do not hold extensions, ex. 1234 is the file name not 1234.txt....thank you
    -RaY
    VB .Net 2010 (Ultimate)

  2. #2
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658

    Thumbs up Give this a whirl

    Code:
    Private Sub Command1_Click()
      If Dir$(Text1.Text) <> "" Then
        'the file exists
        Form2.Visible = True
      Else
        MsgBox "File Does Not Exist In Current Directory"
      End If
    End Sub
    Iain, thats with an i by the way!

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    May 2000
    Posts
    344

    Angry Didn't work

    With the code that was given, no matter what i typed in the text field i get a file not found box.
    -RaY
    VB .Net 2010 (Ultimate)

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    May 2000
    Posts
    344

    Unhappy Rephrase that

    Not a file not found box but the MSGBOX we request it to ask when a file is not in that directory. I know the code is similar to the one given, and i been cracking at so many different ways to run it. Someone help, if your still ou there lain hook it up!
    -RaY
    VB .Net 2010 (Ultimate)

  5. #5
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177
    The code Lain gave you works fine, check the files you're looking for actually exist in the current directory which you can get using the CurDir command, i.e.

    Debug.Print CurDir

  6. #6
    Guest
    try this code, it will check to see if a file exists using error handling

    ************************************************
    Private Sub Command1_Click()
    Dim FilePath As String
    On Error GoTo NoFile
    FilePath = CurDir & "\" & Text1.Text
    Open FilePath For Input As #1
    Close #1
    'put things to do with file that exists between here.
    MsgBox "Good file"
    'And Here
    Exit Sub
    NoFile:
    MsgBox "No File"
    End Sub
    ************************************************

    put what you want to do with a good file in between the comments and a bad file is in the labe NoFile.

    Hope this helps.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    May 2000
    Posts
    344

    Red face Damn

    It searchs the file in which the *.mak file is right? And does it matter that I have VB 3? It's frustrating cause it seems so simple.
    -RaY
    VB .Net 2010 (Ultimate)

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    May 2000
    Posts
    344

    dmartin

    I get resume errors with your code, ;o\ THanks for helping me guys dont give up on me now
    -RaY
    VB .Net 2010 (Ultimate)

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    May 2000
    Posts
    344

    Talking I'm on to it

    Leans code does work
    If Dir$(Text1.Text) <> "" Then
    'the file exists
    Form2.Visible = True
    Else
    MsgBox "File Does Not Exist In Current Directory"
    End If
    however i have to put a \ in the text box for it to read files....how would i get it to put the \ automatically without having to actually type it in the text box? That would make it work!!!
    -RaY
    VB .Net 2010 (Ultimate)

  10. #10
    Addicted Member pardede's Avatar
    Join Date
    Jan 2000
    Posts
    232
    If you only need the backslash used in the Dir function you can just concatenate it:

    If Dir$("\" & Text1.Text) <> "" Then ... etc etc

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    May 2000
    Posts
    344

    Cool that easy huh

    Hehe thanks for all your help guys, i wound up figuring out the last part though, however made it much more complicated then what you wrote hehehe. I put

    a = "\"
    b = (text1.text)
    If Dir$(a + b) <> "" Then
    'the file exists
    Form2.Visible = True
    Else
    MsgBox "File Does Not Exist In Current Directory"
    End If

    cool huh? I was proud as hell, I looked at a how to add two times together example and took the idea from that. It works!!! Thanks again for all your help guys!
    -RaY
    VB .Net 2010 (Ultimate)

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