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
Register
| FAQ | Members List | Calendar | 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
Reply
 
Thread Tools Search this Thread Display Modes
  #11 (permalink)  
Old January 6th, 2005, 04:00 PM
Friend of Wrox
Points: 4,007, Level: 26
Points: 4,007, Level: 26 Points: 4,007, Level: 26 Points: 4,007, Level: 26
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Lansing, Michigan, USA.
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

I just told you :)

strUsername = Mid(TextLine$, Instr(TextLine$,"=") + 2)


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
Reply With Quote
  #12 (permalink)  
Old January 6th, 2005, 04:01 PM
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

Im sorry but i dont understand :( Apologies.

Rhys

Reply With Quote
  #13 (permalink)  
Old January 6th, 2005, 05:20 PM
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

Right this is whati have :

A BAT file called Test.BAT (with extension)
A form with a label called Label1 and a command button called command1.

This is all of the code that i have :

Code:
Private Sub Command2_Click()
  Dim TextLine$, Filename$
  Dim FileHandle As Integer
  Dim strUserName As String
  Filename$ = "Test.BAT"

    ' Test if the file exists
  If Dir(Filename$) = "" Then Exit Sub

  FileHandle = FreeFile ' This is safer than assigning a number

  Open Filename$ For Input As #FileHandle

  Do While Not EOF(FileHandle)        ' Loop until end of file
   Line Input #FileHandle, TextLine$  ' Read line into variable
    ' Your code here
strUserName = Mid(TextLine$, InStr(TextLine$, "=") + 2)
  Loop

  Close #FileHandle
Label1.Caption = strUserName
End Sub

>>>>>>>>>>>>>>>>>>>>>>>>>>>

Private Sub Form_Load()

Open App.Path & "\Test.BAT" For Output As #1
   Print #1, "strUserName = rhys"
   Print #1, ""
   Print #1, ""
Close #1
End Sub
>>>>>>>> indicates a end of the code .. and start of another bit of code.

Now on pressing the command button (note that this needs to be compilied to an exe before it will write to the bat file) the caption of the label should be set to the value that has been taken from the BAT file (rhys)!! But its not, its set to nothing, emtpy, zero, zilch!

I still dont see why i have to put "Dim strUserName as String" in the code because im taking the value from the BAT file?? and not the application itself.

Regards
Rhys

Reply With Quote
  #14 (permalink)  
Old January 6th, 2005, 06:32 PM
Authorized User
 
Join Date: Dec 2004
Location: , , .
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Rhysduk,

strUserName is an arbitrary memory variable used to hold a piece of the string read from the file. It could be called strPiece for that matter. It doesn't necessarily correspond to the text you have written to the file. The caption property of your label needs to be set to a character string.

Dude
Reply With Quote
  #15 (permalink)  
Old January 7th, 2005, 08:46 AM
Friend of Wrox
Points: 4,007, Level: 26
Points: 4,007, Level: 26 Points: 4,007, Level: 26 Points: 4,007, Level: 26
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Lansing, Michigan, USA.
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Here, this may help.

Code:
Private Sub Command2_Click()

    Dim TextLine$, Filename$
    Dim FileHandle As Integer
    Dim strUserName As String

    Filename$ = "Test.BAT"

    ' Test if the file exists
    If Dir(Filename$) = "" Then Exit Sub

    FileHandle = FreeFile ' This is safer than assigning a number
    Open Filename$ For Input As #FileHandle

    ' Initialize the user in case it's not found in the BAT file
    strUserName = "Not Found"

    Do While Not EOF(FileHandle)      ' Loop until end of file
        Line Input #FileHandle, TextLine$  ' Read line into variable
        If Instr(Textline$,"=") > 0 Then 
            strUserName = Mid(TextLine$, InStr(TextLine$, "=") + 2)
        End If
    Loop

    Close #FileHandle
    Me.Label1.Caption = strUserName

End Sub

Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
Reply With Quote
  #16 (permalink)  
Old January 7th, 2005, 08:57 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

Thank you very much greg. it is working exactly how i want!

Do i need to repeat the process to get another value for another string in the BAT file?

If not.. what?

Thanks
Rhys

Reply With Quote
  #17 (permalink)  
Old January 7th, 2005, 09:02 AM
Friend of Wrox
Points: 4,007, Level: 26
Points: 4,007, Level: 26 Points: 4,007, Level: 26 Points: 4,007, Level: 26
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Lansing, Michigan, USA.
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Quote:
quote:Originally posted by rhysduk
Do i need to repeat the process to get another value for another string in the BAT file?
You're welcome. If you want to get another string out of the BAT file, yes, you need to look for it in a similar way you did the user ID. Fortunately, you have loop already going in this code so you don't have to repeat the whole subroutine again, just put your second search after the first search inside the existing loop.

Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
Reply With Quote
  #18 (permalink)  
Old January 7th, 2005, 09:06 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

I modifies your code that you agve me to this:

Code:
Private Sub Command2_Click()

    Dim TextLine$, Filename$
    Dim FileHandle As Integer
    Dim strUserName As String
    Dim strUserReg As Integer

    Filename$ = "Test.BAT"

    ' Test if the file exists
    If Dir(Filename$) = "" Then Exit Sub

    FileHandle = FreeFile ' This is safer than assigning a number
    Open Filename$ For Input As #FileHandle

    ' Initialize the user in case it's not found in the BAT file
    strUserName = "Not Found"

    Do While Not EOF(FileHandle)      ' Loop until end of file
        Line Input #FileHandle, TextLine$  ' Read line into variable
        If InStr(TextLine$, "=") > 0 Then
            strUserName = Mid(TextLine$, InStr(TextLine$, "=") + 2)
Do While Not EOF(FileHandle)      ' Loop until end of file
        Line Input #FileHandle, TextLine$  ' Read line into variable
        If InStr(TextLine$, "=") > 0 Then
            strUserReg = Mid(TextLine$, InStr(TextLine$, "=") + 2)

        End If
    Loop

        End If
    Loop

    Close #FileHandle
    Me.Label1.Caption = strUserName
    Me.Label2.Caption = strUserReg
End Sub
And it works perfectly.. Thanks a lot!

You're going in the credits section of the program :)

Reagrds
Rhys

Reply With Quote
Reply


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
confused- what to use .bat or .jar file - plz he ruchisingh Java Basics 1 May 18th, 2006 12:08 PM
bat file doesn't work maroun BOOK: Beginning Cryptography with Java 1 October 25th, 2005 04:59 PM
Run .bat file from Excel VBA Harold Hawken Excel VBA 2 June 23rd, 2005 03:03 PM
Problem with reading BAT file rhysduk VB How-To 0 January 12th, 2005 09:53 AM



All times are GMT -4. The time now is 08:21 PM.


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