In reply to janudeep3:
The genvar works only with constant value or parameter.
Here, you can use a parameter instead of a variable. Check the example program at below link.
http://www.edaplayground.com/x/7bm
In this example, parameter P is overridden from value 2 to 5. I think it may fulfill your requirement of using variable b.
BTW, what is your purpose for using a generate block?