ATTN: VB Guru's!  | | |
March 8th, 2002, 05:32 PM
|
#1 (permalink)
| | Ordained Mommy
Join Date: Oct 2001 Location: Big Sky Country
Posts: 4,259
|
Hello VB Guru's,
Im too lazy to find the old Oh Vass! The VB Guru Thread so starting new one!
Anyhow doing a code here and im stumped. I'll put code up then explain where im stumped at. This is to do with the Loop and DoWhile Code: Private Sub cmdDisplay_Click()
Dim passWord As String, info As String
If UCase(txtName.Text) = "SECRET.TXT" Then
passWord = ""
Do While passWord <> "SHAZAM"
passWord = InputBox("What is the password?")
passWord = UCase(passWord)
Loop
End If
Open txtName.Text For Input As #1
Input #1, info
picItem.Cls
picItem.Print info
Close #1
End Sub Where I have the code in yellow, this too me is asking to open a file on my disk to get the info it needs. I have set up file in hard drive with the txtName.txt and then wrote that line as Code: Open F:\CIS122\txtName.txt For Input As #1 But it keeps saying error and hightlight the : symbol and so i left it to just exactly how the book has the code written as the first code listed here and I am stumped at why im getting the erro message.
Error message with first code listed: Path/File Error
Error message changing line to the second code listed here: Comple Error expected As  But if i try to run it a second time it says syntax error.
Any suggestions?
NeoStar
____________________________________________
3 more week till term is finished and counting! Phew!
Last edited by NeoStarO1 : March 8th, 2002 at 05:34 PM.
|
| |
March 8th, 2002, 06:01 PM
|
#2 (permalink)
| | Ultimate Member
Join Date: Oct 2001
Posts: 1,542
|
The Open statement takes as its first argument a string which should be the filename of the file to open.
e.g. Open "F:\CIS122\txtName.txt" For Input As #1
The quotes (or lack of) are why you're getting the error! |
| |
March 8th, 2002, 06:40 PM
|
#3 (permalink)
| | Ordained Mommy
Join Date: Oct 2001 Location: Big Sky Country
Posts: 4,259
|
Still No Go  |
| |
March 8th, 2002, 07:03 PM
|
#4 (permalink)
| | Banned
Join Date: Oct 2001
Posts: 447
|
line o' code is blue in my browser... Quote: |
Open "F:\CIS122\txtName.txt" For Input As #1
| Do you have a file named 'txtName.txt'? thus, sumtin like:
Open "F:\CIS122\" + txtName.txt For Input As #1
(or however you concat a string in VB) |
| |
March 8th, 2002, 07:33 PM
|
#5 (permalink)
| | Senior Member
Join Date: Oct 2001 Location: New Jersey
Posts: 707
| Quote: |
(or however you concat a string in VB)
| Actually I would use the & symbol instead of +
Open "F:\CIS122\" & txtName.txt For Input As #1
'This is considering that txtName.txt is the name of a text box where it asks you what the name of the file you want to open is, I think...
Is that any help Neo?
__________________
"It's only after we've lost everything that we're free to do anything" www.rjponzio.com |
| |
March 9th, 2002, 01:35 AM
|
#6 (permalink)
| | Ordained Mommy
Join Date: Oct 2001 Location: Big Sky Country
Posts: 4,259
|
Thank you for the suggestions, I have tired those and with the help of Vass online we were able to find the problem. apparently the book doesn't teach you to type in the full path of the file you are looking for. Geezzzz, I said it defeated the purpose and said well nto really cause normally you have a browse for file button but im not to that point yet.
Once again thank you all VB Guru's!!!!
Thanks Vass!!!
NeoStar |
| |
March 9th, 2002, 02:14 AM
|
#7 (permalink)
| | Senior Member
Join Date: Oct 2001 Location: New Jersey
Posts: 707
|
Once again, I am glad to see that you solved one of your VB problems  Keep it up Neo! |
| |
March 9th, 2002, 02:52 AM
|
#8 (permalink)
| | Not Really a Member
Join Date: Oct 2001
Posts: 25,385
|
Thanks all for your help as well 
My connection has been suckin' all day 
Need to get my roommate to call Cox and tell 'em off for crappy connection :P lol
__________________
Helicopters don't fly; they vibrate so much and make so much noise that the earth rejects them.
|
| |
March 9th, 2002, 04:11 PM
|
#9 (permalink)
| | Senior Member
Join Date: Oct 2001 Location: Alberta, Canada
Posts: 563
|
might already know this but oh well...
if your readin a file from the folder of the application, you can use app.Path & "\filename.txt". But, if your app is on a root drive (C:, D: etc) app.Path will return a trailing "\". So you gotta watch for this!
or here's my little modification on app.Path: Code: 'Modified app.path, normal app.Path only returns a trailing "\" when called from a
'root drive, not when in a directory. This function always returns a trailing "\".
Function MyAppPath() As String
MyAppPath = IIf((Right(App.Path, 1) <> "\"), App.Path & "\", App.Path)
End Function Then just use MyAppPath & "filename.txt" and fergetabout the darn "\" heheh
feel free to use and moify if u want!  Could easily change it to accept the filename as a parameter and return the whole path instead...
cyas!  |
| |
March 9th, 2002, 04:26 PM
|
#10 (permalink)
| | Not Really a Member
Join Date: Oct 2001
Posts: 25,385
|
hyd, just FYI
app.path doesn't work in .NET if I remember right so keep an eye out for it
There's an equivalent, but the app object no longer works :/ |
| | | Thread Tools | Search this Thread | | | | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | | | Most Active Discussions | | | | | Recent Discussions  | | | | | |