char2num or str2num

Hi every one, i have a simple question about converting ascii to number. Here, I have some VB program that convert Ascii character (I think) to number:

ibrd ud, recvbuffer, 4 lsb2& = Asc(Left(recvbuffer, 1)) lsb1& = Asc(Right(Left(recvbuffer, 2), 1)) msb2& = Asc(Right(Left(recvbuffer, 3), 1)) msb1& = Asc(Right(Left(recvbuffer, 4), 1))

In Igor, how it should be write?
like this:

NI4882 ibrd={ud,4}
recvbuffer=S_value
lsb1=char2num (Rdbuffer[0])
lsb2=char2num (Rdbuffer[1])
msb1=char2num (Rdbuffer[2])
msb2=char2num (Rdbuffer[3])

or
NI4882 ibrd={ud,4}
recvbuffer=S_value
lsb1=str2num (Rdbuffer[0])
lsb2=str2num (Rdbuffer[1])
msb1=str2num (Rdbuffer[2])
msb2=str2num (Rdbuffer[3])



When I tried to print the values by using str2num or num2char I just got 'NaN' for each of the value instead of '0'

You are not assigning anything to Rdbuffers. That's why you're getting NaNs. You could discover this by putting:
Print Rdbuffers

in your function or by using the Igor debugger:
DisplayHelpTopic "The Debugger"


char2num returns the numeric code for a single character. str2num converts a string containing text formatted as a number to a numeric value. My guess is that you want the numeric value of a single byte. For that you should use char2num.

I don't think this your situation, but, if S_value contains a number in ASCII format, you can do this:
Variable val = str2num(S_value)

There is a mistake in my program. I forgot to change the Rdbuffer to recvbuffer. The actual program is suppose to be like this:

NI4882 ibrd={ud,4}
recvbuffer=S_value
lsb1=char2num (recvbuffer[0])
lsb2=char2num (recvbuffer[1])
msb1=char2num (recvbuffer[2])
msb2=char2num (recvbuffer[3])