Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using MSComm to import text strings

Status
Not open for further replies.

PureSoft

Programmer
Aug 12, 2002
24
0
0
GB
Hi,

I have written some code which seems to trip up, can anyone tell me why this deosn't work?

input_string = MSComm1.Input
input_string_holder_array = Split(input_string, ",")
Label1.Caption = input_string_holder_array(2)

It seems that when the array value is passed over to Label1.Caption is causes a 'Subscript out of range' error. Do I need to do some sort of formatting of that string?

Your advice would be greatly apreciated.

Philip.
 
can you provide an example of the input string? It seems like when you performing the split there is nothing in input_string_holder_array(2), the number of values produced by the split is less than 2.

Below is an example:

inputstring = "John,Mark"

If I perform split
inputstringarray = Split(inputstring,",")
and then try to get inputstringarray(2), i will get an error. The only values for the array are inputstringarray(0), and inputstringarray(1). The array starts at 0.
 
You are refering to the third element (input_string_holder_array(2)); do you actually have 3 elements in this 'array'?
 
How about a little error checking?

[green]input_string = input_string+MSComm1.Input
input_string_holder_array = Split(input_string, ",")
if ubound(input_string_holder_array())>1 then
Label1.Caption = input_string_holder_array(2)
input_string=""
endif[/green]

Good luck
 
Guys,

Thank you for your replies. The input string is about 50 characters long. I'm trying to interface a PIC microcontroller. I have comms going from the PC to the PIC, but not the other way around. I have done some further tests and it appears to be an issue with my string input not being detected by the VB app. so I'm looking into that now.

Thanks again for your input.

Philip.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top