VB前辈们,帮我吧下面这两段vb代码翻译成C#的,小弟不胜感激,谢谢!!

hunter911x 2009-04-14 10:21:31
ps:调用了两个DLL
[DllImport("MySerial.dll" )]

Private Declare Function OpenScalePort Lib "MySerial.dll" (ByVal ComPort As String, ByVal seting As String, ByVal fangshi As String) As Long

Private Declare Function ReadInstruments Lib "MySerial.dll" (ByVal yibiao As String) As String

Private Declare Function CloseScalePort Lib "MySerial.dll" () As Long

Private Declare Function YHa9ReadCode Lib "MySerial.dll" ()

Private Declare Function LoadCellReadData Lib "MySerial.dll" (ByVal LoadCellType As String, ByVal LoadCellNumber As Long, ByVal ntime As Long) As String

Private Sub Command1_Click()

If OpenScalePort(Combo2.Text, Text1.Text, Combo3.Text) = 1 Then

If Combo1.Text = "boast" Then

Timer2.Enabled = True

Else

Timer1.Enabled = True

End If

Command1.Enabled = False

Else

MsgBox "失败!", vbInformation + vbOKOnly, "提示"

End If

End Sub



Private Sub Command2_Click()

Timer1.Enabled = False

Timer2.Enabled = False

e = CloseScalePort

Command1.Enabled = True

End Sub



Private Sub Form_Unload(Cancel As Integer)

e = CloseScalePort

End Sub


Private Sub Timer1_Timer()

Text2.Text = ReadInstruments(Combo1.Text)

End Sub



Private Sub Timer2_Timer()

DoEvents

Dim b As String



Dim LoadCellNumber As Integer



LoadCellNumber = 8



b = LoadCellReadData("boast", LoadCellNumber, 25)



Text2.Text = b



If Left(b, 1) = "S" Then



For i = 0 To LoadCellNumber - 1



Label1(i).Caption = Mid(b, 2 + i * 6, 6)



Next i



End If



End Sub



[DllImport("MyComm.dll")]


Private Declare Function OpenCom Lib "MyComm.dll" (ByVal ComPort As String, ByVal seting As String, ByVal fangshi As String) As Long

Private Declare Function YHScreen Lib "MyComm.dll" (ByVal bigscreenType as String ,ByVal b As Double) As Long

Private Declare Function CloseCom Lib "MyComm.dll" () As Long

Private Sub Command1_Click()

If OpenCom("com1", "600,n,8,1", "start") = 1 Then

Timer1.Enabled = True

End If

End Sub



Private Sub Form_Unload(Cancel As Integer)

e = CloseCom

End Sub



Private Sub Timer1_Timer()

DoEvents

e = YHScreen("abc",123456)

End Sub


最好是帮我解释下,谢谢了。。

...全文
111 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
chowyi 2009-04-14
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 kkun_3yue3 的回复:]
http://www.developerfusion.com/tools/convert/csharp-to-vb/
[/Quote]
这个怎么用
hunter911x 2009-04-14
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 Sandy945 的回复:]
http://www.developerfusion.com/tools/convert/vb-to-csharp/

http://www.codechanger.com/
[/Quote]
这个转换过来的是
CONVERSION ERROR: Code could not be converted. Details:

-- line 30 col 13: invalid EmbeddedStatement

Please check for any errors in the original code and try again.
FlyBee 2009-04-14
  • 打赏
  • 举报
回复
友情UP
zgke 2009-04-14
  • 打赏
  • 举报
回复
[DllImport("MyComm.dll")]
public static extern int OpenCom(StringBuilder ComPort, StringBuilder seting, StringBuilder fangshi);
[DllImport("MyComm.dll")]
public static extern int YHScreen(StringBuilder bigscreenType, double b);
[DllImport("MyComm.dll")]
public static extern int CloseCom();

[DllImport("MySerial.dll")]
private static extern int OpenScalePort(StringBuilder ComPort, StringBuilder seting, StringBuilder fangshi);
[DllImport("MySerial.dll")]
private static extern StringBuilder ReadInstruments(StringBuilder yibiao);
[DllImport("MySerial.dll")]
private static extern int CloseScalePort();
[DllImport("MySerial.dll")]
private static extern void YHa9ReadCode();
[DllImport("MySerial.dll")]
private static extern string LoadCellReadData(StringBuilder LoadCellType, int LoadCellNumber, int ntime);



其他的自己翻印把.都是控件的使用了
辰爸 2009-04-14
  • 打赏
  • 举报
回复
这工作量有点大啊!呵呵!~~

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧