This topic is closely related to the Topic entitled "Writing to a BAT file using VB6 " :
http://p2p.wrox.com/topic.asp?TOPIC_ID=24475
Can someone help me on this little problem please? I have successfully written and read to a BAT file on two occasions in my program, the problem is that the program will read the first two lines of the BAT file (Consisting of a username, and serial number) but it will not read the third (true / false) even though i have repeated the steps that i used to read the first two lines of the file.
My program is justsmethign i have put togethr to increase my skills at vb6, See if you can follow this plan of what, in theory, i want the program to do:
1.) The program is opened, a form is filled out to register the program, and this data is written to the BAT file in three seperate lines: the contents (example) are as follows:
Rhys Davies \\Username
5685-52654 \\Serial number
True \\True meaning program is registered
2.) The registration form is closed and the user is returned to the home page (main form) where 3 labels have been set to the username, serial number (unique to each user due to different data in each users BAT file on their PC)
3.) Now the application is closed and reopened, the program reads the BAT file to check whether or not the program is registered, (
this is the problem) if the program is registered, the labels on the main form are set as #2
Now, the problem is like i have explained, the program refuses to read whether or not the program is registered!? Why? I can get this kind of feature to work with only a registration thing (registered or not) but not when i introduce the username and serial number.
Here is the code that i am using :
Code:
Private Sub Form_Load()
Dim TextLine$, Filename$
Dim FileHandle As Integer
Dim strUsername As String
Dim strUserReg As Integer
Dim strRegistered As Boolean
Filename$ = "Dont_Modify.BAT"
If Dir(Filename$) = "" Then Exit Sub
FileHandle = FreeFile
Open Filename$ For Input As #FileHandle
strUsername = "Invalid Data"
Do While Not EOF(FileHandle)
Line Input #FileHandle, TextLine$
If InStr(TextLine$, "=") > 0 Then
strUsername = Mid(TextLine$, InStr(TextLine$, "=") + 2)
Do While Not EOF(FileHandle)
Line Input #FileHandle, TextLine$
If InStr(TextLine$, "=") > 0 Then
strUserReg = Mid(TextLine$, InStr(TextLine$, "=") + 2)
Do While Not EOF(FileHandle)
Line Input #FileHandle, TextLine$
If InStr(TextLine$, "=") > 0 Then
strRegistered = Mid(TextLine$, InStr(TextLine$, "=") + 2)
End If
Loop
End If
Loop
End If
Loop
Close #FileHandle
If strRegistered = True Then
label_big_registered.Caption = "This program is registered."
label_big_registered.Enabled = False
Me.lbl_registered_to.Caption = "Registered to :" & strUsername
Me.lbl_reg_no.Caption = "Registration No :" & strUserReg
End If
End Sub
This is the code when the correct details for registering the program are entered:
Code:
Private Sub Command1_Click()
Username = username_text.Text
RegNo = reg_no_text.Text
Begin2:
If Username = "Rhys Davies" And RegNo = "5947-38156" Then
MsgBox ("Your details are correct, please proceed")
GoTo DetailsCorrect
Else
MsgBox ("You have entered incorrect details.")
username_text.Text = Empty
reg_no_text.Text = Empty
Exit Sub
End If
DetailsCorrect:
Open App.Path & "\Dont_Modify.BAT" For Output As #1
Print #1, Username
Print #1, RegNo
Print #1, "True"
Close #1
Welcome_Screen.lbl_registered_to.Caption = "Registered to :" & Username
Welcome_Screen.lbl_reg_no.Caption = "Registration No :" & RegNo
Welcome_Screen.label_big_registered.Caption = "This program is registered."
Welcome_Screen.label_big_registered.Enabled = False
Me.Hide
End Sub
Regards
Rhys