Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 12th, 2005, 09:53 AM
Authorized User
Join Date: Sep 2004
Location: , , .
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to rhysduk Send a message via Yahoo to rhysduk
Default Problem with reading BAT file

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 :

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
End If
End If
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:

Private Sub Command1_Click()
Username = username_text.Text
RegNo = reg_no_text.Text

If Username = "Rhys Davies" And RegNo = "5947-38156" Then
MsgBox ("Your details are correct, please proceed")
GoTo DetailsCorrect
MsgBox ("You have entered incorrect details.")
username_text.Text = Empty
reg_no_text.Text = Empty
Exit Sub
End If

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
End Sub
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem in reading some part of a file denzil_cactus Perl 1 June 29th, 2007 09:29 AM
Creating a .bat file with CR and linefeed rjonk XSLT 1 November 29th, 2006 01:38 PM
bat file doesn't work maroun BOOK: Beginning Cryptography with Java 1 October 25th, 2005 04:59 PM
Writing to a .BAT file using VB6 rhysduk VB How-To 17 January 7th, 2005 09:06 AM

All times are GMT -4. The time now is 09:46 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.