|
David Skelly wrote: Interpolation
Ding ding ding! Winner winner chicken dinner!
|
|
|
|
|
Ok, we established that what i need, is some sort of linear interpolation.
Any ideas ?
|
|
|
|
|
Dim arr() As Single = {17, 18, 0, 0, 24, 23, 0, 20, 0, 0, 0, 16}
Dim idx1 As Int16 = -1, idx2 As Int16 = -1
Dim FoundAZero As Boolean = False
For i As Int16 = 0 To arr.GetUpperBound(0)
If Not FoundAZero Then
If arr(i) = 0 Then
FoundAZero = True 'once we find an zero the else will be used below until we find the next non zero
Else
idx1 = i 'hold on to the index every non zero
End If
Else
If arr(i) <> 0 Then '
idx2 = i 'hold on to the index of the non zero
'--------------------------------------
'get the value that's held in both indexes
Dim val1 As Int16 = arr(idx1), val2 As Int16 = arr(idx2)
Dim IncVal As Single
'increment value is non zero 1 minus non zero 2 / the number of zeros between
'the * -1 is whether or not we need to increment up or down depending on values of the array
If val1 < val2 Then
IncVal = (val2 - val1) / (idx2 - idx1)
Else
IncVal = ((val1 - val2) / (idx2 - idx1)) * -1
End If
For x As Int16 = idx1 + 1 To idx2 - 1
arr(x) = arr(x - 1) + IncVal 'replace the 0 inbetween both indexes with the incremented value
Next
'--------------------------------------
idx1 = idx2 'take the last none zero and set it to the first hold as we continue down the array
FoundAZero = False 'reset finding a zero flag
End If
End If
Next
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous
|
|
|
|
|
Ok, the code above works almost perfectly.
THe only problem is that if the first position of the array is populated with 0, it crashes at " Dim val1 As Int16 = arr(idx1)", because idx1 remains -1
Thanks.
|
|
|
|
|
I understood that when I wrote but I figured it wouldn't be possible to have the array start with a zero or end with one because how can you figure out what those should be. I guess you could take the number to the right of the 0 and divide by 2 but wasn't sure if that's what should happen.
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous
|
|
|
|
|
Then add some error checking. Assuming you put this code in a method, you can do the check at the right at the top of the method to make sure that the parameter a) is not nothing, b) does not start with a zero, and c) does not end with a zero and throw the appropriate exception. Like so:
Private Sub Interpolate(ByVal values() As Single)
If values Is Nothing Then Throw New ArgumentNullException("values")
If values.Length = 0 Then Exit Sub
If values(0) = 0 Then
Throw New ArgumentException("Value array cannot start with a 0.", "values")
End If
If values(values.Length - 1) = 0 Then
Throw New ArgumentException("Value array cannot end with a 0.", "values")
End If
End Sub
|
|
|
|
|
You may want to turn on Option Strict. When you use val1 and val2 as integers, you will produce incorrect results if one of the non-zero values has a decimal component. Also, I would recommend using Integer instead of Int16 for the index variables as turning on Option Strict will cause errors for both of your loop declarations.
|
|
|
|
|
Hmmmmm... chicken!
Personally, I love the idea that Raymond spends his nights posting bad regexs to mailing lists under the pseudonym of Jane Smith. He'd be like a super hero, only more nerdy and less useful. [Trevel] | FoldWithUs! | sighist | µLaunch - program launcher for server core and hyper-v server
|
|
|
|
|
How to get Hexadecimal code of unicode character
|
|
|
|
|
Hi,
I would cast or convert to integer, then use ToString("X4")
|
|
|
|
|
Char.ConvertToUtf32. That gives it back as an integer, then just format it.
|
|
|
|
|
Here is what I have:
1. an Access form with a subform contained within it.
2. the subform is like a property sheet (maybe I can use tabs hmm...)
3. in one of the (sub)forms, i have a button that will open another form (another property page)
4. when I click the button on the property page form, I want to open another propert page form still within the subform container area.
I don't know how to do this.
Also, I don't seem to be having luck with using Active X controls in my Access 2007 UI. So I may avoid using the tab control - UNLESS.....
Thank you for your advice.
|
|
|
|
|
Use tabs, each with an embedded subform is one way to go, or move your button onto the parent form, and update the subform based on what button is clicked if that's what you prefer...
|
|
|
|
|
I will look into the TAB control, thanks.
My initial design idea was that on the property page (that's being embedded as a subform), there would be a button that would jump to a related property page with it's set of properties. That page, also had a button that allows jumping back to related page....
Anyways, yes property pages are more intuitively handled by the TAB control.
Thanks for the advice.
|
|
|
|
|
I have a problem that how to determine which key pressed by user. I have already used 'Keys' enumerator and 'Keycode' property of 'KeyEventArgs' class. It was returned key code only. if user pressed 'A' key, it returned 65. But how can i know that user pressed 'A' or 'a'. In this case i have disabled typing in Text box. Somebody have any idea.
|
|
|
|
|
I don't know which event you're handling, but the KeyEventArgs class has a Modifiers property which will tell you if the Ctrl, Shift, or Alt keys are down at the time the key was up or down.
|
|
|
|
|
You are probably going to have to be a bit more specific in what you are trying to do.
Pasan148 wrote: if user pressed 'A' key, it returned 65
That is correct since 65 is the ASCII code for A
Pasan148 wrote: how can i know that user pressed 'A' or 'a'
If the user entered a lower case 'a' the ASCII code would be 97.
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Individuality is fine, as long as we do it together - F. Burns
Help humanity, join the CodeProject grid computing team here
|
|
|
|
|
The KeyPress event passses a KeyPressEventArgs which holds the KeyChar, i.e. the char that the user intends when he types a key or key combination that produces some text. This is the event you should use to consume text input.
The KeyDown and KeyUp events also fire for key actions that don't produce visible text, such as the control key. They hold a KeyEventArgs that has all possible information about a key and the key modifiers. These are the events you could use to filter keyboard input.
BTW: Control.ModifierKeys is always up to date, but seldom needed.
PS: is something wrong with the documentation? did Google break down? Read up on the classes you use!
|
|
|
|
|
Hi !
I have two DLLs (VB.NET converted from VB6 COM).
First of them is instantiated in the test windows executable.
Then the method of this DLL is called, that in turn has to instantiate the second
DLL and to call it's method.
On two computers it works, on the third - fails with error in subject on instantiating second assembly.
The only difference between these computers is the VS2008. On the first two it is
installed, on the third - not.
I've tried all that I could find in the Internet and that looks more or less close to my problem. With no luck.
Can somebody please help me to solve this problem and to understand - why this happens.
The issue is very urgent.
Thanks in advance.
Regards,
Gennady
My English is permanently under construction. Be patient !!
|
|
|
|
|
Error 53 is "network path not found". Is this second .DLL locally installed on the machine and does it reside in the .EXE's folder or one of the folders listed in the PATH environment variable?
|
|
|
|
|
All DLLs and .exe are in the same folder.
Thanks.
Regards,
Gennady
My English is permanently under construction. Be patient !!
|
|
|
|
|
What about framework versions? VS2008 can build against 2.0, 3.0 or 3.5 I believe.
Check which version your dlls were compiled against and check what is installed on the third machine.
|
|
|
|
|
Good point. I'll check it tomorrow morning (it's 20:45 now).
I suppose that 3.5 on the target computer is installed, but it's worth to check.
Thanks.
Regards,
Gennady
My English is permanently under construction. Be patient !!
|
|
|
|
|
I've checked it. Versions 2.0,3.0 and 3.5 are installed on all three machines.
Regards,
Gennady
My English is permanently under construction. Be patient !!
|
|
|
|
|
Hi !
Finally the problem solved. Thanks to Ben Peterson and his
A .NET assembly viewer[^] !!
Among Referenced Assemblies I've found the ADODB assembly, that is absent on the third machine.
Now all works as expected.
Thanks to everyone who tried to help me.
Regards,
Gennady
My English is permanently under construction. Be patient !!
|
|
|
|