Problem reading pwm value sent from GUI (VB.net)

I recently developed a wi-fi controlled 4 wheel car that uses a router and an ethernet shield instead of the x-bee module. I can control the forward, backward, left, and right controls from the GUI by sending characters like : ‘A’ for forward, ‘B’ for backward etc. What I also want to do now is send a numeric value (0~255) from my GUI through a scrollbar control into the arduino via the serial protocol. I am sending a numeric value from my GUI but I can’t get to set the pwm in my arduino according to that value. Why is this happening? Is my syntax wrong in the arduino sketch?

void setup(){

pinMode(up,OUTPUT);
pinMode(down,OUTPUT);
pinMode(left,OUTPUT);
pinMode(right,OUTPUT);

Serial.begin(9600);
}

int pwm = 0;

void loop(){
int val;

if (Serial.available()){
while (Serial.available()>0){
val = Serial.read();

if (val>=0){ //i want to set pwm for motor driver according to the value (0~255) I sent from GUI
pwm = val;}
else if(val==‘0’){
pwm = 0;
}

if(val==‘A’){ // I am using a character ‘A’ so that pwm and navigation instructions are not messed up . THIS PART IS WORKING FINE EXCEPT FOR PWM.
analogWrite(up,pwm);analogWrite(down,0);} //motor driver input1 and input 2
else if(val==‘0’){
analogWrite(up,0);analogWrite(down,0); //grounding both inputs for braking
}

if (val==‘B’){
analogWrite(up,0);analogWrite(down,pwm);}
else if(val==‘0’){
analogWrite(up,0);analogWrite(down,0);
}

What I also want to do now is send a numeric value (0~255) from my GUI through a scrollbar control into the arduino via the serial protocol.

How are you doing that?

I am sending a numeric value from my GUI

Well, lovely. As a string? Or, as binary data?

but I can't get to set the pwm in my arduino according to that value.

Perhaps because you are sending a string and expecting binary data. Send what you expect, or expect what you send.

I am sending scrollbar values as binary in the range 0-255. No problem on that part of the GUI!

I am sending scrollbar values as binary in the range 0-255. No problem on that part of the GUI!

    if (val>=0){     //i want to set pwm for motor driver according to the value (0~255) I sent from GUI
      pwm = val;}
        else if(val=='0'){
          pwm = 0;
        }

Under what conditions will the else clause ever be evaluated?

You need to post your PC code.