![]() |
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 |
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 |
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 |
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 |
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 |
All times are GMT +1. The time now is 10:16 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com