Thursday, July 3, 2008

Directv Tivo in two rooms

For the longest time I’ve struggled with what to do about a TV in our bedroom. We don’t watch a lot of TV in bed, but occasionally it’s nice to have. We currently only have 2 TVs – one in our living room with a DirecTV Tivo, and the already mentioned bedroom TV with nothing. The Bedroom TV used to have a satellite connection, but we didn’t use it enough to justify the cost.

I finally did some research online and came across the idea to take the Video-Out from the Tivo (actually the Cable-Out) and run a cable to another room. What this does is essentially give us an exact copy of what’s on one TV on the other.

The specifics of the cable hookup are like this:
  1. I had all our rooms wired for cable quite some time ago, and all the rooms run into a box in the basement
  2. I ran an additional cable from that box to the living room with the Tivo, and fished it through the same hole as the existing cable wall outlet
  3. I bought a new cable wall faceplate that has 3 cable connectors instead of the usual one (Directv Tivos use 2 cables from the Satellite dish, I just needed 1 to go back out) and connected this new cable to it. This made it look perfectly normal in the living room, no messy cables coming out of a hole in the wall
  4. Connect the new cable coming from the living room (connected to the extra Cable-out from the Tivo) to the cable going to the bedroom
  5. Now the TV upstairs sees exactly the same thing as the living room

This solved the problem of getting the TV upstairs to work, but how do I control the Tivo, change channels, etc? Simple, I used a Remote Control Extender – which I got here (link). You basically set up the ufo-looking object somewhere in the room with the Tivo, then put the transmitter in as one of the batteries for your remote. You can then operate the remote from almost anywhere in the house – it’s great. They even supply two batteries, one of which is stored (and charged) in the ufo base.

Number of Decimal places and the SubString() function

I wanted a function that could give me the number of decimal places used in a given number. I really didn’t find any elaborate solutions on the web, so I decided to write my own by converting the number into a varchar and parsing it appropriately. While building the function, I discovered a neat little feature of the SubString() function.


Normally, SQL seems to work with an index of 1. So I if asked it the position of the “J” in “Jason”, it would return 1 (one). However, I was surprised to learn that the SubString() function accepts a 0 (zero) as a parameter for where to start the sub string.


This is an effective way to trim-off the last character of a string using SubString(@var, 0, len(@var)). For example, if I want to trim off the last character of “0040”, I can use the SubString() command to trim off the last “0”.

Here is an explanation with code:

--SubString(string, start, length)

Declare @var varchar(10);

Set @var = '0040';

Select SubString(@var, 1, len(@var)) --will return ‘.0040’

Select SubString(@var, 0, len(@var)) --will return ‘.004’


Using 0 for the start point with the length of the string has the effect of trimming the last character from the string. I wasn’t expecting this behavior, but it certainly is nice!


Decimal Count Function

Here is the entire function in case you are looking for something similar. I built it for use with SQL Server 2005.


Here is my usual disclaimer:

I’m not sure if this was the best way to go about solving the problem, but it worked. I thought my code and comments might be useful for someone else who has a similar problem. This code is free and comes with no guarantees.


One more thing - apparently I lost my formatting (tabs/spaces/etc) when I pasted this code, and I'm too lazy to fix it. Should only take a couple of minutes to make it look the way you're used to seeing it.



/*

DecimalCount

7/3/2008 JMJ

Count of the number of decimal places used after decimal point.

Params:

@numString varchar(MAX) varchar representing a number, assumes 1 (one) decimal point

Returns:

int Number of places used after decimal point, 0 (zero) if no decimal point

is found in the number. Will not consider zeros on the end of the number

(i.e. .0040 will consider only .004, which will return 3).

*/

CREATE function [dbo].[DecimalCount] (

@numString varchar(MAX)

) returns int

as

begin

declare @decimalPlace bigint;

declare @subStr varchar(max);

set @decimalPlace = 0;

--find index of decimal place

set @decimalPlace = Charindex('.',@numString,0);

if (@decimalPlace > 0)

begin

-- @subStr = string without decimal (or anything left of decimal)

set @subStr = @numString;

set @subStr = Right(@numString, Len(@numString) - @decimalPlace);

-- remove any trailing zeros

while(charindex('0',@subStr,len(@subStr))) = len(@subStr)

begin

-- catch conditions for numbers like '100.' or '100.0'

if ( charindex('0',@subStr,len(@subStr)) = 0

and len(@subStr) = 0 )

begin

break;

end

--using 0 for beginning will trim the last char from string

set @subStr = SubString(@subStr, 0, len(@subStr));

end

if (len(@subStr) is null)

begin

return 0;

end

else

begin

return len(@subStr);

end

end

else

begin

--no decimal place

return 0;

end

return 0;

end