views:

16

answers:

1

My goal is the discern whether the domain has a subdomain or not by counting the number of periods there are in the domain name. If it has 2 periods, there is obviously a subdomain. I have the following crystal reports formula written in crystal syntax

local numbervar count :=0;
Local numbervar strLen := length({?domain});
local stringvar c := {?domain};
local numbervar i; 
local numbervar pos2 :=0; 
for i:=1 to strLen do
(    if Mid({?domain}, i, 1) = "." then
     (
        count := count + 1; 
        if count = 2 then (
            pos2 := i
        );

       ); 
);
if count > 1 then 
left({?domain}, pos2)
else 
left({?domain},instr({?domain}, ".")-1)

any ideas? hopefully this is something my tired eyes are just glazing over.

UPDATE: here is the weird thing that happens. If I add "+ totext(pos2)

if count > 1 then 
    left({?domain}, pos2) + totext(pos2)
    else 
    left({?domain},instr({?domain}, ".")-1)

it outputs correctly subdomain.domain with the .com removed

if i run it without the totext(pos2)

if count > 1 then 
    left({?domain}, pos2)
    else 
    left({?domain},instr({?domain}, ".")-1)

it only shows the subdomain part of subdomain.domain.com Any ideas why?

A: 

Should there be a final ; on the last line?

Alternatively, have you considered making the entire formula something like:

Left({?domain},InStrRev({?domain}, ".")-1)
Mark Bannister