#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Read/Write


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


--
mattsvai
------------------------------------------------------------------------
mattsvai's Profile: http://www.excelforum.com/member.php...o&userid=31134
View this thread: http://www.excelforum.com/showthread...hreadid=508222

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Read/Write

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.

--
Regards,
Tom Ogilvy


"mattsvai" wrote in
message ...

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


--
mattsvai
------------------------------------------------------------------------
mattsvai's Profile:

http://www.excelforum.com/member.php...o&userid=31134
View this thread: http://www.excelforum.com/showthread...hreadid=508222



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Read/Write

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

--
Regards,
Tom Ogilvy

"Tom Ogilvy" wrote in message
...
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.

--
Regards,
Tom Ogilvy


"mattsvai" wrote

in
message ...

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


--
mattsvai
------------------------------------------------------------------------
mattsvai's Profile:

http://www.excelforum.com/member.php...o&userid=31134
View this thread:

http://www.excelforum.com/showthread...hreadid=508222





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Read/Write


You're very helpful Tom :)

I will give it a shot...

Matt

--
mattsva
-----------------------------------------------------------------------
mattsvai's Profile: http://www.excelforum.com/member.php...fo&userid=3113
View this thread: http://www.excelforum.com/showthread.php?threadid=50822

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Read/Write


Awesome bit of code! Will come in very handy. Thank you very much! :

--
clayto
-----------------------------------------------------------------------
clayton's Profile: http://www.excelforum.com/member.php...nfo&userid=456
View this thread: http://www.excelforum.com/showthread.php?threadid=50822



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
read only and write only zilah New Users to Excel 2 July 8th 07 03:01 PM
I have a read only xl file, I need it to be read and write drama queen Excel Discussion (Misc queries) 3 July 1st 06 12:25 AM
How can a file be converted from Read-Only to Read/Write Jim in Apopka Excel Discussion (Misc queries) 2 November 19th 05 04:59 PM
Who has read/write John Pritchard Excel Programming 0 September 28th 04 04:36 PM
write to/read from add-ins abartkowski Excel Programming 3 October 10th 03 04:33 PM


All times are GMT +1. The time now is 02:40 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"