筱红包 2015-12-08 11:36 采纳率: 0%
浏览 1373
已结题

vb Get #lngFno, 101, datLogdat 改写成c#,怎么改?

下面一段VB代码改写成C#,该怎么改?
Public Type TYPE_SYSLOG
lngPointer As Long

strDate As String
strTime As String
lngStatus As Long

lngSize As Long

strLog As String
End Type

Public Sub PubSuSysbLogPut(prmstrLog As String, prmlngStatus As Long)
Dim lngFno As Long

Dim lngPointer As Long

Dim VarNowTime As Variant

Dim datLogdat As TYPE_SYSLOG

Dim lngFsize As Long

Dim lngCnt As Long

Dim prmstrFname As String

prmstrFname="D:\log.SLG"

On Error Resume Next
lngFsize = FileLen(prmstrFname)
If Err Then
    FileCopy NEW_SYSLOG, prmstrFname
End If
On Error GoTo 0

VarNowTime = Now

On Error Resume Next
For lngCnt = 1 To 200
    Err = 0
    lngFno = FreeFile
    Open prmstrFname For Random Lock Write As #lngFno Len = Len(datLogdat)
    If Err Then
        Call Sleep(100)
    Else
        Exit For
    End If
Next lngCnt

If lngCnt > 200 Then
    If SYS_GRVL_ErrHandler_Dlog_Sw = SYS_GRVL_EHDLOG_ON Then
        MsgBox "Write Error" & Chr(&HD) & "FileName = " & prmstrFname & Chr(&HD) & "ErrorCode = " & Err
    End If
End If
On Error GoTo 0

Get #lngFno, 101, datLogdat

lngPointer = datLogdat.lngPointer + 1
If lngPointer > 100 Then lngPointer = lngPointer - 100

With datLogdat
    .lngPointer = lngPointer
    .strDate = Format(VarNowTime, "yyyy/mm/dd")
    .strTime = Format(VarNowTime, "hh:nn:ss")
    .lngStatus = prmlngStatus
    .lngSize = LenB(StrConv(prmstrLog, vbFromUnicode))
    .strLog = prmstrLog
End With

Put #lngFno, datLogdat.lngPointer, datLogdat

Put #lngFno, 1011, datLogdat

Close #lngFno

End Sub

  • 写回答

1条回答 默认 最新

  • threenewbee 2015-12-08 15:44
    关注

    最简单不动脑子的改法就是直接引用visualbasic命名空间,调用FileSystem.FileGet

    https://msdn.microsoft.com/library/dh87yy97.aspx

    如果你不会,你可以用VB写出程序,用ilspy反编译,里面可以查看对应的C#写法。

    评论

报告相同问题?

悬赏问题

  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型