home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Ask a Tech Support Question (free)!

ATTN: VB Guru's!

Reply
Get bargains at  »  Dealighted.com
 
Thread Tools Search this Thread
Currently Active Users: 2305
Discussions: 200,942, Posts: 2,379,288, Members: 246,305
Old March 8th, 2002, 05:32 PM   Digg it!   #1 (permalink)
Ordained Mommy
 
NeoStarO1's Avatar
 
Join Date: Oct 2001
Location: Big Sky Country
Posts: 4,259
Blog Entries: 1
ATTN: VB Guru's!

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.
NeoStarO1 is offline   Reply With Quote
Old March 8th, 2002, 06:01 PM     #2 (permalink)
Ultimate Member
 
strangerstill's Avatar
 
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!
strangerstill is offline   Reply With Quote
Old March 8th, 2002, 06:40 PM     #3 (permalink)
Ordained Mommy
 
NeoStarO1's Avatar
 
Join Date: Oct 2001
Location: Big Sky Country
Posts: 4,259
Blog Entries: 1
Still No Go
NeoStarO1 is offline   Reply With Quote
Old March 8th, 2002, 07:03 PM     #4 (permalink)
Banned
 
qball's Avatar
 
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)
qball is offline   Reply With Quote
Old March 8th, 2002, 07:33 PM     #5 (permalink)
Senior Member
 
PonzSpyder's Avatar
 
Join Date: Oct 2001
Location: New Jersey
Posts: 707
Send a message via AIM to PonzSpyder Send a message via Yahoo to PonzSpyder
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
PonzSpyder is offline   Reply With Quote
Old March 9th, 2002, 01:35 AM     #6 (permalink)
Ordained Mommy
 
NeoStarO1's Avatar
 
Join Date: Oct 2001
Location: Big Sky Country
Posts: 4,259
Blog Entries: 1
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
NeoStarO1 is offline   Reply With Quote
Old March 9th, 2002, 02:14 AM     #7 (permalink)
Senior Member
 
PonzSpyder's Avatar
 
Join Date: Oct 2001
Location: New Jersey
Posts: 707
Send a message via AIM to PonzSpyder Send a message via Yahoo to PonzSpyder
Once again, I am glad to see that you solved one of your VB problems Keep it up Neo!
PonzSpyder is offline   Reply With Quote
Old 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.
vass0922 is offline   Reply With Quote
Old 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!
^hyd^ is offline   Reply With Quote
Old 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 :/
vass0922 is offline   Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Most Active Discussions
Is It Just Me? (2917)
Hackers global warming emails (5)
windows 7 problem (7)
CPU fan stops spinning randomly (8)
Wireless Televisions. (9)
Regular Build (6)
Is the PSU I received dead? (11)
HIS HD5770 graphic card question (15)
windows vista security holes (9)
Install XP pro and a Vista laptop ?.. (11)
Print spooler problem (13)
Foreign voltage (10)
Dept. of HS: NSA 'Helped' Develop V.. (15)
A good PSU? (10)
Recent Discussions
Asus P4G8X Mobo (5)
screen resolution vs monitor size (2)
Wireless Televisions. (9)
radeon x850xt platinum & shader 3 (4)
sms storage to PC (0)
Regular Build (6)
Open With ..... Win7 (0)
java code for fibonacci (1)
[F@H SPAM 11/16/09] ! 1/2 months to r.. (35)
windows 7 problem (7)
CPU fan stops spinning randomly (8)
Partition Magic caused HDD problem (3)
Is the PSU I received dead? (11)
Have you switched yet? (85)
Point and Shoot Camera Suggestions. (2)
Modern Warfare 2 freeze (13)
wireless user (1)
World's largest Monopoly Game using G.. (332)
Ideal cheap graph card for PC-Gaming? (17)
BIOS won't read disk when I try to fl.. (0)
Install XP pro and a Vista laptop ?? (11)
Graphics Card Upgrade Question (1)
favorit (1)
solutions for virtical white lines on.. (1)
Fire in DVD (2)


All times are GMT -4. The time now is 03:39 PM.
TechIMO Copyright 2009 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28