Main Site Documentation

How to change this VB Function into C# (MF 4.1)


Hello Guys,

I am new to programming by using C#.

I try to change this function into a C# function.
However, some of the methods are not supported in C#.

For example, I can’t really find the " Asc() " [ According to MSDN : Returns the ANSI character code corresponding to the first letter in a string.

] in C#.

So I planned to use this “Convert.ToInt32()” to solve this problem, but for some reasons I can’t find this in MF4.1.

[b] Public Function WriteStr(ByRef Str As String) As Boolean

          Dim SData(Str.Length - 1) As Byte
          Dim i As Long

          WriteStr = True          
          SockErr = 0                 

             For i = 0 To Str.Length - 1
                 SData(i) = Asc(Str.Chars(i))
          Next i

          WriteStr = WriteBin(SData, Str.Length)

   End Function[/b]

Thank you for your concern.


So I planned to use this “Convert.ToInt32()” to solve this problem, but for some reasons I can’t find this in MF4.1.

You could use

Int32.Parse(String, NumberStyles);
Int32.Parse(String, IFormatProvider) ;
Int32.Parse(String, String, NumberStyles, IFormatProvider) ;

Her is the link that worth looking at,
It has both VB and VC# sample that did the same task.

Hope this help


Looks to me like UTF8Encoding.GetBytes() is what you want. Turns a string into an array of bytes.



I use sometime the following website to convert to code:

Always working :wink:

So you would get the following function:

public bool WriteStr(ref string Str)
	bool functionReturnValue = false;

	byte[] SData = new byte[Str.Length];
	long i = 0;

	functionReturnValue = true;
	SockErr = 0;

	for (i = 0; i <= Str.Length - 1; i++) {
		SData[i] = Strings.Asc(Str[i]);

	functionReturnValue = WriteBin(SData, Str.Length);
	return functionReturnValue;



public bool WriteStr(string str)
	byte[] sData = Encoding.UTF8.GetBytes(str);
	return (WriteBin(sData, sData.Length));


Stan45, how’s it going?


Hello guys,

Thank you all for the help.

I could convert that VB function into a C# function.

Sorry about replying late.

I am currently working my graduation project.

I may come up here to ask more questions regarding MF4.1 and C#.

Thank you again for the help~! ;D