Storing and Calculating data into Hashtable
I am making a small tool that require some calculation. I am using hashtable to store values that I need to calculate. This tool continuously extract data on specific time interval(30 seconds) from webpage and add those data into the hashtable. Now the problem is I need to store the previous extraction data and when new extraction occurs, I need to deduct the previous data from new data.
Here is the process I am currently following:
Dim MyTable as New Hashtable
MyTable.Add("Data1","200")
MyTable.Add("Data2","100")
MyTable.Add("Data3", MyTable.Item("Data1") - MyTable.Item("Data2") )
'Here I need to redefine the value of Data2 as same as Data1
MyTable.Add(MyTable.Item("Data1"))
On first run it shows the result of Data3 = 100 which is currect. But on second run I need to redefine the value of Data2 = Data1 . So I need a result of Data3 = 0 on second run. This may not be the proper way to do this sort of operation. I have also tried using listbox, listview and even textfile to store the Data2 and recall that on second run. But could not make it possible.
This is the last phase of my tool and I am st开发者_如何学运维uck with it. So, I really hope someone will come front and help me in this regards.
Thanks
Dude, I don't quite understand what you are asking, however I'll give it a shot. First off, I dont believ you need to use a HASTABLE unless you'll be searching a list via keys. It appears you just want to keep the previous callculated result during the application runtime scope (or lifetime). Look into making your vairables Global.
'This variable is outside the scope of the function.
Private previousResult As Integer
Public Function ComputeData(valueOne as Integer, ValueTwo as Integer) as Integer
previousResult = valueOne - valueTwo
Return previousResult
End Function
Whenever the ComputeData is called the the new calculated result is stored in the previousResult variable. Note that it is a valid storage for the lifetime of the application.
精彩评论