How can I do a variable for meta_query?

Use a ternary operation to keep it trim.

array(
    'key' => 'rob_value', 
    'value' => $rob, 
    'compare' => ( empty( $rob ) ? '!=' : '=' )
);

Breakdown, incase you’ve not seen ternary operators before..

array(
    'key' => 'rob_value', 
    'value' => $rob, 
    'compare' => ( 
        // If
        empty( $rob ) 
        // Then
        ? '!=' 
        // Else
        : '=' 
    )
);

http://php.net/manual/en/language.operators.comparison.php

FYI: This question should ideally have been on StackOverflow, it’s more centric to general PHP(if/else/comparison) than to WordPress(you just happening to be writing code for WordPress).

All the same, hope that helps..