MSComm String Data Out Help

Status
Not open for further replies.

Suraj143

Active Member
Hi, I can send a single character when I press a command button in VB.

Here is the code

Code:
Private Sub Command1_Click()
MSComm1.Output = "A" + Chr(13)
End Sub

Now I need to send a string which is typed in the textbox when I pressed the command button. Can anybody help me out to do this?

Thanks
 
Try,
Code:
Private Sub Command1_Click()
    MSComm1.Output = Text1.Text & vbCr
End Sub

Mike.
 
Hi Mike thats what I was looking, I couldn't find this on the net.

Ahh this will send a string what I type in the Text1 box.

I'll try to add your code.Can I change the character length also,I mean character length (Word) must not exceed 10 characters.Its never mind I'll try to solve that out.

Thanks Mike
 
You could do,
Code:
Private Sub Command1_Click()
Dim Temp As String
    Temp = Text1.Text
    If Len(Temp) > 10 Then Temp = Left(Temp, 10)
    MSComm1.Output = Temp & vbCr
End Sub

Mike.
 
Hi Mike now I got it.Thanks for the superb code.All I understand except the Left(Temp, 10) part.Does it move left when it receive 11 characters?So every time it is a below 10 letter word.
 
Left just returns a number of characters from the beginning of the string and so, Temp=Left("Hello World",5) would result in Temp containing "Hello".

Mike.
 
Left just returns a number of characters from the beginning of the string and so, Temp=Left("Hello World",5) would result in Temp containing "Hello".

Mike.

Totally understood.I got everything from you that I was looking everywhere.

Thanks Again.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…