【问题标题】:Equivalent of Open for input as - in VB.NET等效于 VB.NET 中的 Open for input as -
【发布时间】:2017-08-28 20:08:02
【问题描述】:

您好,我正在将应用程序从 vb 6 迁移到 .net,但我不知道如何将 Open PATH_IN For Input as intfile(0) 转换为 vb.NET 语法,提前感谢您的帮助对不起我的英语,这是代码:

 Open PATH_IN For Input As intFile(0) 
For intContador = 1 To intDefinicions - 1
        intFile(intContador) = FreeFile()
        Open Targetes(intContador).Out For Output As intFile(intContador)
Next
    While Not EOF(intFile(0))
        intRegs = intRegs + 1
        Line Input #intFile(0), sRegistre

    If Len(sRegistre) >= 146 Then
            sTipusFitxerEMV = Mid(sRegistre, 144, 3)
            sTipusFitxerEMV = verificarTipusFitxerHOST(sTipusFitxerEMV)
            bTipusFitxerEMV = True
            ciCVV = Mid(sRegistre, 147, 3)
            sRegistre = Left(sRegistre, 143)
        Else
            bTipusFitxerEMV = False
        End If

        sBIN = Left(sRegistre, LEN_BIN)
        bTrobat = False
        For intConta = 1 To intDefinicions - 1
            If Targetes(intConta).BIN = sBIN Then
                bTrobat = True
                sNewReg = "$" & transCaractersEspecials(sRegistre) & Chr(Hex2Dec(22)) & ComposaBanda(sRegistre, Targetes(intConta).Banda)



                If Targetes(intConta).EMV Then
                    sNewReg = sNewReg & ComposaEMV(sRegistre, Targetes(intConta).Identificacio, Targetes(intConta).PEK, Targetes(intConta).Banda, ciCVV)
                Else
                    iPosNoEMV = Len(sNewReg)
                    sNewReg = sNewReg & String2Hex(sNewReg)
                    sNewReg = Mid(sNewReg, 1, iPosNoEMV)
                End If

                If bTipusFitxerEMV And Targetes(intConta).EMV Then
                    escriureFitxerEMV sNewReg & "#END#", intConta, sTipusFitxerEMV
            Else
                    Print #intFile(intConta), sNewReg & "#END#"
            End If

            End If
        Next
        If Not bTrobat Then
            MsgBox "It do not exist" & vbLf & vbCr & sRegistre, vbCritical, "Atention"
    End If
Wend

【问题讨论】:

  • 您想转换为 .NET 的做事方式(在这种情况下,MarkusEgle 的答案是可行的方法)还是只想做最少的必要工作以使其正常工作.NET?

标签: vb.net migration vb6-migration


【解决方案1】:

对于文件读取,您需要将其更改为使用 StreamReader 对象

例如

Using streamReader As System.IO.StreamReader = System.IO.File.OpenText(PATH_IN)
    While Not streamReader.EndOfStream
        sRegistre = streamReader.ReadLine()
        ...
    End While
End Using

【讨论】:

  • 我刚刚发现:FileOpen(intFile(0), PATH_IN, OpenMode.Input) For intContador = 1 To intDefinicions - 1 intFile(intContador) = FreeFile() FileOpen(intFile(intContador), Targetes (intContador).Out, OpenMode.Output) Next ' Llegim tots els registres, While Not EOF(intFile(0)) intRegs = intRegs + 1 sRegistre = LineInput(intFile(0)) 正确吗?还是我错了?
  • 那个 FileOpen 仍在使用 intFile(0),这是一个 FileHandle 和旧样式。 MSDN How to: Read From Text Files in Visual Basic 说:“要一次读取文件一行文本,请使用 My.Computer.FileSystem 对象的 OpenTextFileReader 方法。OpenTextFileReader 方法返回一个 StreamReader 对象。您可以使用StreamReader 对象一次读取一行文件。"
猜你喜欢
  • 2012-03-28
  • 2018-10-31
  • 2012-02-04
  • 1970-01-01
  • 2011-01-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-05
相关资源
最近更新 更多