Get the "changed" data from a _chage textbox event

Twigathy
03-05-2004, 12:53 PM
Hi there,

Im Fairly new to all this stuff, how do I get the text that has changed on a _change event? At the moment i'm using the following code:


Private Sub txtRecieved_Change()
If AutoLog = True Then

Dim FileName As String
Dim FileNumber As Integer
Dim DataToWrite As String
'Define the variables [well no * * * *]

DataToWrite = vbCrLf & txtRecieved.n
FileName = App.Path & "\Logs\" & Date$ & ".txt"
'This makes sure the file saved is in the same dir as the application. Else it gets saved
'in the same directory as the thingy being listed...

FileNumber = FreeFile()
'Set the file number to a "free file"

Open FileName For Append As FileNumber
'Open the file for APPENDING (See the tut for details about different modes)

Write #FileNumber, DataToWrite
Close FileNumber
End If
End Sub


Note that the "AutoLog" is defined under the general declarations thingy, and its changed by another function (Which is in an options menu)

The thing is that this produces log files that look like the one below. Two questions really:

1) How to get rid of the " marks where new stuff is being written
2) How to return the changed text so I only write to the text file what has changed

Much thanks

Twigathy :) (http://www.twigathy.com)

noi_max
03-05-2004, 01:36 PM
Is the user going to type in a new value in the textbox?

Somehow I don't see this as the best option. It looks like when the textbox changes the file gets saved. The change event will fire every time something is typed into the textbox. Unless the textbox is being updated some other way.

Twigathy
03-05-2004, 01:47 PM
Figured something new out. Instead of logging when new data arrives into the textbox I stuck the code into the Winsock-data recieved bit, so now it looks like this:


Private Sub WinsockClient_DataArrival(ByVal bytesTotal As Long)
Dim strMessage As String
Dim FileName As String
Dim FileNumber As Integer
Dim DataToWrite As String
'Define variables

WinsockClient.GetData strMessage
'Get the message from the winsock cache
frmChat.txtRecieved.Text = frmChat.txtRecieved.Text & vbCrLf & strMessage

If AutoLog = True Then
DataToWrite = vbCrLf & strMessage
FileName = App.Path & "\Logs\" & Date$ & ".txt"
'This makes sure the file saved is in the same dir as the application. Else it gets saved
'in the same directory as the thingy being listed...

FileNumber = FreeFile()
'Set the file number to a "free file"

Open FileName For Append As FileNumber
'Open the file for APPENDING (See the tut for details about different modes)

Write #FileNumber, DataToWrite
Close FileNumber
End If
End Sub


However, i'm still interested to know how I would find the answer to my first questions. Mainly the fact that every time the text file gets written to it has Quote (") marks round the text.

thingimijig
03-05-2004, 01:48 PM
use Print instead of Write

thingimijig.

Twigathy
03-05-2004, 02:02 PM
Solved it in a kind of round about way :/

Heres the menu code:

Private Sub mnuOptionsAutoLog_Click()
If mnuOptionsAutoLog.Checked = False Then
mnuOptionsAutoLog.Checked = True
lblAutoLog.Caption = "Enabled"
MsgBox "Autologging is Enabled", vbInformation, "LAN Share"
Else
mnuOptionsAutoLog.Checked = False
lblAutoLog.Caption = "Disabled"
MsgBox "Autologging is Disabled", vbInformation, "LAN Share"
End If
End Sub


And heres what happens when a connection is recieved:
Private Sub WinsockClient_DataArrival(ByVal bytesTotal As Long)
Dim strMessage As String
Dim FileName As String
Dim FileNumber As Integer
Dim DataToWrite As String
'Define variables

WinsockClient.GetData strMessage
'Get the message from the winsock cache
frmChat.txtRecieved.Text = frmChat.txtRecieved.Text & vbCrLf & strMessage

If frmChat.lblAutoLog.Caption = "Enabled" Then
DataToWrite = vbCrLf & strMessage
FileName = App.Path & "\Logs\" & Date$ & ".txt"
'This makes sure the file saved is in the same dir as the application. Else it gets saved
'in the same directory as the thingy being listed...

FileNumber = FreeFile()
'Set the file number to a "free file"

Open FileName For Append As FileNumber
'Open the file for APPENDING (See the tut for details about different modes)

Write #FileNumber, DataToPrint
Close FileNumber
End If
End Sub


Is there a better way of passing data between forms other than using labels? Seems kind of silly to me, although my label is visible to to the user to they can see the status of autologging :)

btw, this project can be found at sourceforge (https://sourceforge.net/projects/lanshare/)

Thanks for your help :)

PWNettle
03-05-2004, 02:48 PM
Is there a better way of passing data between forms other than using labels? Seems kind of silly to me, although my label is visible to to the user to they can see the status of autologging :)

A form is an object based on a class...and you can create your own custom properties for them...can be a good way to pass data without using a control (although using a control does work).

This thread from yesterday (http://www.visualbasicforum.com/showthread.php?t=150404), amongst others, has some discussion about forms and custom properties. It's a bit long but if you sift through it you can see how to setup and use a custom property on a form.

Cheers,
Paul

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum