如何将vb6的chr函数的ascii值转换为c#窗体 [英] how to convert ascii values of chr function of vb6 into c# windows forms

查看:100
本文介绍了如何将vb6的chr函数的ascii值转换为c#窗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好我的名字是过去3天的固定我一直在打破如何将vb6的Chr函数的ASCII值转换为c#windows窗体?

我使用的是winsock控件来自c#server形式的工具箱中的COM组件与sql server2008。

i想知道什么相当于 Chr(250) Chr(251) vb6 adodb的 Chr(104) Chr(105)与cql server2008的c#windows窗体中的Ms访问?

下面给出的是包含定时器控件中Chr值的vb6代码:

Hi my name is vishal for past 3 days i have been breaking my head on how to convert ASCII values of Chr function of vb6 into c# windows forms?
I am using winsock control which i got from COM components from toolbox in c# windows forms with sql server2008.
i was wondering what is equivalent of Chr(250),Chr(251),Chr(104) and Chr(105) of vb6 adodb with Ms access in c# windows forms with sql server2008?
I am using winsock control in c# windows forms in order to establish connection between client and server.
Given below is vb6 code containing Chr values in a timer control:

Private Sub Timer1_Timer(index As Integer)
    On Error GoTo errh
    Timer1(index).Enabled = False
    
    If (Timer1(index).Tag = "") Then   'Sync API call
        sckClient(index).SendData Chr(250) & Chr(0) & Chr(105) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(251)
    Else    'Get Last test data API call
        sckClient(index).SendData Chr(250) & Chr(0) & Chr(104) & Chr("0") & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(251)
    End If
    Timer1(index).Tag = ""
    Exit Sub
errh:
    MsgBox "syncing error:" & Err.Description, vbCritical
End Sub



其中 sckClient 是vb6中另一个winsock控件的名称。

下面是我对c#窗体中上述代码的翻译/解释


where sckClient is name of another winsock control in vb6.
Given below is my translation/interpretation of above code in c# windows forms

private void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            if (timer1.Tag == "")
            {
                sckClient.SendData(Convert.ToChar(250) +Convert.ToChar(0) +Convert.ToChar(105) +Convert.ToChar(0) +Convert.ToChar(0) +Convert.ToChar(0) +Convert.ToChar(0) +Convert.ToChar(0) +Convert.ToChar(0) +Convert.ToChar(251));
            }
            else
            {
                sckClient.SendData(Convert.ToChar(250) +Convert.ToChar(0) +Convert.ToChar(104) +Convert.ToChar(0) +Convert.ToChar(0) +Convert.ToChar(0) +Convert.ToChar(0) +Convert.ToChar(0) +Convert.ToChar(0) +Convert.ToChar(251));
            }
            timer1.Tag = "";
            return;
        }



其中 sckClient 是c#windows窗体中另一个winsock控件的名称。



我的doudt和问题是我正确解释了 Chr(250) Chr(0) Chr(105) c#中 vb6 adodb的 Chr(104) Chr(251) c#中的Ms访问 windows窗体 sql 服务器2008



我相信在vb6中,Chr(250),Chr(251),Chr(104),Chr(105)和Chr(0)指的是ASCII字符。

我的问题是如何绑定 ASCII 相当于 Chr(250) Chr(251) Chr(104) Chr c#windows窗体中的 vb6 的(105) Chr(0)



我在上面的c#代码中做错了什么?有人可以帮我吗?任何帮助/指导解决这个问题将不胜感激。


where sckClient is name of another winsock control in c# windows forms.

My doudt and question is am i interpreting correctly of Chr(250),Chr(0),Chr(105),Chr(104) and Chr(251) of vb6 adodb with Ms access in c# windows forms with sql server 2008.

I believe that in vb6 that Chr(250),Chr(251),Chr(104),Chr(105) and Chr(0) are referring to ASCII characters.
My question is how to how to bind ASCII equivalent of Chr(250),Chr(251),Chr(104),Chr(105) and Chr(0) of vb6 in c# windows forms?

Am i doing anything wrong in my c# code above? Can anyone help me please? Any help/guidance in solving of this problem would be greatly appreciated.

推荐答案

你遗漏了一件重要的事情:.NET char ,这是 ToChar()返回类型是而不是ASCII 。所有.NET都基于Unicode; ASCII仅支持作为流的编码,并且使用它需要在字符串数据的一般情况下丢失数据。



还有一件事:永远不要使用多个串联( '+'运算符)。它的结果总是字符串,字符串是不可变的。我必须解释后果吗?你整个来回复制不断增长的字符串,非常低效。通常,所有 SendData 的行都是过于临时和硬编码而不可接受的。摆脱它。如果这确实是一个常量数据,它应该写成单个字符串文字,没有任何转换。



你问题的最终答案取决于你的内容将发送字符。是的,当您将整数转换为char时,您将获得具有相应代码点值的Unicode字符。如果该值恰好在ASCII范围内(仅为0到255),则该字符将位于Unicode的ASCII子集中。您需要了解Unicode的工作原理 - 这根本不是编码,只有UTF,而不同的UTF给出了同一串代码点的不同二进制表示。 Unicode定义了代码点之间的映射,代码点被理解为从其计算机表示中抽象出来的数学整数,以及作为文化实体的字符,从其图形表示的细节中抽象出来。计算机相关的表示由UTF定义。



如果您发送数据的内容完全符合ASCII,则可能无效。所以,请参阅: http://msdn.microsoft.com/en-us/library /system.text.encoding.aspx [ ^ ]。



-SA
You are missing one important thing: .NET char, which is the ToChar() return type is not ASCII. All .NET is based on Unicode; ASCII is only supported as the encoding for streams and using it entails the loss of data in the general case of string data.

One more thing: never use multiple concatenation ('+' operator). It's result is always string, and string is immutable. Do I have to explain the consequence? You copy the growing string back and forth as a whole, very inefficient. Generally, all your lines with SendData are too ad-hoc and hard-coded to be acceptable. Get rid of it. If this is really a constant data, it should be written as a single string literal, without any "Convert".

The final answer to your question depends on what you are going to do with send characters. Yes, when you convert integer to char, you get a Unicode character with the corresponding code point value. If the value happens to be in the ASCII range (which is only 0 to 255), the character will be in the ASCII subset of Unicode. You need to learn how Unicode works — this is not encoding at all, only the UTFs are, and different UTFs gives different binary representation of the same string of code points. Unicode defines mapping between code points, which are understood as mathematical integers abstracted from their computer representations, and characters as cultural entities, abstracted from the detail of their graphical representations. Computer-related representation is defined by UTFs.

If something where you send data expects exactly ASCII, it may not work. So, please see: http://msdn.microsoft.com/en-us/library/system.text.encoding.aspx[^].

—SA


亲爱的先生Sergey Alexandrovich Kryulov

这是我的Vishal。我在C#中找到了ASCII码的解决方案。以下是我找到它的链接。



http://etutorials.org/Programming/actionscript/Appendix+A.+Unicode+Escape+Sequences+for+ Latin + 1 + Characters / [ ^ ]



首先对不起这个长链接,因为这是我第一次在此发布链接论坛。

我知道你可能已经花了很多心思去理解c#中的ASCII代码来解决我的问题。我知道你可能已经看过这个链接/页面的Unicode Escape Sequences for Latin 1 Characters。我只是想如果我在这里发布这个链接/信息它会帮助像我这样试图在c#中找到ASCII码的其他用户。我希望它能帮助别人。这就是我在这里发布此信息的原因。
Dear Mr.Sergey Alexandrovich Kryulov
It's me Vishal. I have found a solution of ASCII codes in C#. Given below is link of where i found it.

http://etutorials.org/Programming/actionscript/Appendix+A.+Unicode+Escape+Sequences+for+Latin+1+Characters/[^]

First sorry for this long link since this is my first time of posting a link in this forum.
I know that you might have taken some pains to understand ASCII codes in c# for giving solution to my problem. I know that you might have seen this link/page of Unicode Escape Sequences for Latin 1 Characters already. I just thought if i post this link/information here it would help other users like me who are trying to find ASCII codes in c#. I hope it helps others. That is the reason why i posted this information here.


这篇关于如何将vb6的chr函数的ascii值转换为c#窗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆