Code:
alias find.a.person { 
  if (!$isid) { 
[color:green]    set %lastname smith
    set %firstname b
    set %street.num 1423
    set %street.name Windemere Cres
    set %apt[/color] 
    sockopen findap findaperson.canada411.ca 80 
  } 
} 
on *:sockopen:findap:{ 
  unset %match
  unset %page*
  sockwrite -n $sockname GET $+(/10649/search/Find_Person?firstname_begins_with=1&firstname=,%firstname,&name_begins_with=1&name=,%lastname,&city_zip=Sarnia&state_id=ON) HTTP/1.1 
  sockwrite -n $sockname Host: findaperson.canada411.ca $+ $crlf $+ $crlf 
} 
on *:sockread:findap:{ 
  if ($sockerr) { 
    echo -a some error occurred oh no. 
    return 
  } 
  else { 
    var %nc 
    sockread %nc
    if ($+(*,%street.num,*,%apt,*,%street.name,*) iswm %nc) {
      var %nc = $right(%nc,20)
      var %nc = $left(%nc,14)
      [color:green]echo -s did -ra Observer 15 %nc[/color]
      set %match found
    }
    elseif (*search_id* iswm %nc) && !%search_id {
      set %search_id $gettok(%nc,2,34)
      set %search_id $gettok(%search_id,-1,61)
    }
    elseif ($+(*,%lastname,*,%firstname,*,Total*) iswm %nc) {
      var %nc = $gettok(%nc,-2,32)
      var %nc = $gettok(%nc,-1,62)
      set %pages $calc($int($calc(%nc / 10)) + 1)
      set %pages $calc(%pages - 1)
    }
    elseif [color:red]([/color](</html* iswm %nc) || [color:red]([/color]%match[color:red]))[/color] {
      sockclose findap
     if [color:red](([/color]!%match[color:red])[/color] && [color:red]([/color][color:blue]%pages[/color][color:red]))[/color] {
        inc %page
        sockopen findap $+ %page findaperson.canada411.ca 80
      }
    }
  } 
}

on *:sockopen:[color:blue]$([/color]findap $+ %page[color:blue])[/color]:{
  set %limit $calc(%page * 10 + 1)
  sockwrite -n $sockname GET $+(/10649/search/Alpha_Limit?search_id=,%search_id,&old_search_type=Find_Person&sort=&alpha_limit=&lower=,%limit,) HTTP/1.1
  sockwrite -n $sockname Host: findaperson.canada411.ca $+ $crlf $+ $crlf 
}

on *:sockread:[color:blue]$([/color]findap $+ %page[color:blue])[/color]:{
  if ($sockerr) { 
    echo -a some error occurred oh no. 
    return 
  } 
  else { 
    var %nc 
    sockread %nc
    if ($+(*,%street.num,*,%apt,*,%street.name,*) iswm %nc) {
      var %nc = $right(%nc,20)
      var %nc = $left(%nc,14)
      echo -a did -ra Observer 15 %nc
      set %match found
      sockclose findap
    }
  }
  elseif [color:red]([/color](</html* iswm %nc) || [color:red]([/color]%match[color:red]))[/color] {
    sockclose findap
    if [color:red](([/color]!%match[color:red])[/color] && [color:red]([/color][color:blue]%pages[/color][color:red]))[/color] {
      inc %page
      sockopen findap $+ %page findaperson.canada411.ca 80
    }
  }
} 


Above,

GREEN = changes I made for testing purposes only. The above code will work without the dialog. Type /find.a.person and it will echo the result in the status window.

RED = Added brackets. These missing backets may or may not have affected the operation, but they are in good coding style.

BLUE = The main problems with the code. Explanation of the problems:

I changed this code: findap $+ %page to this: $(findap $+ %page) in the second SOCKOPEN and SOCKREAD events. You need the $() to evaluate the $+ and %page in an event.

And I changed this code: if !%match && !%pages to this: if ((!%match) && (%pages)) in the last elseif of each SOCKREAD event. The problem was the !%pages part. That line basically said, IF <there is no match> AND <there are no other pages> search the next page.

I hope that helps you. wink

-genius_at_work