如何将字符串的值从一个受保护的子替换为另一个

How to replace the value of a string from one protected sub to another

我正在尝试从另一个受保护的子程序中更改受保护的子程序中的字符串值,以避免复制和粘贴代码的次数超过我想要计算的次数...我创建了一个名为 EventLogBuilder 的子程序每次用户单击页面上的按钮时,我都希望被写入,这会给我几个受保护的子项(每个按钮一个)。在 EventLogBuilder() 里面我有一个 logBuilder.WriteLine("How to put text here comes from another sub")

'Log Builder
Protected Sub EventLogBuilder()

    'Create a streamwriter for the logs...
    Dim logBuilder As StreamWriter

    'Pass the file path and name for the log files...
    logBuilder = New StreamWriter("C:\GateInterfaceLog.txt")

    'Write a test line of text...
    logBuilder.WriteLine("")

    logBuilder.Close()

End Sub

然后在我的一个按钮中,我想做一些类似...(为清楚起见删除了一些代码)

Protected Sub eastOpen_Click(sender As Object, e As EventArgs) Handles eastOpen.Click

    'Actions take place here 

从这里我想以某种方式写一些东西,这些东西会用新数据(例如 aButtonClick)写回我的 EventLogBuilder() 方法...

这可能吗?还是我走错路了?

谢谢。

您可以简单地将您想要的字符串作为方法的参数传递,如下所示:

Protected Sub EventLogBuilder(ByVal LogString as String)

    'Create a streamwriter for the logs...
    Dim logBuilder As StreamWriter

    'Pass the file path and name for the log files...
    logBuilder = New StreamWriter("C:\GateInterfaceLog.txt")

    'Write a test line of text...
    logBuilder.WriteLine(LogString)

    logBuilder.Close()

End Sub