Achilles wrote: Ok, so I know Visual Basic can hardly be considered a true programming language but for my current college project I just need to know one thing as endless googling hasn't given me the answer. Currently I have a program that's reading integers from a text file so that the numbers stay constant when the program starts and finishes (we haven't learned how to integreate Databases into our programs yet). Anyways at present I have it reading the text file by typing out the full path to the file as it doesn't except just the file name. Is there a way to just get it to read from the textfile of the directory that the form (uncompiled) is currently in? Cheers.
Kernel32 wrote: RTFMhttp://msdn.microsoft.com/library/default.asp?url=/library/en-us/vb98/html/vbpropath.asp
Laguna wrote: That's not a helpful comment, I think the charter should say something about posts saying RTFM/unhelpful comments? (if it doesn't already).
Achilles wrote: Ok, so I know Visual Basic can hardly be considered a true programming language...
dim filePath as string filePath = app.path & "\" & "doyourownhomeworkinfuture.txt"
Laguna wrote: That's not a helpful comment, I think the charter should say something about posts saying RTFM/unhelpful comments? (if it doesn't already). Besides, I had a look at the link, it provides no answer to the mans question, it's not even close. So in future if you're going to shove something in someones face, make sure it's the right information..
Achilles wrote: Is there a way to just get it to read from the textfile of the directory that the form (uncompiled) is currently in?
Open "M:\College\CP2\Visual Basic\Vending Machine Project\stock.txt" For Input As #1 Input #1, CokeStock, DietCokeStock, FantaStock, LiltStock, SpriteStock Close #1 txtCokeQuantity.Text = CokeStock txtDietCokeQuantity.Text = DietCokeStock txtFantaQuantity.Text = FantaStock txtLiltQuantity.Text = LiltStock txtSpriteQuantity.Text = SpriteStock
Open "stock.txt" For Input As #1 Input #1, CokeStock, DietCokeStock, FantaStock, LiltStock, SpriteStock Close #1 txtCokeQuantity.Text = CokeStock txtDietCokeQuantity.Text = DietCokeStock txtFantaQuantity.Text = FantaStock txtLiltQuantity.Text = LiltStock txtSpriteQuantity.Text = SpriteStock
Achilles wrote: Jesus christ I never should have posted here in the first place. Any time anybody asks for help you always pick apart every little thing that the user asks.
Achilles wrote: Jesus christ I never should have posted here in the first place. Any time anybody asks for help you always pick apart every little thing that the user asks. The program we were asked to create is a Vending Machine Simulation Program. I've explained what I'm trying to do as best as I can. Basically I'm looking to input 5 variables into 5 seperate text files that are retreaved from a text file, do this like so: Open "M:\College\CP2\Visual Basic\Vending Machine Project\stock.txt" For Input As #1 Input #1, CokeStock, DietCokeStock, FantaStock, LiltStock, SpriteStock Close #1 txtCokeQuantity.Text = CokeStock txtDietCokeQuantity.Text = DietCokeStock txtFantaQuantity.Text = FantaStock txtLiltQuantity.Text = LiltStock txtSpriteQuantity.Text = SpriteStock As you can see, for it to work I have to give it the full path of the directory, which in this case is my pen drive. The problem I will have later is if I want to work on it on a college PC or when I submit it on a floppy discs, the paths won't be correct and I can be damned if i'm changing all the file paths (the above aint the only instance in my program of where code is read from a text file) if I'm changing all of the paths manually. If I do something along the lines of this:Open "stock.txt" For Input As #1 Input #1, CokeStock, DietCokeStock, FantaStock, LiltStock, SpriteStock Close #1 txtCokeQuantity.Text = CokeStock txtDietCokeQuantity.Text = DietCokeStock txtFantaQuantity.Text = FantaStock txtLiltQuantity.Text = LiltStock txtSpriteQuantity.Text = SpriteStock Then it doesn't work. So how do I get it to read the variables from a text file?
Achilles wrote: But surely there's a way to get it to open variables.txt from within the same folder as the form.
bonkey wrote: No, there isn't. There is a way to open it from the same location/folder as the compiled .exe, but - as has been pointed out - when working in Debug mode this will look for the file in the same location as where the .vbp is stored. IN either case, this may be the same folder as "the form" (by which I can only assume you mean the .frm), but that would fall into the category of "programming by coincidence" in my book. Why not look at the FileOpen Dialog, and simply get the user to select the file they want to read the values from? Or use a .INI file with the app? jc
Open as #1 filePath = app.path & "\" & "coins.txt"
Beano wrote: sin é
I can be damned if i'm changing all the file paths (the above aint the only instance in my program of where code is read from a text file) if I'm changing all of the paths manually
Laguna wrote: Besides, I had a look at the link, it provides no answer to the mans question, it's not even close.
Trampas wrote: Typical college student comment about Visual Basic not a programming language.
Kernel32 wrote: Hobbes went one step further and supplied a line of code. I'm not sure what more is needed?
Laguna wrote: OK now, let me see if I've got this right.. This is the Programming forum... yes? Why is it taboo/forbidden for people (especially 'newbies') to ask Programming questions?
Anytime anyone ever asks a question that has a *hint* of a college assignment from it, you're all down their throat deeming yourselves to have carte blanche to pick apart everything and anything they say