Try this:

vb Code:
  1. Public Class Form1
  2.  
  3.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  4.        
  5.         Dim Isprime As Integer
  6.         Dim str As String
  7.         Dim m As Integer
  8.         Dim n As Integer
  9.         Dim TestLimit As String
  10.         Dim TestPrime As String
  11.         Dim TestNum As String
  12.  
  13.  
  14.         str = ""
  15.         m = InputBox("Enter Upper limit")
  16.         n = InputBox("Enter lower limit")
  17.         If (n > 50) Then
  18.             MsgBox("outside range")
  19.             Exit Sub
  20.  
  21.         End If
  22.  
  23.         '  
  24.         ' Eliminate even numbers
  25.         If TestPrime Mod 2 = 0 Then Exit Sub
  26.         '   Loop through ODD numbers starting with 3
  27.         TestNum = 3
  28.         TestLimit = TestPrime
  29.         Do While TestLimit > TestNum
  30.           for x= TestNum to  TestLimit step 2
  31.             If TestPrime Mod TestNum = 0 Then
  32.                 '   Uncomment this if you really want to know
  33.                 '   MsgBox "Divisible by " & TestNum  
  34.  
  35.                 Exit Sub
  36.             End If
  37.  
  38.             '   There's logic to this.  Think about it.
  39.             TestLimit = TestPrime \ TestNum
  40.  
  41.             '   Remember, we only bother to check odd numbers
  42.             TestNum = TestNum + 2
  43.            if prime then list.additem x
  44.              next x
  45.         Loop
  46.  
  47.         '   If we made it through the loop, the number is a prime.
  48.  
  49.         Isprime = True
  50.  
  51.  
  52.     End Sub

I have requested the thread moved since you are using vb.net not vb6. Something such as that although, I haven't tested it so I can't be sure.