P
Paul Ilacqua
I'm a VB6 convert with 6 months into VB2005... I'm a Database developer and
like to roll my own "counters" for my front end programs. Instead of using
IDENTITY I use my counters.
Is this code even close to being efficient or am I off base. It does work
though... I just want to get off the ground correctly with the new VB
Thanks
Paul
'-----------------------------------------------------------------------------------------------------------
Function Increment_Counter() As Integer
Dim sFile As String = "L:\Warranty\Secure\123.dat"
Dim CurrentValue As Integer = 0
Dim NewValue As Integer = 0
Dim fs As New System.IO.FileStream(sFile, IO.FileMode.Open,
IO.FileAccess.ReadWrite, IO.FileShare.None)
Dim r As New IO.BinaryReader(fs)
fs.Lock(0, 5)
CurrentValue = (r.ReadInt32())
fs.Unlock(0, 5)
fs.Close()
fs = New System.IO.FileStream(sFile, IO.FileMode.Open,
IO.FileAccess.ReadWrite)
Dim w As New IO.BinaryWriter(fs)
NewValue = CurrentValue + 1
fs.Lock(0, 5)
w.Write(NewValue)
r = New IO.BinaryReader(fs)
CurrentValue = (r.ReadInt32())
fs.Unlock(0, 5)
r.Close()
w.Close()
fs.Close()
Return NewValue
End Function
'-----------------------------------------------------------------------------------------------------------
like to roll my own "counters" for my front end programs. Instead of using
IDENTITY I use my counters.
Is this code even close to being efficient or am I off base. It does work
though... I just want to get off the ground correctly with the new VB
Thanks
Paul
'-----------------------------------------------------------------------------------------------------------
Function Increment_Counter() As Integer
Dim sFile As String = "L:\Warranty\Secure\123.dat"
Dim CurrentValue As Integer = 0
Dim NewValue As Integer = 0
Dim fs As New System.IO.FileStream(sFile, IO.FileMode.Open,
IO.FileAccess.ReadWrite, IO.FileShare.None)
Dim r As New IO.BinaryReader(fs)
fs.Lock(0, 5)
CurrentValue = (r.ReadInt32())
fs.Unlock(0, 5)
fs.Close()
fs = New System.IO.FileStream(sFile, IO.FileMode.Open,
IO.FileAccess.ReadWrite)
Dim w As New IO.BinaryWriter(fs)
NewValue = CurrentValue + 1
fs.Lock(0, 5)
w.Write(NewValue)
r = New IO.BinaryReader(fs)
CurrentValue = (r.ReadInt32())
fs.Unlock(0, 5)
r.Close()
w.Close()
fs.Close()
Return NewValue
End Function
'-----------------------------------------------------------------------------------------------------------