range

Test if range exists in VBA

只谈情不闲聊 提交于 2019-11-29 06:47:00
I have a dynamically defined named range in my excel ss that grabs data out of a table based on a start date and an end date like this =OFFSET(Time!$A$1,IFERROR(MATCH(Date_Range_Start,AllDates,0)-1,MATCH(Date_Range_Start,AllDates)),1,MATCH(Date_Range_End,AllDates)-IFERROR(MATCH(Date_Range_Start,AllDates,0)-1,MATCH(Date_Range_Start,AllDates)),4) But if the date range has no data in the table, the range doesn't exists (or something, idk). How can I write code in VBA to test if this range exists or not? I have tried something like If Not Range("DateRangeData") Is Nothing Then but I get "Runtime

Declaring an integer Range with step != 1 in Ruby

℡╲_俬逩灬. 提交于 2019-11-29 05:50:27
UPDATE 2 : For posterity, this is how I've settled on doing it (thanks to Jorg's input): 100.step(2, -2) do |x| # my code end (Obviously there are plenty of ways to do this; but it sounds like this is the most "Ruby" way to do it; and that's exactly what I was after.) UPDATE : OK, so what I was looking for was step : (2..100).step(2) do |x| # my code end But it turns out that I wasn't 100% forthcoming in my original question. I actually want to iterate over this range backwards. To my surprise, a negative step isn't legal. (100..2).step(-2) do |x| # ArgumentError: step can't be negative end So

Forcing auto to be a reference type in a range for loop

微笑、不失礼 提交于 2019-11-29 05:30:14
Suppose I have foo which is a populated std::vector<double> . I need to operate on the elements of this vector. I'm motivated to write for (auto it : foo){ /*ToDo - Operate on 'it'*/ } But it appears that this will not write back to foo since it is a value type: a deep copy of the vector element has been taken. Can I give some guidance to auto to make it a reference type? Then I could operate directly on it . I suspect I'm missing some trivial syntax. A minimal auto reference The loop can be declared as follows: for (auto& it : foo) { // ^ the additional & is needed /*ToDo - Operate on 'it'*/

How to find if range is contained in an array of ranges?

六眼飞鱼酱① 提交于 2019-11-29 05:12:21
Example business_hours['monday'] = [800..1200, 1300..1700] business_hours['tuesday'] = [900..1100, 1300..1700] ... I then have a bunch of events which occupy some of these intervals, for example event = { start_at: somedatetime, end_at: somedatetime } Iterating over events from a certain date to a certain date, I create another array busy_hours['monday'] = [800..830, 1400..1415] ... Now my challenges are Creating an available_hours array that contains business_hours minus busy_hours available_hours = business_hours - busy_hours Given a certain duration say 30 minutes, find which time slots are

How to customize only with css for html5 input range slider-vertical?

僤鯓⒐⒋嵵緔 提交于 2019-11-29 05:05:40
问题 I would like to customize the look of a html5 input[range] when it's vertical. Want to avoid CSS 3 directive like transform:rotate , it complicates the UI layout then. Webkit css properties are recognised in my context, the others vendors are useless in my case. The customisation works good for the horizontal default slider, but not for the vertical one, you can look at here : jsFiddle : http://jsfiddle.net/QU5VD/1/ Otherwise, here's the code : HTML <input type="range" class="vHorizon" />

Groovy range with a 0.5 step size

 ̄綄美尐妖づ 提交于 2019-11-29 03:53:02
What's the most elgant way in Groovy to specify a range of integers and the 0.5 steps between them? e.g.: 1, 1.5, 2, 2.5, 3, 3.5, 4 Edit: To clarify: As an end result I need a range object for use in a Grails constraint. Though I suppose a list would be OK too. Best way I can see is using the step command. i.e. 1.step(4, 0.5){ print "$it "} would print out: "1 1.5 2.0 2.5 3.0 3.5" A little late, but this works too A one-liner for your above set: (2..8)*.div(2) Soo, to build on above. To test if a value val is in the range 1..n but with half values: def range = 2..(n*2).collect { return it/2.0

boost::range::join for multiple ranges

孤街醉人 提交于 2019-11-29 02:35:28
问题 I want to do the following: std::vector<int> a = {1,2,3}, b = {4,5,6}, c = {7,8,9}; for(auto&& i : join(a,b,c)) { i += 1 std::cout << i; // -> 2345678910 } I tried using boost::range::join , this works fine: auto r = boost::join(a,b); for(auto&& i : boost::join(r,c)) { i += 1; std::cout << i; // -> 2345678910 } Chaining joins, reading operations work: for(auto&& i : boost::join(boost::join(a,b),c)) std::cout << i; // -> 123456789 However , writing doesn't work: for(auto&& i : boost::join

How should I handle inclusive ranges in Python?

别说谁变了你拦得住时间么 提交于 2019-11-29 02:06:34
问题 I am working in a domain in which ranges are conventionally described inclusively. I have human-readable descriptions such as from A to B , which represent ranges that include both end points - e.g. from 2 to 4 means 2, 3, 4 . What is the best way to work with these ranges in Python code? The following code works to generate inclusive ranges of integers, but I also need to perform inclusive slice operations: def inclusive_range(start, stop, step): return range(start, (stop + 1) if step >= 0

How do I summarize array of integers as an array of ranges?

耗尽温柔 提交于 2019-11-29 02:05:45
I'd like to take input such as: [1,2,4,5,6,7,9,13] and turn it into something like the following: [[1,2],[4,7],[9,9],[13,13]] Each sub-array represents a range of integers. Functional approach using Enumerable#chunk : ranges = [1, 2, 4, 5, 6, 7, 9, 13] .enum_for(:chunk) # .chunk for Ruby >= 2.4 .with_index { |x, idx| x - idx } .map { |_diff, group| [group.first, group.last] } #=> [[1, 2], [4, 7], [9, 9], [13, 13]] How it works: once indexed, consecutive elements in the array have the same x - idx , so we use that value to chunk (grouping of consecutive items) the input array. Finally we just

How to select values within a provided index range from a List using LINQ

一个人想着一个人 提交于 2019-11-29 02:02:28
问题 I am a LINQ newbie trying to use it to acheive the following: I have a list of ints:- List<int> intList = new List<int>(new int[]{1,2,3,3,2,1}); Now, I want to compare the sum of the first three elements [index range 0-2] with the last three [index range 3-5] using LINQ. I tried the LINQ Select and Take extension methods as well as the SelectMany method, but I cannot figure out how to say something like (from p in intList where p in Take contiguous elements of intList from index x to x+n