我正在嘗試嵌入我的代碼。我創建了一個名爲JrnlHeader
的子例程來聲明我將在另一個子例程中使用的變量。我目前只關注一個名爲Header
的變量。我想知道爲什麼Header
在子程序PrintToTextFile
中爲空,以及我如何修復它以便能夠使用在JrnlHeader中聲明的字符串。將字符串傳遞給另一個子例程
Private Sub JrnlHeader()
Dim Header As String
Dim SeqNo As String
Dim SeqVar As String
Dim Bu As String
Dim BuVar As String
Dim JrnlID As String
Dim JrnlIDVar As String
Dim JrnlDate As String
Dim JrnlDateVar As String
Dim Descr As String
Dim DescrVar As String
Dim Ledger As String
Dim LedgerVar As String
Dim Source As String
Dim SourceVar As String
Dim CurEff As String
Dim Reverse As String
Dim AutoLn As String
Dim AdjEnt As String
Header = "<JRNL_HDR_IMP>"
SeqNo = "<SEQNO>" & SeqVar & "</SEQNO>"
Bu = "<BUSINESS_UNIT>" & BuVar & "</BUSINESS_UNIT>"
JrnlID = "<JOURNAL_ID>" & JrnlIDVar & "</JOURNAL_ID>"
JrnlDate = "<JOURNAL_DATE>" & JrnlDateVar & "</JOURNAL_DATE>"
Descr = "<DESCR254>" & DescrVar & "</DESCR254>"
Ledger = "<LEDGER_GROUP>" & LedgerVar & "</LEDGER_GROUP>"
Source = "<SOURCE>" & SourceVar & "</SOURCE>"
CurEff = "<CUR_EFFDT>" & JrnlDateVar & "</CUR_EFFDT>"
Reverse = "<REVERSAL_CD>N</REVERSAL_CD>"
AutoLn = "<AUTO_GEN_LINES>N</AUTO_GEN_LINES>"
AdjEnt = "<ADJUSTING_ENTRY>N</ADJUSTING_ENTRY>"
End Sub
Sub PrintToTextFile()
Dim FileNum As Integer
JrnlHeader
FileNum = FreeFile ' next free filenumber
'Open "C:\Temp\TEXTFILE.TXT" For Output As #FileNum ' creates the new file
Open "C:\temp\TEXTFILE.TXT" For Append As #FileNum
Print #FileNum, Header
Close #FileNum ' close the file
End Sub