Re: Function CrossOver in VB.net

Tech-Archive recommends: Fix windows errors by optimizing your registry



The description you have provided is inconsistent with the example. The way I read it, I would have thought you were looking for:
1.6542 1.6540 +
1.6541 1.6540 + No crossover - false
1.654 1.6540 0 Crossover - true
1.6539 1.6540 - No Ccossover - false

Or, maybe you have given us the data backwards (as per your last comment). So the data really is:

1.6539 1.6540 -
1.654 1.6540 0 (assume - = 0) - false
1.6541 1.6540 + Crossover - true
1.6542 1.6540 + No Crossover

If the last one is the actual case, then the function simply needs to invert the arrays, scan the number pairs calculating the test condition, and return whenever the indicator changes from 0 to +

Private Function ArrayTest(ByVal Array1() As Double, ByVal Array2() As Double) As Boolean()
'Test each array pair and return true on change from 0 to +
Array1.Reverse()
Array2.Reverse()
'Function will fail if Array2 is shorter than Array1
Dim Result(Array1.Length - 1) As Boolean
Dim C As Integer = 0
Dim C1 As Integer
For I As Integer = 1 To Array1.Length - 1
C1 = Math.Sign(Array1(I) - Array2(I))
If C = 0 And C1 = +1 Then
Result(I) = True
Else
Result(I) = False
End If
C = C1
Next I
Result.Reverse()
Return Result
End Function

"Gum" <gum@xxxxxxxxxxxxx> wrote in message news:784A5C62-F3A9-4D0E-8589-F116383695FB@xxxxxxxxxxxxxxxx
I would like to create a function that returns true whenever Array1 crosses
over Array2. For example:
Array1 Array2
1.6542 1.6540 False
1.6541 1.6540 True
1.654 1.6540 False
1.6539 1.6540 False
Thus given any pair of numbers (Array1,Array2), whenever Array1 crosses over
Array2 (Array1>Array2) that instance is true, but it is NOT TRUE for any
other instance in which Array1>Array2 (see above table where the last record
is the first - desc order).


.



Relevant Pages

  • RE: How to exclude a list of number from another list?
    ... 'Assumes array1 and array2 are allready ... Dim TempArray() As Boolean ... > I've two lists of data in array in VBA. ...
    (microsoft.public.excel.programming)
  • Re: Arrays please help me
    ... I have two arrays. ... array2 contains 6 elements ... I need to assign the left over 4 elements of array1 into new array. ... Dim array3 ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Arrays Problem
    ... If the 2 arrays are the same size ... If they aren't the same size you need to copy the elements of array1 ... individually into array2. ... Dim Second() As String ...
    (comp.lang.basic.visual.misc)
  • Re: Creating a Table of a Type which contains a nested table
    ... array1 t_array_va, ... array2 t_array_va ... Syntax and documentation are available on ... SQL> create or replace type t_complex_type as object ...
    (comp.databases.oracle.server)
  • Re: exception question,
    ... Suppose the constructor for Effect throws an exception. ... will Array1 and Array2 be deleted? ... What's the type of Array1? ...
    (microsoft.public.dotnet.languages.vc)