View Single Post
  #13 (permalink)  
Old January 6th, 2005, 05:20 PM
rhysduk rhysduk is offline
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

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 :

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)

  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.


Reply With Quote