|
-
Aug 18th, 2005, 08:36 PM
#1
Thread Starter
Member
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:
Private Sub Command1_Click()
k = 5 'temporary file length
'open "c:\usrtest.txt" for input as #1 '<<this line works when i swap it in :)
Open strDataFileName For Input As #1 '<<this line won't when i select the same file :mad:
ReDim Node(2, k)
i = 0
Do While Not EOF(1)
Input #1, lLat
Input #1, lLon
Input #1, bCon
Node(0, i) = lLat
Node(1, i) = lLon
Node(2, i) = bCon
i = i + 1
Loop
Close #1
i = 0
Label3.Caption = Node(0, 0) & Node(1, 0) & Node(2, 0)
For i = 0 To k
Debug.Print Node(0, i); Node(1, i); Node(2, i)
Next i
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub
Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub
Private Sub File1_Click()
strDataFileName = File1.Path & File1.FileName ' <<selecting file here :wave:
Label2.Caption = strDataFileName
End Sub
Private Sub Form_Load()
Dim strDataFileName As String
Dim lLat As Long, lLon As Long
Dim bCon As Byte
Drive1.Drive = "c:"
End Sub
Private Sub Text1_Change()
If Right(Text1.Text, 4) = ".usr" Then
strSaveFileName = Text1.Text
Else
strSaveFileName = Text1.Text & ".usr"
End If
Label1.Caption = strSaveFileName
End Sub
Private Sub Text2_Change()
strTrailName = Text2.Text
Label2.Caption = strTrailName
End Sub
Last edited by jerrybark; Aug 18th, 2005 at 09:15 PM.
Reason: Resolved
-
Aug 18th, 2005, 08:42 PM
#2
Re: having trouble opening a file
Put a breakpoint on the Open line and then use Quick watch to see what is in strDataFileName.
-
Aug 18th, 2005, 08:46 PM
#3
Addicted Member
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.
**************************************
-
Aug 18th, 2005, 08:48 PM
#4
Lively Member
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:
Private Sub Command1_Click()
k = 5 'temporary file length
'open "c:\usrtest.txt" for input as #1 '<<this line works when i swap it in
MsgBox( strDataFileName )
Exit sub
Open strDataFileName For Input As #1 '<<this line won't when i select the same file
ReDim Node(2, k)
i = 0
Do While Not EOF(1)
Input #1, lLat
Input #1, lLon
Input #1, bCon
Node(0, i) = lLat
Node(1, i) = lLon
Node(2, i) = bCon
i = i + 1
Loop
Close #1
i = 0
Label3.Caption = Node(0, 0) & Node(1, 0) & Node(2, 0)
For i = 0 To k
Debug.Print Node(0, i); Node(1, i); Node(2, i)
Next i
End Sub
-
Aug 18th, 2005, 08:58 PM
#5
Thread Starter
Member
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
-
Aug 18th, 2005, 09:09 PM
#6
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.
-
Aug 18th, 2005, 09:14 PM
#7
Thread Starter
Member
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
-
Aug 18th, 2005, 09:23 PM
#8
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|