I am trying to make a loadcounter so that as a form loads an ID number is input into a readonly text box. This would be calculated from the hash address of the last saved record saved on the file plus 1000. I am stumped as to what to do. Any help?
Printable View
I am trying to make a loadcounter so that as a form loads an ID number is input into a readonly text box. This would be calculated from the hash address of the last saved record saved on the file plus 1000. I am stumped as to what to do. Any help?
Hello,
I would suggest showing code you currently have, otherwise it's a pot-shot in which direction to go in for assisting you.
'Zero the loadcounter
Loadcounter = 0
'Open the file to count customer data
FileOpen(1, "CustomerDetails.dat", OpenMode.Random, , , Len(Customer))
While Not EOF(1)
FileGet(1, "CustomerDetails.dat")
Loadcounter = Loadcounter + 1
End While
FileClose(1)
'add 1 to create new customer ID number
txtCustomerID.Text = (1000 + Loadcounter + 1)
Okay, I am not versed in VB6 style of coding so if I was going to work with a hashtable it would be something like the following which may not work for you.
Adapted from MSDN BinaryFormatter class example.
Code:Sub Serialize()
Dim ht As New Hashtable
For x As Int32 = 1 To 1000
ht.Add(x, "Item" & x.ToString)
Next
Dim fs As New FileStream("DataFile.dat", FileMode.Create)
Dim formatter As New BinaryFormatter
Try
formatter.Serialize(fs, ht)
Catch e As SerializationException
Console.WriteLine("Failed to serialize. Reason: " & e.Message)
Throw
Finally
fs.Close()
End Try
End Sub
Sub Deserialize()
Dim ht As Hashtable = Nothing
Dim fs As New FileStream("DataFile.dat", FileMode.Open)
Try
Dim formatter As New BinaryFormatter
ht = DirectCast(formatter.Deserialize(fs), Hashtable)
Catch e As SerializationException
Console.WriteLine("Failed to deserialize. Reason: " & e.Message)
Throw
Finally
fs.Close()
End Try
'
' Uncomment to see the data
'
'For Each de As DictionaryEntry In ht
' Console.WriteLine("{0}: {1}.", de.Key, de.Value)
'Next
TextBox1.Text = CStr((From T In ht.Cast(Of DictionaryEntry)() Select CInt(T.Key)).FirstOrDefault + 1)
End Sub