Yes, there are different ways to arrive at the same result. I like to have multiple text boxes so that I can see what is going on during the process. It helps me to troubleshoot problems later on. I built the code from scratch this time, just to make sure that I show all of the code required:
Imports ActiveHomeScriptLib
Imports System.IO
Public Class Form1
Dim WithEvents ActiveHomeObj As ActiveHomeScriptLib.ActiveHome
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ActiveHomeObj = New ActiveHome
End Sub
Sub ActiveHome_RecvAction(ByVal bszRecv As Object _
, ByVal vParm1 As Object _
, ByVal vParm2 As Object _
, ByVal vParm3 As Object _
, ByVal vParm4 As Object _
, ByVal vParm5 As Object _
, ByVal vReserved As Object) Handles ActiveHomeObj.RecvAction
TextBox1.Text = " " & (vParm1 & " " & vParm2 & " " & vParm3)
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Dim TargetFile As StreamWriter
Try
System.IO.File.WriteAllText("C:\X10Activity.txt", "")
TargetFile = New StreamWriter("C:\X10Activity.txt", True)
TargetFile.Write(Now())
TargetFile.Write(TextBox2.Text)
TargetFile.WriteLine()
TargetFile.WriteLine()
TargetFile.Close()
Dim clsRequest As System.Net.FtpWebRequest = _
DirectCast(System.Net.WebRequest.Create("
http://ftp://ftp.<your-website>.com/X10Activity.txt"), System.Net.FtpWebRequest)
clsRequest.Credentials = New System.Net.NetworkCredential("<your ftp login>", "your ftp password")
clsRequest.Method = System.Net.WebRequestMethods.Ftp.UploadFile
' read in file...
Dim bFile() As Byte = System.IO.File.ReadAllBytes("C:\X10Activity.txt")
' upload file...
Dim clsStream As System.IO.Stream = _
clsRequest.GetRequestStream()
clsStream.Write(bFile, 0, bFile.Length)
clsStream.Close()
clsStream.Dispose()
TextBox2.AppendText(TextBox1.Text & " " & Date.Now & vbCrLf)
Catch exc As Exception
Console.WriteLine("err num: " & Str(Err.Number) & " '" & exc.ToString & "'")
End Try
End Sub
End Class
The program will hang momentarily when it receives the first event. Just let it run and trigger your events and watch the file up on the web.
The file on the web will reset (zero out) every time the program is launched.
Don can modify it according to his needs.
- spval