varying voltage output of arduino with vb 2010

So I am making a user interface on vb 2010 that allows the user to type in a textbox the PWM they want a value between 0-255. I want to be able to take the value and change it as much as i want but there seems to be a problem i am only able to send one value without needing to debug the program again. The LED I am using as the test doesn't seem to be responding with the equivalent level brightness for the PWM that i use in the textbox. I hope to be able to control this with 8 separate relays as the end goal using some sort of switch statement. Any help would be very nice my current code: VB

Imports System.IO
Imports System.IO.Ports
Imports System.Threading
Public Class Form1
    Shared _continue As Boolean
    Shared _serialPort As SerialPort
    Dim SerialPort1 As SerialPort
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        SerialPort1 = New SerialPort
        SerialPort1.PortName = "COM4"
        SerialPort1.BaudRate = 9600
        SerialPort1.DataBits = 8
        SerialPort1.Parity = Parity.None
        SerialPort1.StopBits = StopBits.One
        SerialPort1.Handshake = Handshake.None
        SerialPort1.Encoding = System.Text.Encoding.Default
        SerialPort1.Open()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim input As String
        Dim returnvalue As String

        input = TextBox1.Text
        returnvalue = input


        SerialPort1.Write(input)
        SerialPort1.Close()


        MessageBox.Show(returnvalue)

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim a As Integer
        a = SerialPort1.ReadChar()
        MessageBox.Show(a)
    End Sub
End Class

Arduino

void setup() {
  // initialize serial communication:
  Serial.begin(9600);
   // initialize the LED pins:
      int thisPin = 2;
        pinMode(thisPin, OUTPUT);
      }
   
void loop() { 
    int inByte= 0;
    int V1;
  if (Serial.available()) {
     inByte = Serial.read();
     V1 = inByte;
      analogWrite(2, V1);
  }
}
        SerialPort1.Write(input)
        SerialPort1.Close()

Send some data and then immediately reset the Arduino. No real sense in having sent the data, is there?

I dont exactly understand what you mean im sorry. The data that i am sending is going to be the the number that i plug into the text box. That number then will change the PWM of the in this case LED for now which will cause a change in brightness. When i press the button on the VB interface the LED lights up but it doesnt seem to change its pwm because no matter the value i plug in the brightness stays the same.

Opening the serial port resets the Arduino. Closing the serial port resets the Arduino, too.

Just as you open the port once, you should close the port only once, in a callback triggered by a button.

Ahhh i see what you mean i fixed it thanks Paul