Results 1 to 8 of 8

Thread: Resolved: having trouble opening a file

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2005
    Posts
    47

    Resolved Resolved: having trouble opening a file

    i am having trouble opening a file when the file name is selected through a file list box, the file will open and run just fine when i simply type in the location in the code. any ideas what might be wrong? or perhaps a simpler way to select a file to open.

    i know its probably simple, but being a beginner i sometimes can't see the easy ones.

    thanks
    jerry

    VB Code:
    1. Private Sub Command1_Click()
    2.  
    3.  
    4. k = 5 'temporary file length
    5. 'open "c:\usrtest.txt" for input as #1  '<<this line works when i swap it in :)
    6. Open strDataFileName For Input As #1    '<<this line won't when i select the same file :mad:
    7.    ReDim Node(2, k)
    8.    i = 0
    9.    Do While Not EOF(1)
    10.         Input #1, lLat
    11.         Input #1, lLon
    12.         Input #1, bCon
    13.        
    14.         Node(0, i) = lLat
    15.         Node(1, i) = lLon
    16.         Node(2, i) = bCon
    17.        
    18.        
    19.         i = i + 1
    20.        
    21.     Loop
    22.     Close #1
    23.      i = 0
    24.      
    25.     Label3.Caption = Node(0, 0) & Node(1, 0) & Node(2, 0)
    26.     For i = 0 To k
    27.         Debug.Print Node(0, i); Node(1, i); Node(2, i)
    28.     Next i
    29.    
    30. End Sub
    31.  
    32. Private Sub Command2_Click()
    33. Unload Me
    34.  
    35. End Sub
    36.  
    37. Private Sub Dir1_Change()
    38. File1.Path = Dir1.Path
    39.  
    40. End Sub
    41.  
    42. Private Sub Drive1_Change()
    43. Dir1.Path = Drive1.Drive
    44.  
    45. End Sub
    46.  
    47. Private Sub File1_Click()
    48. strDataFileName = File1.Path & File1.FileName  ' <<selecting file here :wave:
    49.  
    50. Label2.Caption = strDataFileName
    51.  
    52. End Sub
    53.  
    54. Private Sub Form_Load()
    55. Dim strDataFileName As String
    56. Dim lLat As Long, lLon As Long
    57. Dim bCon As Byte
    58.  
    59.  
    60. Drive1.Drive = "c:"
    61.  
    62.  
    63. End Sub
    64.  
    65. Private Sub Text1_Change()
    66. If Right(Text1.Text, 4) = ".usr" Then
    67.         strSaveFileName = Text1.Text
    68.         Else
    69.         strSaveFileName = Text1.Text & ".usr"
    70.         End If
    71. Label1.Caption = strSaveFileName
    72.        
    73.  
    74. End Sub
    75.  
    76. Private Sub Text2_Change()
    77. strTrailName = Text2.Text
    78. Label2.Caption = strTrailName
    79.  
    80. End Sub
    Last edited by jerrybark; Aug 18th, 2005 at 09:15 PM. Reason: Resolved

  2. #2

  3. #3
    Addicted Member
    Join Date
    Aug 2002
    Location
    Alberta, Canada
    Posts
    138

    Re: having trouble opening a file

    use the stepinto (F8) to get to File1_Click and put your mouse over strDataFileName and make sure its a correct path.

    EDIT:

    lol or what Martin said
    Jon_G
    AKA Phil From Marketing
    **************************************
    Insert Something Memorable And Witty Here.
    **************************************

  4. #4
    Lively Member Something Else's Avatar
    Join Date
    Nov 2003
    Location
    Where Humboldt Intersects Carlson
    Posts
    99

    Re: having trouble opening a file

    Marty,
    What is Quick Watch {Darn the focus loss! What, is THIS add now doing that!!!}

    Anyways,

    You could also do a msgbox. ie...
    VB Code:
    1. Private Sub Command1_Click()
    2.  
    3.  
    4. k = 5 'temporary file length
    5. 'open "c:\usrtest.txt" for input as #1  '<<this line works when i swap it in  
    6. MsgBox( strDataFileName )
    7. Exit sub
    8. Open strDataFileName For Input As #1    '<<this line won't when i select the same file  
    9.    ReDim Node(2, k)
    10.    i = 0
    11.    Do While Not EOF(1)
    12.         Input #1, lLat
    13.         Input #1, lLon
    14.         Input #1, bCon
    15.        
    16.         Node(0, i) = lLat
    17.         Node(1, i) = lLon
    18.         Node(2, i) = bCon
    19.        
    20.        
    21.         i = i + 1
    22.        
    23.     Loop
    24.     Close #1
    25.      i = 0
    26.      
    27.     Label3.Caption = Node(0, 0) & Node(1, 0) & Node(2, 0)
    28.     For i = 0 To k
    29.         Debug.Print Node(0, i); Node(1, i); Node(2, i)
    30.     Next i
    31.    
    32. End Sub
    no soap...radio -mendhak

    I understand...just a little...
    No comprende, it's a riddle
    - Wall of Voodoo-Mexican Radio

  5. #5

    Thread Starter
    Member
    Join Date
    Apr 2005
    Posts
    47

    Re: having trouble opening a file

    OK<

    i used the message box idea to look things over, the path is correct after it is selected, then it is still the same after it displays in the label2.caption but it is blank right before the open???

    what gives with that, is there something that could happen in between?

    thanks for the responses so far,

    jerry

  6. #6
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: having trouble opening a file

    How did you declare the strDataFileName? If it is not declared as a global or Public variable then you can use it between procedures.

  7. #7

    Thread Starter
    Member
    Join Date
    Apr 2005
    Posts
    47

    Re: having trouble opening a file

    that's it!

    thanks Baja Yu, i had declared it in the wrong place.

    see, just what i predicted: something simple that i just couldn't see.

    cheers
    jerry

  8. #8
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: Resolved: having trouble opening a file

    Don't worry about it, with more practice you will get better at spotting errors.
    What tipped it of here is I noticed that The open line is practicaly the first line with the variable in that procedure (click event), and just before that it is fine. So there is not code in between to mess it up, it must be something else. The declaration.

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