Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can VB access variables be stored in Word ?

Status
Not open for further replies.

1ooo1

Technical User
Jan 20, 2003
50
AU
Hi,
A beginner question.
I have made a small project that does a few small calculations based on user input into a TextBox. The variables change once every financial year, is it possible to have the variables in a text file (Word, Notepad etc) so that my code will look at the text file for the variables instead of in the code itself? This is so that any user can access the text file and change the variables, without having to rely on me to access the project code to do this.
I am using VB6.
I hope this makes sense!!
Any advice would be appreciated.

Thanx
Ken
 
Oops, the thread heading should have been....
"Can VB access variables stored in Word ?"
 
Yes, that can be done.
You'll need to set a reference to MS Scripting Runtime.
Using the FileSystemObject you have access to files, which you can read in a textstream.

Code:
Dim FSO As New Scripting.FileSystemObject
Dim F As Scripting.TextStream
Dim strInFromFile As String

Set F = FSO.OpenTextFile("C:\temp\xxxxx.txt", ForReading)
strInFromFile = F.ReadLine
You can read the file line after line (ReadLine), or get it all at once (Read), or read a number of characters at a time (Read(10)).
The tricky part is: how do you prevent users to mess up your textfile? If you make it:
"thisyears_bonus<tab>10000"
some user is going to overwrite it as:
"nextyear<whitespace>$999999"

 
Jel,
My Text file would be something like this..
MIN = 541.88 'RESIDENTIAL MINIMUM
VACANT = 59 'VACANT LAND WASTE CHARGE
BIN80 = 220 '80l BIN CHARGE
BIN120 = 289 '120l BIN CHARGE
BIZMIN = 695.72 'BUSINESS MINIMUM
Dol = 0.29245 'RESIDENTIAL RATE AMOUNT
BDol = 0.7754 'BUSINESS RATE AMOUNT
RMin = 185289.79 'MINIMUM VALUE - RESIDENTIAL
BMin = 89724.01 'MINIMUM VALUE - BUSINESS

Just a list of things that my code refers to, the user/manager would update this file manually by opening the file and making changes, the 'normal' user would not know that this file exists.
So, what you are saying is that I can make a label caption etc read and display only the first 12 characters of line 1 and the first 11 charactars of line 2, first 11 of line 3 etc....

Ken
 
Sorry I missed your last posting yesterday...
Using code like I posted you can read text-files, so if you want to keep it real simple, you could read 1 line, take the part before "=" and the part after it, and then you know which value applies to which variable.
I justed wanted to warn you that this is not a very robust method - it will do if the guy that updates the file is an old schoolfried that has the number of your cell-phone...
If you want to avoid people calling you in the middle of the night, you might consider to build an interface to update the file - that way you can validate changes.
Also: a texfile is the most unstructured thing you can think of. You might consider to use a table in a database, or an xml-file.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top