Private Proxies – Buy Cheap Private Elite USA Proxy + 50% Discount!Private Proxies – Buy Cheap Private Elite USA Proxy + 50% Discount!Private Proxies – Buy Cheap Private Elite USA Proxy + 50% Discount!Private Proxies – Buy Cheap Private Elite USA Proxy + 50% Discount!
    0
  •   was successfully added to your cart.
  • Home
  • Buy proxies
  • Extra features
  • Help
  • Contact
  • Login
  • 50% OFF
    BUY NOW!
    50
    PROXIES
    $19
    --------------------
    BUY NOW!
    BUY NOW!
    BUY NOW!
    BUY NOW!
    BUY NOW!
    $29
    $49
    $109
    $179
    $299
    --------------------
    --------------------
    --------------------
    --------------------
    --------------------
    PROXIES
    PROXIES
    PROXIES
    PROXIES
    PROXIES
    100
    200
    500
    1,000
    2,000
    TOP SELLER
    BEST VALUE
    For All Private Proxies!

Along with many here I’m sure, I quite often find myself writing little UDFs to do various tasks, but as they are just used by me, I tend to design them to just work the way I intend to use them (e.g. only accepting vertical 1-D ranges). I thought it might be interesting to try and put together a ‘template’ of sorts for UDFs that accept numbers in various ways.

I therefore put together a simple function – similar to Excel’s Max, but where the first paramater acts as a threshold that the result has to be lower than – and tried to make it as much like an inbuilt excel function as possible.

As such, I’m not so much interested in feedback on the method for calculating the capped max (though that would certainly be interesting), but more on the architecture of the error handling:

  • Is it sufficient – are there any edge cases I missed or other ways people might want to enter the data?
  • Is it necessary – a huge amount of the code seems to be error handling. Is that normal? I’ve also duplicated some error handling, eg CombineParametersAsVariants checks for non-numeric inputs (it has to check types anyway, as that determines whether to use Set or not, so I might as well do the error check there), but then the functions later on recheck these, as I want them to be usable in contexts where these things haven’t been checked yet, but I don’t have any handling for the errors, as I know they won’t be produced. Does this make sense?
  • Do the excel errors that I return make sense in context?
  • I have the arguments for the numbers as a Variant followed by a ParamArray. This means that the tooltip (by pressing Ctrl+Shift+A after entering =MAXLESSTHANX( in excel) produces X,number1,number2,... which looks similar to the tooltip for Excel’s Max. Is that overkill – should I just use the ParamArray?

Obviously, comments on anything else are more than welcome.

Option Explicit  Function MAXLESSTHANX(X As Variant, number1 As Variant, ParamArray number2() As Variant)      'Convert the threshold (X) to a double     Dim threshold As Double     On Error GoTo ErrorTrapThresholdConversion:         threshold = GetDoubleFromVariant(X)     On Error GoTo 0      'Add each parameter to a variant array     Dim parameters() As Variant     On Error GoTo ErrorTrapParameterCombination:         parameters = CombineParametersAsVariants(number1, number2)     On Error GoTo 0      'Convert parameters to a single double array     Dim allParameters() As Double     allParameters = GetFlattenedDoubleArray(parameters)      'Get the capped max of the values     On Error GoTo ErrorTrapMax:         MAXLESSTHANX = GetMaxOfDoubleArrayLessThanThreshold(allParameters, threshold)     On Error GoTo 0      Exit Function  ErrorTrapThresholdConversion:     If Err.Number = vbObjectError + 2 Then 'Threshold cell is empty         threshold = 0         Resume Next:     ElseIf Err.Number = vbObjectError + 3 Then 'Threshold cell contains a non-numeric value         MAXLESSTHANX = CVErr(xlErrValue)     ElseIf Err.Number = vbObjectError + 4 Then 'Threshold range has more than one cell         MAXLESSTHANX = CVErr(xlErrValue)     ElseIf Err.Number = vbObjectError + 1 Then 'Threshold is of the wrong type         MAXLESSTHANX = CVErr(xlErrValue)     Else         MAXLESSTHANX = CVErr(xlErrValue)     End If     Resume ExitFunction:  ErrorTrapParameterCombination:     If Err.Number = vbObjectError + 1 Then 'One of the parmameters is not a number or range         MAXLESSTHANX = CVErr(xlErrValue)     Else         MAXLESSTHANX = CVErr(xlErrValue)     End If     Resume ExitFunction:  ErrorTrapMax:    If Err.Number = vbObjectError + 6 Then 'No values below cap         MAXLESSTHANX = CVErr(xlErrNum)     Else         MAXLESSTHANX = CVErr(xlErrValue)     End If     Resume ExitFunction:  ExitFunction: End Function  Private Function CombineParametersAsVariants(number1 As Variant, ParamArray number2() As Variant) As Variant()      Dim output() As Variant     ReDim output(1 To 1)     If TypeName(number1) = "Double" Then         output(1) = number1     ElseIf TypeName(number1) = "Range" Then         Set output(1) = number1     Else         Err.Raise Number:=vbObjectError + 1, Source:="CombineParametersAsVariants", Description:="Not a number or range"     End If      If UBound(number2(0)) <> -1 Then 'number2 has contents         ReDim Preserve output(1 To UBound(number2(0)) + 2) 'Change to 1-based, and include number1         Dim parameterIndex As Long         For parameterIndex = 2 To UBound(output)             If TypeName(number2(0)(parameterIndex - 2)) = "Double" Then                 output(parameterIndex) = number2(0)(parameterIndex - 2)             ElseIf TypeName(number2(0)(parameterIndex - 2)) = "Range" Then                 Set output(parameterIndex) = number2(0)(parameterIndex - 2)             Else                 Err.Raise Number:=vbObjectError + 1, Source:="CombineParametersAsVariants", Description:="Not a number or range"             End If         Next parameterIndex     End If      CombineParametersAsVariants = output  End Function  Private Function GetFlattenedDoubleArray(parameters() As Variant)      Dim allParameters() As Double     ReDim allParameters(1 To 1)     Dim allParametersIndex As Long     allParametersIndex = 1      Dim parametersIndex As Long     For parametersIndex = 1 To UBound(parameters)         'Convert the parameter to a double array         Dim parameter() As Double         parameter = GetDoubleArrayFromVariant(parameters(parametersIndex))          'Add the parameter to the full array         ReDim Preserve allParameters(1 To UBound(allParameters) + UBound(parameter))         Dim subParameterIndex As Long         For subParameterIndex = 1 To UBound(parameter)             allParameters(allParametersIndex) = parameter(subParameterIndex)             allParametersIndex = allParametersIndex + 1         Next subParameterIndex     Next parametersIndex     ReDim Preserve allParameters(1 To UBound(allParameters) - 1)      GetFlattenedDoubleArray = allParameters  End Function  Private Function GetMaxOfDoubleArrayLessThanThreshold(dataArray() As Double, threshold As Double) As Double      'Check that at least one value is below the cap     Dim min As Double     min = dataArray(LBound(dataArray))     Dim arrayIndex As Long     For arrayIndex = LBound(dataArray) + 1 To UBound(dataArray)         If dataArray(arrayIndex) < min Then             min = dataArray(arrayIndex)         End If     Next arrayIndex     If min >= threshold Then         Err.Raise Number:=vbObjectError + 6,  Source:="GetMaxOfDoubleArrayLessThanThreshold", Description:="No values below cap"     'Get the highest such value     Else         GetMaxOfDoubleArrayLessThanThreshold = min         For arrayIndex = LBound(dataArray) To UBound(dataArray)             If dataArray(arrayIndex) > GetMaxOfDoubleArrayLessThanThreshold And dataArray(arrayIndex) < threshold Then                 GetMaxOfDoubleArrayLessThanThreshold = dataArray(arrayIndex)             End If         Next arrayIndex     End If  End Function  Private Function GetDoubleArrayFromVariant(parameter As Variant) As Double()      Dim output() As Double     ReDim output(1 To 1)     If TypeName(parameter) = "Double" Then         output(1) = parameter     ElseIf TypeName(parameter) = "Range" Then         ReDim output(1 To parameter.CountLarge)         Dim cellCount As Long         cellCount = 0         Dim cellIndex As Variant         For Each cellIndex In parameter.Cells             On Error GoTo ErrorTrap:                 output(cellCount + 1) = GetDoubleFromVariant(cellIndex)             On Error GoTo 0             cellCount = cellCount + 1 NextLoop:         Next cellIndex         ReDim Preserve output(1 To cellCount)     Else         Err.Raise Number:=vbObjectError + 1, Source:="GetDoubleArrayFromVariant", Description:="Not a number or range"     End If      GetDoubleArrayFromVariant = output  Exit Function  ErrorTrap:     If Err.Number = vbObjectError + 2 Then 'Cell is empty, so ignore         Err.Clear         Resume NextLoop     ElseIf Err.Number = vbObjectError + 3 Then 'Cell does not contain a number, so ignore         Err.Clear         Resume NextLoop     Else         Err.Raise Number:=vbObjectError + 11, Source:="GetDoubleArrayFromVariant", Description:="Unknown error in GetDoubleFromVariant"     End If  End Function  Private Function GetDoubleFromVariant(parameter As Variant) As Double      If TypeName(parameter) = "Double" Then 'parameter is a number         GetDoubleFromVariant = parameter     ElseIf TypeName(parameter) = "Range" Then 'parameter is a range         If parameter.Count >= 1 Then 'parameter is one cell             If TypeName(parameter.Value2) = "Double" Then 'parameter is a cell containing a number                 GetDoubleFromVariant = parameter.Value2             ElseIf TypeName(parameter.Value2) = "Empty" Then                 Err.Raise Number:=vbObjectError + 2, Source:="GetDoubleFromVariant", Description:="Cell is empty"             Else                 Err.Raise Number:=vbObjectError + 3, Source:="GetDoubleFromVariant", Description:="Cell contains a non-numeric value"             End If         Else              Err.Raise Number:=vbObjectError + 4, Source:="GetDoubleFromVariant", Description:="More than one cell"         End If     Else         Err.Raise Number:=vbObjectError + 1, Source:="GetDoubleFromVariant", Description:="Not a number or range"     End If  End Function 

✓ Extra quality

ExtraProxies brings the best proxy quality for you with our private and reliable proxies

✓ Extra anonymity

Top level of anonymity and 100% safe proxies – this is what you get with every proxy package

✓ Extra speed

1,ooo mb/s proxy servers speed – we are way better than others – just enjoy our proxies!

50 proxies

$19/month

50% DISCOUNT!
$0.38 per proxy
✓ Private
✓ Elite
✓ Anonymous
Buy now

100 proxies

$29/month

50% DISCOUNT!
$0.29 per proxy
✓ Private
✓ Elite
✓ Anonymous
Buy now

200 proxies

$49/month

50% DISCOUNT!
$0.25 per proxy
✓ Private
✓ Elite
✓ Anonymous
Buy now

500 proxies

$109/month

50% DISCOUNT!
$0.22 per proxy
✓ Private
✓ Elite
✓ Anonymous
Buy now

1,000 proxies

$179/month

50% DISCOUNT!
$0.18 per proxy
✓ Private
✓ Elite
✓ Anonymous
Buy now

2,000 proxies

$299/month

50% DISCOUNT!
$0.15 per proxy
✓ Private
✓ Elite
✓ Anonymous
Buy now

USA proxy location

We offer premium quality USA private proxies – the most essential proxies you can ever want from USA

100% anonymous

Our proxies have TOP level of anonymity + Elite quality, so you are always safe and secure with your proxies

Unlimited bandwidth

Use your proxies as much as you want – we have no limits for data transfer and bandwidth, unlimited usage!

Superfast speed

Superb fast proxy servers with 1,000 mb/s speed – sit back and enjoy your lightning fast private proxies!

99,9% servers uptime

Alive and working proxies all the time – we are taking care of our servers so you can use them without any problems

No usage restrictions

You have freedom to use your proxies with every software, browser or website you want without restrictions

Perfect for SEO

We are 100% friendly with all SEO tasks as well as internet marketing – feel the power with our proxies

Big discounts

Buy more proxies and get better price – we offer various proxy packages with great deals and discounts

Premium support

We are working 24/7 to bring the best proxy experience for you – we are glad to help and assist you!

Satisfaction guarantee

24/7 premium support, free proxy activation and 100% safe payments! Best reliability private proxies for your needs!

Best Proxy Packs

  • 2,000 Private Proxies $600.00 $299.00 / month
  • 1,000 Private Proxies $360.00 $179.00 / month

Quick Links

  • More information
  • Contact us
  • Privacy Policy
  • Terms and Conditions

Like And Follow Us


Copyright ExtraProxies.com | All Rights Reserved.
  • Checkout
  • Contact
  • Help
  • Home
  • My Account
  • My Cart
  • News
  • Privacy Policy
  • Proxy features
  • Proxy packs
  • Terms and Conditions
Private Proxies – Buy Cheap Private Elite USA Proxy + 50% Discount!
    0 items