I think you need to provide more info than you have already. Is those first 2 sets of codes from plugins ye? And if so I presume you're trying to get that variable into the if statement ye?
I think it all depends on how this $rep['thread'] or $rep.thread is defined. If you're trying to define it inside a plugin then it needs to be registered or pre-registered (if used in an existing template). And then the format for using the variable (outside of the if statements as if statements are different) would be more like {vb:raw $rep.thread} (for your a href link.
But yeah for the if statement you cant use the same format. You do it the same way as you would use to. So yeah what Lynne suggested should be what you need for the if statement. Though it would still need to be registered inside the plugin. There's a few good vb4 articles which shoudl help:
https://vborg.vbsupport.ru/showthread.php?t=228078
https://vborg.vbsupport.ru/showthread.php?t=231525