Jump to content

create log file

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
12 replies to this topic

#1
yonghan

yonghan

    Learning Programmer

  • Members
  • PipPipPip
  • 99 posts
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.

#2
scsefrmr

scsefrmr

    Learning Programmer

  • Members
  • PipPipPip
  • 45 posts
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.


'-- 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 :)

#3
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
How are you storing the data? And which version of VB are you using? .NET?
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#4
scsefrmr

scsefrmr

    Learning Programmer

  • Members
  • PipPipPip
  • 45 posts
Ah yes, didn't think to ask what version of VB he used...
For the record... my example code was in VB6.

#5
yonghan

yonghan

    Learning Programmer

  • Members
  • PipPipPip
  • 99 posts
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
yonghan

yonghan

    Learning Programmer

  • Members
  • PipPipPip
  • 99 posts
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
scsefrmr

scsefrmr

    Learning Programmer

  • Members
  • PipPipPip
  • 45 posts
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.


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
yonghan

yonghan

    Learning Programmer

  • Members
  • PipPipPip
  • 99 posts
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

#9
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
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?

Edited by Xav, 22 May 2008 - 07:52 AM.

Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#10
yonghan

yonghan

    Learning Programmer

  • Members
  • PipPipPip
  • 99 posts
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

#11
yonghan

yonghan

    Learning Programmer

  • Members
  • PipPipPip
  • 99 posts
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
noobtyro

noobtyro

    Newbie

  • Members
  • Pip
  • 1 posts
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..