Here's what I would do in PHP, it's automated..

PHP Code:

```
``````
for($i = 1000; $i < 10000; $i++)
```

{

$first = strpos($i, 0, 2);

$last = strpos($i, 2, 2);

$sum = $first + $last;

$result = $sum * $sum;

if ($result == $i)

{

"The number ".$i." is magic.\n";

}

}

If it's possible in VB, run a for loop from numbers 1000-9999, and then just do the math, and then use a if statement to see if the result is equal to the number inputted via the for loop, if it is equal, then output it's magic, and then if not, don't do anything (otherwise it will use more resources and it would be hard to see which are magic). Hope this helps.

Also, for the second this is what I would do in PHP:

PHP Code:

```
``````
for($i = 1; $i < 1000; $i++)
```

{

$first_digits = strpos($i, 0, strlen($i) - 1); // take of last digit

if(($i % $first_digits) == 0) // modulus operation (operation gives remainder after dividing first number with second number)

{

echo $i." is a magic number"; // echo number

}

}

Just run a for loop from 1-1000, and then take off the last digit. Then, if POSSIBLE in VB, use modulus to see if there is a remainder. If VB doesn't have modulus, then you can divide the number from the for loop by the number after the last digit is taken off, and then check for a '.' in the string to see if its a decimal, if not then ouput the number as magic. Again, hope this helps.