Wrox Programmer Forums
|
Pro VB 6 For advanced Visual Basic coders working in version 6 (not .NET). Beginning-level questions will be redirected to other forums, including Beginning VB 6.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 5th, 2005, 10:59 AM
Authorized User
 
Join Date: Dec 2004
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default saving a variable

hi bit of an odd one here to get your heads around i am creating a program to paste a invoice from multiple folders to just one iv done that no prblems there the poblem comes when i need to have a seperate form to enter in the file path once save it some how then for that file path to be used many times by the end user without hardcodeing it i was using normal vaiables for the file path its just the point that after enter the file path in form to when it closes the app then gose to use the file path from form to it wont be there as you can see this is a majour problem please help

Regards

Matthew Allee
Computer Consultant
R Charles Associates

 
Old January 5th, 2005, 01:33 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Listen Matt: How about giving us a break, and writing like a professional. Add punctuation.
It might be cute in a chat room, but it is taxing to try to read. Plus, caps in the right places further clarify what it is that you are trying to get across.
Don't ask so much of your 'audience.'

Separate, not seperate.
Somehow, not Some how.
Goes, not gose.

I've tried to read your question like 5 times, but I still don't quite follow.
Could you rewrite it with punctiation, re-read it before you hit the submit, and give a little more step-by-step at the point of the problem?
I hate to come on like a grammar teacher, but if you want people to help you, it is helpful to be clear on what it is that you are after.

I want to help, but you make it hard...
I think I see what it is you want, and have 2 ideas to help, but I would like to be clearer on the problem.
 
Old January 5th, 2005, 01:57 PM
Authorized User
 
Join Date: Dec 2004
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am very sorry BrianWren, I know my punctuation and speling is terrible i am dyslexic and i can't work out how to use the spell checker on this site. Thank you for your interest, my problem is as follows;

I have a form (form2)on which i enter the file path into a txt box to be used on a seperate form (form1) in the code [FileCopy "Source", "destination"]. i have all this working very well but when i close the project then restart it, the file path has been lost, because it was stored in a variable.

So i need a way to either save the variables to a file then open that file and read them. or something else. i use multiple source file paths but only one destination path. I use String Variables for the file path.

Regards

Matthew Allee
Computer Consultant
R Charles Associates

p.s. I do hope this is much easier to read i tried very hard

 
Old January 5th, 2005, 03:50 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Much better. Thanks.

You can save values in the Registry, which is pretty nice to use.
(I always feel more important when I use the Registry...)

To save the value use
Code:
    SaveSetting App.Title, "<SectionHere>", "<EntryInSection>", <Value>
App.Title could be a different string, if you want to do that.
So you would use like
Code:
    SaveSetting App.Title, "UserPrefs", "FilePath", form2.txtPath.Text
To retrieve the value, use
Code:
    <VariableHere> = GetSetting(App.Title, "<SectionHere>", "<EntryInSection>", <defaultValue>)
So, again
Code:
    form2.txtPath.Text = GetSetting(App.Title, "UserPrefs", "FilePath", "")

A second way would be to just write it out to a file. I really like using the Windows Scripting Runtime, because it is so easy.
Add a reference to your project for "Microsoft Scripting Runtime," (scrun.dll, in systen32 on my machine).
Declare a variable (I like fso):
Code:
    Dim fso As FileSystemObject
    Dim ts  As TextStream

    Set ts = fso.OpenTextFile("FileName", ForAppending [or ForWriting], <Create T/F>, TristateUseDefault)

    ts.WriteLine form2.txtPath.Text

    ts.Close

=============================

    Set ts = fso.OpenTextFile("FileName", ForReading, False, TristateUseDefault)

    form2.txtPath.Text = ts.ReadLine

    ts.Close

    Set fso = Nothing
That should do it...

Using the Registry method allows you to easily store several different things (using a different section/item combination), which then can be easily retrieved individually. If you use the writing-to-a-file method, you will have to devise a way to keep things separate if you store more than 1 item.





Similar Threads
Thread Thread Starter Forum Replies Last Post
ASSIGNING A JAVA SCRIPT VARIABLE TO A XSL VARIABLE SOMANATHAN10 XSLT 1 February 21st, 2007 04:26 AM
Object Variable or With Block Variable Not Set Iashia06 Access 1 May 22nd, 2006 10:24 AM
EXCEL question saving a file saving the the first macupryk VS.NET 2002/2003 0 January 6th, 2005 05:33 PM
How To avoid the SAving of toolbars while saving Hari_Word Excel VBA 6 July 26th, 2004 12:13 AM
Saving data from an array into a variable cutovoi Excel VBA 1 January 7th, 2004 10:09 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.