I want to ask for help for creating an activity logfie for example if the client delete data from the database,it will written to the logfile at what time he/she delete the data etc.Also i want to ask,is it possible to read ip and write it to log file from the client if the application was only installed on the server side,but the application was used by 3 clients?Thanks a lot.
create log file
Started by yonghan, May 19 2008 05:27 PM
12 replies to this topic
#1
Posted 19 May 2008 - 05:27 PM
|
|
|
#2
Posted 20 May 2008 - 11:24 AM
Hi yonghan,
For creating a log, you could open a file for output and print the information to it as it passes various parts of the application.
If the client is accessing the server via Winsock (if the application is a Windows based app rather than a web application on a website), then you could get the users IP via the Winsock object on the server form... a la Winsock1.RemoteHostIP (if I remember right?)
And you can write that to the log file in the same way as above :)
For creating a log, you could open a file for output and print the information to it as it passes various parts of the application.
'-- Open a file for output --| Open "c:\access.log" for output as #1 ................. ................. ................. '-- Set a variable to hold the text going into the log file --| strTemp = << stuff to go into the log file >> '-- Send variable into the log file --| Print #1, strTemp ................. ................. '-- And at the end, close the file --| Close #1
If the client is accessing the server via Winsock (if the application is a Windows based app rather than a web application on a website), then you could get the users IP via the Winsock object on the server form... a la Winsock1.RemoteHostIP (if I remember right?)
And you can write that to the log file in the same way as above :)
#4
Posted 20 May 2008 - 02:26 PM
Ah yes, didn't think to ask what version of VB he used...
For the record... my example code was in VB6.
For the record... my example code was in VB6.
#5
Posted 20 May 2008 - 06:12 PM
i'm using vb 6.I'm intending to make a log for the clients activity for example delete data etc.So the owner know what had happen..Are there any reference about winsock using vb 6??Thanks..
#6
Posted 20 May 2008 - 06:19 PM
The application was putted on the server,the clients are using it..Some sort of creating a shortcut to the application i suppose..Is it possible to get the clients ip that access the application??thanks..
#7
Posted 21 May 2008 - 04:55 AM
For creating a log, the code I provided will work fine - I use it myself for the same purpose in another application I've made in the past.
Right... I originally thought there were 2 applications (a server side and a client side) which may have used winsock to communicate between them.
From the quote I've included, it seems as though there is only one application which is kept on the server which I wouldn't know how to get the client's IP address from :(
yonghan said:
The application was putted on the server,the clients are using it..Some sort of creating a shortcut to the application i suppose..Is it possible to get the clients ip that access the application??thanks..
Right... I originally thought there were 2 applications (a server side and a client side) which may have used winsock to communicate between them.
From the quote I've included, it seems as though there is only one application which is kept on the server which I wouldn't know how to get the client's IP address from :(
#8
Posted 21 May 2008 - 06:48 PM
Ok,thanks..I also want to ask for help again..I wrote a function to add data to access.I'm intending to store the sold goods into it,and check when a transaction was made,are there the same date,code,name of the goods.If there are same,then the quantity field will be updated..I create it to see the most sold goods..Here are the codes..Please help me to check it..Or are there another way to get the most sold goods??Thanks..
Private Sub terlaku()
Dim a, Jumlah As Integer
Dim kode As String
For a = txtKode.LBound To txtKode.UBound
If txtKode(a).Text <> "" Then
If txtQty(a).Text <> "" Then
kode = txtKode(a).Text
rsterlaku.AddNew
rsterlaku!ID = CStr(Date) & " - " & strUser
rsterlaku!tgl = Date
rsterlaku!kd_brg = txtKode(a).Text
rsterlaku!nm_brg = txtNama(a).Text
rsterlaku!Qty = txtQty(a).Text
rsterlaku!User = strUser
rsterlaku!Update = Now
If rsterlaku.RecordCount > 0 Then
rsterlaku.MoveFirst
rsterlaku.Index = "tgl"
rsterlaku.Seek "=", Date
If Not rsterlaku.NoMatch Then
rsterlaku.Index = "kd_brg"
rsterlaku.Seek "=", kode
If Not rsterlaku.NoMatch Then
rsterlaku.Index = "user"
rsterlaku.Seek "=", lbluser.Caption
If Not rsterlaku.NoMatch Then
Jumlah = CInt(rsterlaku!Qty)
rsterlaku.Edit
rsterlaku!Qty = CStr(Jumlah + CInt(rsterlaku!Qty))
rsterlaku!User = strUser
rsterlaku!Update = Now
Else
If rsterlaku.NoMatch Then
rsterlaku.AddNew
rsterlaku!ID = CStr(Date) & " - " & strUser
rsterlaku!tgl = Date
rsterlaku!kd_brg = txtKode(a).Text
rsterlaku!nm_brg = txtNama(a).Text
rsterlaku!Qty = txtQty(a).Text
rsterlaku!User = strUser
rsterlaku!Update = Now
End If
End If
End If
End If
End If
End If
End If
rsterlaku.Update
Next a
End Sub
Private Sub terlaku()
Dim a, Jumlah As Integer
Dim kode As String
For a = txtKode.LBound To txtKode.UBound
If txtKode(a).Text <> "" Then
If txtQty(a).Text <> "" Then
kode = txtKode(a).Text
rsterlaku.AddNew
rsterlaku!ID = CStr(Date) & " - " & strUser
rsterlaku!tgl = Date
rsterlaku!kd_brg = txtKode(a).Text
rsterlaku!nm_brg = txtNama(a).Text
rsterlaku!Qty = txtQty(a).Text
rsterlaku!User = strUser
rsterlaku!Update = Now
If rsterlaku.RecordCount > 0 Then
rsterlaku.MoveFirst
rsterlaku.Index = "tgl"
rsterlaku.Seek "=", Date
If Not rsterlaku.NoMatch Then
rsterlaku.Index = "kd_brg"
rsterlaku.Seek "=", kode
If Not rsterlaku.NoMatch Then
rsterlaku.Index = "user"
rsterlaku.Seek "=", lbluser.Caption
If Not rsterlaku.NoMatch Then
Jumlah = CInt(rsterlaku!Qty)
rsterlaku.Edit
rsterlaku!Qty = CStr(Jumlah + CInt(rsterlaku!Qty))
rsterlaku!User = strUser
rsterlaku!Update = Now
Else
If rsterlaku.NoMatch Then
rsterlaku.AddNew
rsterlaku!ID = CStr(Date) & " - " & strUser
rsterlaku!tgl = Date
rsterlaku!kd_brg = txtKode(a).Text
rsterlaku!nm_brg = txtNama(a).Text
rsterlaku!Qty = txtQty(a).Text
rsterlaku!User = strUser
rsterlaku!Update = Now
End If
End If
End If
End If
End If
End If
End If
rsterlaku.Update
Next a
End Sub
#9
Posted 22 May 2008 - 07:49 AM
Don't forget to wrap [CODE ] and [/CODE ] tags around your code!
I'm not sure if your code is the most efficient way to write it. There are lots of End Ifs at the end, don't you think? Could you indent the code to make it easier to read?
I'm not sure if your code is the most efficient way to write it. There are lots of End Ifs at the end, don't you think? Could you indent the code to make it easier to read?
Edited by Xav, 22 May 2008 - 07:52 AM.
#10
Posted 22 May 2008 - 06:11 PM
Private Sub terlaku()
Dim a, Jumlah As Integer
Dim kode As String
For a = txtKode.LBound To txtKode.UBound
If txtKode(a).Text <> "" Then
If txtQty(a).Text <> "" Then
kode = txtKode(a).Text
rsterlaku.AddNew
rsterlaku!ID = CStr(Date) & " - " & strUser
rsterlaku!tgl = Date
rsterlaku!kd_brg = txtKode(a).Text
rsterlaku!nm_brg = txtNama(a).Text
rsterlaku!Qty = txtQty(a).Text
rsterlaku!User = strUser
rsterlaku!Update = Now
If rsterlaku.RecordCount > 0 Then
rsterlaku.MoveFirst
rsterlaku.Index = "tgl"
rsterlaku.Seek "=", Date
If Not rsterlaku.NoMatch Then
rsterlaku.Index = "kd_brg"
rsterlaku.Seek "=", kode
If Not rsterlaku.NoMatch Then
rsterlaku.Index = "user"
rsterlaku.Seek "=", lbluser.Caption
If Not rsterlaku.NoMatch Then
Jumlah = CInt(rsterlaku!Qty)
rsterlaku.Edit
rsterlaku!Qty = CStr(Jumlah + CInt(rsterlaku!Qty))
rsterlaku!User = strUser
rsterlaku!Update = Now
Else
If rsterlaku.NoMatch Then
rsterlaku.AddNew
rsterlaku!ID = CStr(Date) & " - " & strUser
rsterlaku!tgl = Date
rsterlaku!kd_brg = txtKode(a).Text
rsterlaku!nm_brg = txtNama(a).Text
rsterlaku!Qty = txtQty(a).Text
rsterlaku!User = strUser
rsterlaku!Update = Now
End If
End If
End If
End If
End If
End If
End If
rsterlaku.Update
Next a
End Sub
Dim a, Jumlah As Integer
Dim kode As String
For a = txtKode.LBound To txtKode.UBound
If txtKode(a).Text <> "" Then
If txtQty(a).Text <> "" Then
kode = txtKode(a).Text
rsterlaku.AddNew
rsterlaku!ID = CStr(Date) & " - " & strUser
rsterlaku!tgl = Date
rsterlaku!kd_brg = txtKode(a).Text
rsterlaku!nm_brg = txtNama(a).Text
rsterlaku!Qty = txtQty(a).Text
rsterlaku!User = strUser
rsterlaku!Update = Now
If rsterlaku.RecordCount > 0 Then
rsterlaku.MoveFirst
rsterlaku.Index = "tgl"
rsterlaku.Seek "=", Date
If Not rsterlaku.NoMatch Then
rsterlaku.Index = "kd_brg"
rsterlaku.Seek "=", kode
If Not rsterlaku.NoMatch Then
rsterlaku.Index = "user"
rsterlaku.Seek "=", lbluser.Caption
If Not rsterlaku.NoMatch Then
Jumlah = CInt(rsterlaku!Qty)
rsterlaku.Edit
rsterlaku!Qty = CStr(Jumlah + CInt(rsterlaku!Qty))
rsterlaku!User = strUser
rsterlaku!Update = Now
Else
If rsterlaku.NoMatch Then
rsterlaku.AddNew
rsterlaku!ID = CStr(Date) & " - " & strUser
rsterlaku!tgl = Date
rsterlaku!kd_brg = txtKode(a).Text
rsterlaku!nm_brg = txtNama(a).Text
rsterlaku!Qty = txtQty(a).Text
rsterlaku!User = strUser
rsterlaku!Update = Now
End If
End If
End If
End If
End If
End If
End If
rsterlaku.Update
Next a
End Sub
#11
Posted 22 May 2008 - 06:14 PM
Actually what i want to do is to create a report of all the goods that are most sold.I do like if there are another way..Can u teach me how to use query to sum all the same goods code at the same day and report it??Thanks a lot..
#12
Posted 04 May 2010 - 04:31 PM
hello to all, im new into programming. i just want to ask how to make a log file (textfile) containing ip address (and username if possible) using vb6, said log file will resides inside a folder for i want to track those who access said folder..thanks in advance..


Sign In
Create Account


Back to top









