Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / March 2006

Tip: Looking for answers? Try searching our database.

Read/Write

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
mattsvai - 03 Feb 2006 17:52 GMT
What is the simplest way to read and write maybe 3 values to a text
file?
I want to use this as a global variables container so that all xls
files can be in sync.

Thanks,

Matts

Signature

mattsvai

Tom Ogilvy - 03 Feb 2006 18:53 GMT
Public V1
Public V2
Public V3

Sub WriteValues()
Dim f As Long
V1 = Int(Rnd() * 100 + 1)
V2 = Int(Rnd() * 100 + 1)
V3 = Int(Rnd() * 100 + 1)
f = FreeFile
Open "C:\MyVar.ini" For Output As #f
Print #f, V1, V2, V3
Close #f
End Sub

Sub ReadValues()
Dim f As Long
f = FreeFile
Open "C:\MyVar.Ini" For Input As #f
Input #f, V1, V2, V3
Close #f
MsgBox V1 & " - " & V2 & " - " & V3
End Sub

You can remove the V1 =  type statements - they are just for texting.

Signature

Regards,
Tom Ogilvy

> What is the simplest way to read and write maybe 3 values to a text
> file?
[quoted text clipped - 4 lines]
>
> Matts
Tom Ogilvy - 03 Feb 2006 18:56 GMT
Small correction.  While that will work for what I presented, you should
actually use WRITE rather than PRINT.  Here is a revision.

Public V1
Public V2
Public V3

Sub WriteValues()
Dim f As Long
V1 = Int(Rnd() * 100 + 1)
V2 = Int(Rnd() * 100 + 1)
V3 = Int(Rnd() * 100 + 1)
f = FreeFile
Open "C:\MyVar.ini" For Output As #f
Write #f, V1, V2, V3
Close #f
End Sub

Sub ReadValues()
Dim f As Long
f = FreeFile
Open "C:\MyVar.Ini" For Input As #f
Input #f, V1, V2, V3
Close #f
MsgBox V1 & " - " & V2 & " - " & V3
End Sub

Signature

Regards,
Tom Ogilvy

> Public V1
> Public V2
[quoted text clipped - 33 lines]
> http://www.excelforum.com/member.php?action=getinfo&userid=31134
> > View this thread: http://www.excelforum.com/showthread.php?threadid=508222
mattsvai - 03 Feb 2006 19:17 GMT
You're very helpful Tom :)

I will give it a shot...

Matt
clayton - 30 Mar 2006 01:55 GMT
Awesome bit of code! Will come in very handy. Thank you very much! :
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.