【发布时间】:2014-11-18 00:46:01
【问题描述】:
我已经检查了谷歌和这里的建议答案,但不幸的是没有运气。
我需要做的最后一件事是让电子邮件将rateNbr 变量读入电子邮件正文,但它只是空的。
我尝试将Public Function FuncRateCheckFile 读作Public Function FuncRateCheckFile(ByVal rateNbr As String),以尝试使其能够在函数外部调用,但这会在其他地方调用时破坏函数。 :(
这里是代码,关于我指的是哪里的 cmets:
Public Function FuncRateCheckFile()
Dim blnContinue As Boolean
Dim strLine As String
Dim strSearchFor, strSearchWrd, LineCount, objFSO, objTextFile, arrLines
Dim dteNow As Date
Dim newDate As String
'//==============================================================================================
'// DECLARED
Dim rateNbr As String
'//==============================================================================================
FuncRateCheckFile = False
blnContinue = True
If blnContinue Then
Const ForReading = 1
'Get todays date and reformat it
dteNow = DateValue(Now)
newDate = Format(dteNow, "dd/MM/yy")
strSearchWrd = newDate
'Read the whole file
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(m_RateCheckFile, ForReading)
LineCount = 0
Do Until objTextFile.AtEndOfStream
strLine = objTextFile.ReadLine()
If InStr(strLine, strSearchWrd) <> 0 Then
arrLines = Split(strLine, vbCrLf)
LineCount = LineCount + 1
End If
Loop
'Log a message to state how many lines have todays day, and if there are none, log an error
If LineCount <> 0 Then
'//==============================================================================================
'// "rateNbr" IS WHAT I AM TRYING TO GET TO PUT IN THE EMAIL
LogMessage "Rate file date is correct"
rateNbr = "Number of rates for " & newDate & " in the file recieved on " & newDate & " is " & LineCount
LogMessage rateNbr
EmailAdvice2
objTextFile.Close
'//==============================================================================================
Else
blnContinue = False
LogError "Failed to retrieve Current Rate date, please check rate file.."
EmailAdvice
objTextFile.Close
End If
End If
FuncRateCheckFile = blnContinue
LogMessage "Completed Check Rate file"
End Function
Private Function EmailAdvice2()
Dim strSMTPFrom As String
Dim strSMTPTo As String
Dim strSMTPRelay As String
Dim strTextBody As String
Dim strSubject As String
Dim oMessage As Object
'//==============================================================================================
'// DECLARED AGAIN
Dim rateNbr As String
'//==============================================================================================
Set oMessage = CreateObject("CDO.Message")
strSMTPFrom = "no-reply@work.com.au"
strSMTPTo = "me@work.com.au"
strSMTPRelay = "smtp.relay.com"
'//==============================================================================================
'// THIS MAKES THE TEXT BODY BLANK, BUT THE EMAIL STILL SENDS
strTextBody = rateNbr
'//==============================================================================================
strSubject = "Todays rates"
'strAttachment = "full UNC path of file"
oMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
oMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strSMTPRelay
oMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
oMessage.Configuration.Fields.Update
oMessage.Subject = strSubject
oMessage.From = strSMTPFrom
oMessage.To = strSMTPTo
oMessage.textbody = strTextBody
'oMessage.AddAttachment strAttachment
oMessage.Send
End Function
我很肯定它是空白的,因为我在EmailAdvice2() 下声明了rateNbr,然后没有给它任何东西来填充变量。但是不知道怎么让它调用FuncRateCheckFile()下的变量。
感谢大家的帮助。
【问题讨论】:
-
事实上,您的问题是代码转储。请将代码简化为说明您的问题所需的最小示例。
-
查看
Scope;在过程中声明,rateNbr仅存在于本地。所以你有两个,一个在FuncRateCheckFile和EmailAdvice2。这甚至是VB.NET吗?有一些非常 VBA 外观的语法和对象使用,例如 FileScripting 对象。 -
您发布了一个非常含糊(而且有些杂乱无章)的问题描述和一堵巨大的代码墙。这不是问题在这里的工作方式。请edit 明确说明问题,将代码减少到您的问题所需的最低限度,并就该代码提出具体问题。
-
抱歉,我已编辑以使代码更有意义并减少代码。我在发帖之前没有读过它,我应该读过。它看起来确实像漫无边际。我什至没有完成标题!
-
这看起来不像 VB.Net 代码。