reading data with VB6

hi all
i am a beginner to use vb 6 with Arduino
i have a problem to read the data from Arduino and use it to change a picture in vb 6 form

Arduino send to vb program that the output is hi or low then vb program receive this data and
change visibility of the photo true or false ( the name of the picture is onn and off )
it already work but it is changed as you see

can you help me to modify my code to get this result stable

my Arduino code is

int inPin = 2;
int led1 = 6;
int val = 0;
String x = "hi";
String y = "low";
void setup() {
Serial.begin(9600);
pinMode(inPin,INPUT);
pinMode(led1,OUTPUT);
}

void loop()
{
val = digitalRead(inPin);
//Serial.println(val);

delay(100);
if ( val > 0 )
{
digitalWrite(led1, HIGH);
delay(1000);
Serial.print ("");
Serial.println (x);
}
else
{
digitalWrite(led1, LOW);
delay(1000);
Serial.print ("");
Serial.println (y);
}
}

my vb code is

Dim str As String
Dim x As Integer
Private Sub Form_Load()
With MSComm1
.CommPort = 3
.Settings = "9600,N,8,1"
.Handshaking = comRTS
.RTSEnable = True
.DTREnable = True
.RThreshold = 1
.SThreshold = 1
.InputMode = comInputModeText
.InputLen = 0
.PortOpen = True
End With
End Sub

Private Sub Timer1_Timer()

str = MSComm1.Input

Text2.Text = str

If str = hi Then
x = 1
Else
x = 0
End If

If (x = 1) Then
Text1.Text = Val(x)
onn.Visible = True
off.Visible = False
delay = 1000
Else
Text1.Text = Val(x)
onn.Visible = False
off.Visible = True
delay = 1000

End If
End Sub

thanks my frinds

Have you looked at PLX-DAX? Its a way to read data from the Arduino USB into an Excel spreadsheet. The neat thing is you can open up the macro, in the spreadsheet, and see how the author is reading data from the Arduino, through the USB, and into the spreadsheet.

I believe you must put
If str = “hi”

Otherwise hi is considered like a variable and by default it is empty.
You can also declare hi as constant string and set it to “hi”

Sure, I'll do this paid work. I accept payment by paypal.

Duplicate topics merged

Why did you start a second one ?

UKHeliBob:
Duplicate topics merged

Why did you start a second one ?

And another one merged

Why did you start a third one ?

Your newly posted duplicate topic has been deleted

Why did you post yet another one ?

@amr_f50

Other post/duplicate DELETED
Please do NOT cross post / duplicate as it wastes peoples time and efforts to have more than one post for a single topic.

Continued cross posting could result in a time out from the forum.

Could you also take a few moments to Learn How To Use The Forum.

Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

sorry for this error

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.