Results 1 to 12 of 12

Thread: bad filename error :( (vb6)

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    6

    bad filename error :( (vb6)

    Code:
    Dim tmp As Variant
    Dim Users As Integer
    Dim strLineValue As String
    Dim strValueToFind As String
    
    Sub CreateFileAndWrite()
    
    Users = FreeFile
    
    'Open the document to write to. Look in the documentation
    'at the Open statement for more information and different modes.
    Open "\\ict-server\stud_redir\davidmica\dtop\personal PR\Users.txt" For Output As Users
    
    'Use the print or Write statement to add data to the file.
    'Again, the documentation will give you more info.
    Print #Users, tmp
    
    
    'Close the file.
    Close #Users
    
    End Sub
    
    Sub WriteInFile()
    
    Users = FreeFile
    
    'Set the string you want to find in the file.
    strValueToFind = tmp
    
    Open "\\ict-server\stud_redir\davidmica\dtop\personal PR\Users.txt" For Input As Users
    
    'Read each line until either the string has been
    'found or you have reached the end of the file.
    Do Until EOF(Users)
    
        Line Input #Users, strLineValue
         
        If InStr(strLineValue, strValueToFind) > 0 Then
             
            MsgBox "User you Selected Already Exists, Sry"
             
            'Close the file and exit this loop
            Close #Users
            Exit Do
            
        Else
        
        
             
        End If
         
    Loop
    
    Close #Users
    
    End Sub
    
    Private Sub cmdCheckUser_Click()
    Set Myfso = CreateObject("Scripting.FileSystemObject")
    
    tmp = txtUser.Text
    
    If (tmp = "") Then
    
    MsgBox "Please Enter A Username Before You Click Check, Thanks", , "No Username Found!"
    
    Else
    
    MsgBox "Please Wait... while checking your username availability", , "Please Wait"
    
        If (Myfso.FileExists("\\ict-server\stud_redir\davidmica\dtop\personal PR\Users.txt")) Then
        
        MsgBox "hello"
        
        Call WriteInFile
        
        Else
        
        Call CreateFileAndWrite
        
        End If
    End If
    
    End Sub
    it is givving me bad filename error

  2. #2
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    499

    Re: bad filename error :( (vb6)

    this is not a valid path

    "\\ict-server\stud_redir\davidmica\dtop\personal PR\Users.txt"

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    6

    Re: bad filename error :( (vb6)

    Quote Originally Posted by user name
    this is not a valid path

    "\\ict-server\stud_redir\davidmica\dtop\personal PR\Users.txt"
    huh? it has been created with that path!

  4. #4
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: bad filename error :( (vb6)

    It's a long code. Which line gives error?

  5. #5

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    6

    Re: bad filename error :( (vb6)

    Quote Originally Posted by Pradeep1210
    It's a long code. Which line gives error?

    it is trying to check if the users already exisits or not in the file.txt if it is not in the file then it will be written in the file.txt the new user

  6. #6
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: bad filename error :( (vb6)

    Which line is the error on? Is it a permission error?

  7. #7
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: bad filename error :( (vb6)

    this is not your original problem, but if you want to add a new user to the file, better to open file for append.

    if you only want to keep the new user then open for output is fine.

    maybe you should destroy your FSO object before trying to open the file

    pete

  8. #8

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    6

    Re: bad filename error :( (vb6)

    ok, let me try it out!

    Thanks
    Regards,
    IL_Pizu

  9. #9

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    6

    Re: bad filename error :( (vb6)

    Code:
    Sub CheckUserAvailability()
    
    intFileNumber = FreeFile
    
    'Set the string you want to find in the file.
    strValueToFind = tmp
    
    Open "\\ict-server\stud_redir\davidmica\dtop\personal PR\Users.txt" For Random Access Read As intFileNumber
    
    'Read each line until either the string has been
    'found or you have reached the end of the file.
    Do Until EOF(intFileNumber)
    
        Line Input #intFileNumber, strValueToFind
         
        If InStr(intFileNumber, strValueToFind) > 0 Then
             
            MsgBox "Found the string"
             
            'Close the file and exit this loop
            Close #intFileNumber
            
            Exit Do
             
        End If
         
    Loop
    
    Close #intFileNumber
    
    End Sub
    it's not working well.. i am trying to see if a user already exists in a file.txt and it's not working!
    Regards,
    IL_Pizu

  10. #10
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926

    Re: bad filename error :( (vb6)

    No, I guess it isn't working.

    'Set the string you want to find in the file.
    strValueToFind = tmp

    'strValueToFind will be replaced with a line from the file, so it looses it's original value.
    Line Input #intFileNumber, strValueToFind

    ' this line doesn't make any sense, you check if the line you just read from the file can be found in the filenumber (probably just 1)
    If InStr(intFileNumber, strValueToFind) > 0 Then
    Frans

  11. #11
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: bad filename error :( (vb6)

    random won't work the way you are doing it open for input

    Line Input #intFileNumber, strFromFile

    If InStr(strFromFile, strValueToFind) > 0 Then

    try that

    pete

  12. #12

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    6

    Re: bad filename error :( (vb6)

    thabks.. i will check them out and tks everyone who is helping me
    Regards,
    IL_Pizu

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