|
I have a sorted list that stores current values of 3 different data types. I also have a hash table that holds the previous value of each data point. I need to compare the newest value to the previous value and store any ones that change to a list. This has been working fine for months but a new requirement was added making some of the values = nothing and this is where my problems began
Previous code
For each de as DictionaryEntry in serialData
name = de.Key.Tostring
If ValueChanged(de.Value, hash.Item(name),de.value.GetType.Name = 1 Then
... add new value to list
... replace value is hash table with new value
End If
Public Function ValueChanged(Byval val1 as Object, ByVal val2 as Object, ByVal typ as String) as Int16
Select Case typ
Case "Single"
Dim newVal, lastVal as Single
newVal = val1
lastVal = val2
If Not newVal = lastVal then
Return 1
Else
Return 0
End If
Case "UInt32"
.... same
Case "Int32"
.... same
End Select
For the new requirement, I added a If val1 = Nothing Then Return 1 but now this line returns true when val2 = 0.0 making the function return 1 which I dont want. 0.0 should not be equal to nothing. I also tried using Nullable types
Public shared Function HasChanged(ByVal val1 as Single, ByVal val2 as Nullable(Of Single)) As Int16
If val2.HasValue Then
If val1 = val2 Then
Return 0
Else
Return 1
End if
Else
Return 1
End if
Public shared Function HasChanged(ByVal val1 as Single, ByVal val2 as Nullable(Of Int32)) As Int16
If val2.HasValue Then
If val1 = val2 Then
Return 0
Else
Return 1
End if
Else
Return 1
End if
Public shared Function HasChanged(ByVal val1 as Single, ByVal val2 as Nullable(Of UInt32)) As Int16
If val2.HasValue Then
If val1 = val2 Then
Return 0
Else
Return 1
End if
Else
Return 1
End if
but this increases my CPU from 3% to 56%! Any idea what I could be doing wrong. I am in a time crunch
|
|
|
|
|
Hi,
nullable types don't come for free, they take more memory and more cycles, as they have to store and process the data that goes with the extra functionality (think of it as one extra boolean flag "hasValue",
it would double the footprint of an int, double the amount of data to be copied when performing nullable int=nullable int, etc).
you may have to account for changes in "hasValue" too; i.e. a variable that goes from "hasNoValue" to "hasValue" has definitely changed (and if you allow the reverse change, from "hasValue" to "hasNoValue", that would be a change too). So your history information should not be just "oldValue" but also "oldHasValue". Hence
Public shared Function HasChanged(ByVal val1 as Single, ByVal val2 as Nullable(Of Int32)) As Int16
IMO should be more like (I'm no VB expert!):
Public shared Function HasChanged(ByVal val1 as Nullable(Of Int32), ByVal val2 as Nullable(Of Int32)) As Bool
if val1.HasValue AND val2.HasValue return val1<>val2 ' value changed
if val1.HasValue <> val2.HasValue return True ' hasValue changed
return False ' was and is without value
End Function
Some more remarks:
1. Try to avoid ToString. if Key is already a string, no need to call ToString on it.
2. I'm not sure having two different collections (one of them a HashTable/Dictionary) is wise; I would try and figure a way with just one. More in particular, if current value and previous value is a characteristic of your objects, I would incorporate that in the object itself, not delegate it to some HashTable. A simple For Each would then suffice.
3. While doing (2) I would not use nullable types, instead I would add an explicit bool flag to my objects. As I expect my code would be more efficient than the general-purpose nullable support (see first alinea).
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
modified on Wednesday, August 12, 2009 2:34 PM
|
|
|
|
|
Thanks for your response Luc,
I definitely get the increase now... I tried your update and while it does make unfortunately I am running on a very limited processor and cant afford a performance hit like that.
Thanks for your other remarks too, I can definitely see the your second point and will try to incorporate in the time i have left.
I appreciate the help
|
|
|
|
|
you're welcome.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Public shared Function HasChanged(ByVal val1 as Nullable(Of Int32), ByVal val2 as Nullable(Of Int32)) As Bool
if val1.HasValue AND val2.HasValue return val1<>val2
if val1.HasValue <> val2.HasValue return True
return False
End Function
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Hi Everyone,
I need a database project in Visual Basic with SQL Server 2005/2008. Can anyone provide me a sample projects/source code for this?
Thanks in Advance
Raj
|
|
|
|
|
Google is your friend and Bing is its buddy.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Why?? So you can pass a class you don't deserve to pass?? I don't think so...
|
|
|
|
|
No. You won't get finished code from here very often, unless you catch someone who's in an exceptionally good mood. If you want a pointer in the right direction, look at this article: Beginners guide to accessing SQL Server through C#[^]
Between the idea
And the reality
Between the motion
And the act
Falls the Shadow
|
|
|
|
|
Hi
In my program I would like to use a cursor from windows\cursors. In the Load event I use the following code:
Cursor = New Cursor("c:\windows\cursors\3dgarro.cur")
(This is a built-in cursor of Windows.)
However, the result is a plain black arrow instead of the 3D golden one. (I tried with other cursors too, the result is always a black arrow.)
I have no idea what the problem is. Any advices would be welcome.
|
|
|
|
|
In my windows folder I don't have a golden cursor.
Maybe extra cursors like that are extra ones you have the choice of adding when you install Windows? Although I have never seen a golden one. What version of Windows are you using?
If everything was not true, would it be not true that everything is not true? So by saying everything is not true, you are automatically denying that everything is not true. Im so confused...
FreeDOS
- An open source modern
MS-DOS/PC-DOS replacement.
|
|
|
|
|
Perhaps the Golden Cursor is a close relative of the Golden Rivet?
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
The problem is not about the golden arrow, it does not work with any cursor.
(Anyway, the golden arrow was installed with my XP Prof by default, not optional, no extra-pack or sg like that.)
|
|
|
|
|
I know a way to do what you want, but it involves using the P/Invoke capability of .NET.
Here it is in C# (I will try to convert it to VB for you but I don't use VB very often, so I may make a few errors), in case another kind CPian will convert it properly.
C#
[DllImport("user32.dll")]
static extern IntPtr LoadCursorFromFile(string lpFileName);
static Cursor ColoredCursor;
static ColoredCursorForm() {
IntPtr cursor = LoadCursorFromFile(@"c:\windows\cursors\3dgarro.cur");
ColoredCursor = new Cursor(cursor);
}
Better than me translating it take a look at this (pinvoke.net)[^], scroll down a bit, you will find a VB example. This is a very useful site, I suggest that you bookmark it.
Good Luck!
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
I used the following code:
Declare Function LoadCursorFromFileA Lib "user32.dll" (ByVal lpFileName$) As IntPtr
Sub LoadCur()
Cursor = New Cursor(LoadCursorFromFileA("c:\windows\cursors\3dgarro.cur"))
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
LoadCur()
End Sub
It works perfectly with every cursor file (even animated ones). Thanks!
|
|
|
|
|
This Solution worked, but only after I figured out that I needed to put my custom cursors in the c:\windows\cursors folder.
Thanks for the tip.
|
|
|
|
|
Hi Everyone,
I am searching for an app or code that will click a required text link on the screen. (i.e) I have a list of names and the program must (1) pick each name from the file (2) search the name in a web page in a browser (3) Once the name is found, click on the name (the names are text links to pages) (4) after some delay, get back to the previous page.
I am not sure where to start from.
Any help would be greatly appreciated.
Thanks.
|
|
|
|
|
Member 2056609 wrote: I am searching for an app or code
The world is a cold and heartless place.
However, we are here to try and warm it up just a little bit, and the title of your post suggests that you have already tried something yourself.
What have you got so far?
My advice is free, and you may get what you paid for.
|
|
|
|
|
Frankly, I have only extracted the list of names that has to be searched (a different part). Haven't done anything constructive in the mouse click part, since not sure where to start from.
Sorry for the empty hand reply.
Thanks.
|
|
|
|
|
Okay just a few pointers in the right direction:
1. Forget the mouse click event
2. Slap a browser control on your form
3. Research how to read through a webpage's content
4. compare your search list to the content of the web page
(5. Store your original url in a variable somewhere)
6. Research how to extract the url from a link on a webpage
7. when a link is found, set your browser control to go to the url of that link
8. after a while tell the browser to go back to the original page.
My advice is free, and you may get what you paid for.
|
|
|
|
|
Hi all...
I am creating a small project in VB.NET(VS2005). There I used wmp.dll library for playing media files.
Now, while playing a song by using that library, I wanna record that sound through output because I wanna mix that song with some other sounds.
Suggest me how can I do that.
Thanks
Gagan
|
|
|
|
|
That does not begin to make sense. You can't record using the output, you would use the input to record.
If everything was not true, would it be not true that everything is not true? So by saying everything is not true, you are automatically denying that everything is not true. Im so confused...
FreeDOS
- An open source modern
MS-DOS/PC-DOS replacement.
|
|
|
|
|
No Lloyd, in Windows one can record any output sound by using a sound or voice recorder and by doing some setting mannually.
Open volume control->Options->Properties
There select recording radio button and check "stereo mix" and "wave" checkboxes.
Now you can play any sound and by using a sound recorder, you can record that output sound.
I wanna do the whole same thing by programming not mannually. I wanna record any output song (not input) through vb.net programming. How can I do this??
Thanks
Gagan
|
|
|
|
|
Well that still does not make sense
However, if you mean any sound the computer makes you wish to record, then I don't really know if this is possible through code.
If everything was not true, would it be not true that everything is not true? So by saying everything is not true, you are automatically denying that everything is not true. Im so confused...
FreeDOS
- An open source modern
MS-DOS/PC-DOS replacement.
|
|
|
|
|
hi
i have problem to record wave output, can i help me please to record sound output cardsound
thanks
|
|
|
|