我有一些由 IDE 编写的代码,它们使文本框成为 Subs。我需要将变量“printString”的值从一个 Sub 保留到另一个。我的搜索似乎表明第一个 sub 需要变成一个函数,但是当我这样做时它会中断。
Private Sub txtSerialNumber_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSerialNumber1.Leave
'condition the scanned serial number
Dim serialNumber As String = txtSerialNumber1.Text
serialNumber = serialNumber.ToUpper()
serialNumber = serialNumber.Trim()
txtSerialNumber2.Focus()
'replace tokens
'read the label file into a string variable
Dim printString As String = My.Resources.Fuel_Cell_Label
'read the top position into a variable
Dim topPosition As String = My.Settings.prntLabelTop
'read the left position into a variable
Dim leftPosition As String = My.Settings.prntLabelLeft
'replace the tokens with values
printString = printString.Replace("[[Top]]", topPosition)
printString = printString.Replace("[[Left]]", leftPosition)
printString = printString.Replace("[[serial_1]]", serialNumber)
End Sub
Private Sub txtSerialNumber2_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSerialNumber2.Leave
'condition the scanned serial number
Dim serialNumber2 As String = txtSerialNumber2.Text
serialNumber2 = serialNumber2.ToUpper()
serialNumber2 = serialNumber2.Trim()
'reset the front panel controls
txtSerialNumber1.Text = ""
txtSerialNumber2.Text = ""
txtSerialNumber1.Focus()
'replace the last token
printString = printString.Replace("[[serial]]", serialNumber2)
'print the label string
Dim Printer As New Microsoft.VisualBasic.PowerPacks.Printing.Compatibility.VB6.Printer
Printer.Print(printString)
'MessageBox.Show(printString)
End Sub
是的,我对此并不陌生。
我将如何保留该变量值?