首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从VBA到vb网的翻译程序

从VBA到vb网的翻译程序
EN

Stack Overflow用户
提问于 2015-08-31 09:41:06
回答 1查看 195关注 0票数 0

通常,我将此工作程序作为Excel中的宏,并希望将其解压缩为一个按钮,简单的windows应用程序。是否有一种简单的方法来做到这一点,或者更好地尝试识别VBA和VB.Net之间的差异,并尝试从头开始编写它?

代码语言:javascript
复制
Sub Zapisywanie_txt_Biesse_WR()

    Dim TextFile As Integer
    Dim FilePath As String
    Dim FileContent As String, strContent() As String
    Dim NewName As String
    Dim StrFile As String
    Dim FileNum As String
    Dim Last_Dot As Long
    Dim posStart As Integer
    Dim posLength As Integer
    Dim i As Integer
    Dim j As Integer
    Dim LPX As Integer
    Dim MyTxtFile

    On Error GoTo ErrorHandle

    'Zmienic domyslna lokacje na lokacje aplikacji
    'ChDir "C:\Users\marcin.perz\Desktop\makro zmieniajace pliki"
    ChDir ActiveWorkbook.Path

    'Spytac sie o plik do przerobienia
    FilePath = Application.GetOpenFilename("Text Files (*.txt),*.txt")

    'Nastepny wolny numer dla txt
    TextFile = FreeFile

    'Otworzenie txt w trybie odczytu
    Open FilePath For Input As TextFile

    'Zapisanie zawartosci pliku do pamieci
    FileContent = Input(LOF(TextFile), TextFile)

    'Zamkniecie pliku
    Close TextFile

    'Znajdz/zamien prcedury
    FileContent = Replace(FileContent, "campoD0=LABL,A,4,4,NULL,0,0", "campoD0=LABL,A,4,4,NULL,0,0")
    FileContent = Replace(FileContent, "campoD1=PROG,A,256,8,NULL,0,2", "campoD1=PROG,A,256,8,NULL,0,2")
    FileContent = Replace(FileContent, "campoD2=QNTA,U,4,4,NULL,0,0", "campoD2=QNTA,U,4,4,NULL,0,0")
    FileContent = Replace(FileContent, "campoD3=CONT,U,4,4,NULL,0,0", "campoD3=CONT,U,4,4,NULL,0,0")
    FileContent = Replace(FileContent, "campoD4=COMM,A,768,80,NULL,0,0", "campoD4=COMM,A,768,80,NULL,0,0")
    FileContent = Replace(FileContent, "ORDRE", "$ ORDRE")
    FileContent = Replace(FileContent, "," & vbCrLf, " $, " & vbCrLf)

    'Nastepny wolny numer dla txt
    TextFile = FreeFile

    'Nadanie nowej nazwy lokazcji
    Last_Dot = InStrRev(FilePath, ".")
    NewName = Left$(FilePath, Last_Dot - 1) & "_rover35" & Mid$(FilePath, Last_Dot)
    FilePath = NewName

    'Otworzenie txt w trybie zapisu
    Open FilePath For Output As TextFile

    'Zapisanie zmienionej zawartosci do pliku
    Print #TextFile, FileContent

    'Zakmniecie pliku
    Close TextFile

    '~~> Podzielenie pliku na linie binarnie
    Open FilePath For Binary As #1
    FileContent = Space$(LOF(1))
    Get #1, , FileContent
    Close #1
    strContent() = Split(FileContent, vbCrLf)

    ' Here i will do some conditional replecments split text into an array by lines etc.

    'Polaczenie pliku
    FileContent = Join(strContent, vbCrLf)

    'Otworzenie txt w trybie zapisu
    Open FilePath For Output As TextFile

    'Zapisanie zmienionej zawartosci do pliku
    Print #TextFile, FileContent

    'Zakmniecie pliku
    Close TextFile

    MyTxtFile = Shell("C:\WINDOWS\notepad.exe " & FilePath, 1)

    'etykieta wyjscia z programu
BeforeExit:
    'wyjscie z programu
    Exit Sub
    'etykieta radzenia sobie z bledami
ErrorHandle:
    MsgBox Err.Description
    'skierowanie do wyjscia z programu
    Resume BeforeExit
    'koniec makra
End Sub
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-08-31 09:47:43

您可以尝试以下方法之一:

  1. 将代码复制到窗体中,并在运行时更正错误
  2. 安装VB6并将代码粘贴到项目中(因为VBA是VB6代码)。然后尝试在VB6中打开VB.NET项目,此时它将为您执行升级过程

祝好运。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32308241

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档