Jump to content

ConsoleWrite to txt doc or excel document


Recommended Posts

hi,

i trying something with this code, the data what incomine are written in the console, this works wonderful, so how i can write the directly to a txtfile oder excel file .xls ??

thanks in adavance

HotKeySet("{ESC}", "_Killit")

$NetComm = ObjCreate("NETCommOCX.NETComm");Create NETComm.ocx object

;Set object settings
With $NetComm
        .CommPort = 1               ;Set port number
        .Settings = "9600,N,8,1"    ;Set port settings
        .InputLen = 0               ;reads entire buffer
        .InputMode = 0              ;reads in text mode
        .HandShaking = 3           ;uses both RTS and Xon/Xoff handshaking
        .PortOpen = "True"          ;opens specified COM port
EndWith

While 1
    _GetData()
WEnd

Func _GetData()
    If $NetComm.InBufferCount > 0 Then      
        ConsoleWrite($NetComm.InputData)    
        Sleep(250)                          
    EndIf
EndFunc

Func _Killit()
    Exit
EndFunc
Link to comment
Share on other sites

Dim $filename = "nameonthefile.txt"
Dim $write = "This is the text I want to write, this is what you are going to write";;This could be Dim $write = $NetComm.InputData
Dim $filehandle = FileOpen($filename, 1)
FileWrite($filehandle, $write)
FileClose($filehandle)

Link to comment
Share on other sites

I thought you asked for how to write a value to a file, and I posted how to do it :)

Dim $filename = "nameonthefile.txt"
Dim $write = "This is the text I want to write, this is what you are going to write"
Dim $filehandle = FileOpen($filename, 1)
FileWrite($filehandle, $write)
FileClose($filehandle)

Dim $filename = "nameonthefile.txt"

*The name of the file you want to write to

Dim $write = "This is the text I want to write, this is what you are going to write"

*What you are going to write to the file

Dim $filehandle = FileOpen($filename, 1)

*Opens the file

FileWrite($filehandle, $write)

*Writes to the file from the variable $write that was decleared

FileClose($filehandle)

*Closes the file (Kind of useless)

Link to comment
Share on other sites

HotKeySet("{ESC}", "_Killit")

$NetComm = ObjCreate("NETCommOCX.NETComm");Create NETComm.ocx object

;Set object settings
With $NetComm
        .CommPort = 1                ;Set port number
        .Settings = "9600,N,8,1"    ;Set port settings
        .InputLen = 0                ;reads entire buffer
        .InputMode = 0                ;reads in text mode
        .HandShaking = 3           ;uses both RTS and Xon/Xoff handshaking
        .PortOpen = "True"            ;opens specified COM port
EndWith

$file = FileOpen("output.txt", 1)

While 1
    If $NetComm.InBufferCount > 0 Then        
        FileWrite($file, $NetComm.InputData)
    EndIf
    Sleep(250)
WEnd

Func _Killit()
    FileClose($file)
    Exit
EndFunc

This will take everything from the line and just write it to the file. I don't know the object so I can't tell you how to send things.

Also, I removed your get data function by just putting it's code in the loop. It's more efficient this way.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...