Grab text line and populate field (1 Viewer)

jfgambit

Kinetic Card Dealer
Local time
Today, 15:41
Joined
Jul 18, 2002
Messages
798
Hello All:

I have written a module that creates a .bat file and runs it to generate a specific Lincese key for a customer. The procedure works great:

1. Creates the .bat file
2. Pauses while the DOS cmd opens
3. SendKeys ENTER to run the .bat
4. .bat returns a .txt file containing the license key.

I'm trying to find a way to open the .txt file and grab the last line (the key) and update the customers license key field in my form with the key that is generated.

Same of the .txt file:

The current date is: Tue 05/17/2005
Enter the new date: (mm-dd-yy) ECHO is on.
license key generation
CheckSum=87
rg67775ghbyt43e


Thanks
 

tembenite

Registered User.
Local time
Today, 10:41
Joined
Feb 10, 2005
Messages
38
Return last line in textfile

The function below will pull the last line from a textfile, and message the text. Hopefully it is useful. (Search Help on "Textstreams" for more info. This is a combo of several of the helpfiles modified for your purpose")
--------------------------------
Function TextStreamTest()
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Dim fs, f, ts, s
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile("e:\testfile.txt")
Set ts = f.OpenAsTextStream(ForReading, TristateUseDefault)
Do Until ts.atendofline
s = ts.Readline
Loop
MsgBox "Your Serial is " & s
ts.Close
End Function
 

jfgambit

Kinetic Card Dealer
Local time
Today, 15:41
Joined
Jul 18, 2002
Messages
798
tembenite:

Thanks, that worked perfect just had to change it slightly to populate the license key field:

Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(txtfile)
Set ts = f.OpenAsTextStream(ForReading, TristateUseDefault)
Do Until ts.atendofline
s = ts.Readline
Loop
Me.CWLicKey = s
ts.Close

Again, thanks!
 

Users who are viewing this thread

Top Bottom