当我解析一封看起来像这样的电子邮件时:
包括_po~301993959 'VBCRLF
po_no~vendor~part_no~class~type_code~buyer~qty_ordered~measure~balance_on_order~cost~amt_ordered~order_date~delivery_date~ship_date~receive_date~open~wo_no 'VBCRLF
301993959~100000~88008K~PROBE 800~F~VAX~4.0~EA~4.0~100.3300~401.32000~011513~012313~012313~000000~Y~STOCK'VBCRLF 301993959~100000~SPTEFCI~010WIRE ~VAX~1.0~SP~1.0~12.6400~12.64000~011513~012313~012313~000000~Y~STOCK 'VBCRLF 301993959~100000~TFIR-010-50~WIRE SPTEF~F~VAX~1.0~SP~1.0~12.6400 ~12.64000~011513~012313~012313~000000~Y~STOCK 'VBCRLF
使用代码:
Public Sub AddItems()
Dim aLineItem() As String
Dim aItem() As String
Dim i As Integer
Dim j As Integer
Dim iCnt As Double
Dim msg
Dim Item As Items
ReDim sWo(0)
iCnt = 0
For i = 1 To UBound(sMsg())
aLineItem = Split(sMsg(i), vbCrLf)
For j = 1 To UBound(aLineItem)
If aLineItem(j) <> "" Then
If blah = 1 Then
Debug.Print ("...." & aLineItem(j))
End If
aItem = Split(aLineItem(j), "~")
If (aItem(0) <> "") And (aItem(0) <> "included_po") And (aItem(0) <> "po_no") Then
Item.PO_num = GetWo(aItem(1))
If Item.PO_num <> "0" Then
Item.Company = aItem(1)
Item.Delivery_date = aItem(12)
Item.pn = aItem(2)
Item.QTY_ordered = aItem(6)
Item.Unit_Price = aItem(9)
End If 'If Item.PO_num <> "0" Then
End If 'If aItem(1) <> "" Then
End If ' If aLineItem(j) <> "" Then
Next j
Next i
End Sub
电子邮件解析如下所示:
....301993959~100000~88008K~探针
....8800~F~VAX~4.0~EA~4.0~100.3300~401.32000~011513~012313~012313~000000~Y~S
....托克
有没有更好的方法来解析这封电子邮件?
编辑#1:
Public Sub GetMailMsg()
Dim pop3 As jmail.pop3
Dim iCount As Integer
Dim i As Integer
Dim mailID As Integer
Dim j As Integer
Dim sSubject As String
j = 0
ReDim sMsg(0)
'connect to the mail box
Set pop3 = New pop3
pop3.Connect "REMOVED FOR SECURITY"
'Get message count
iCount = pop3.Count
'Read Messages
For i = 1 To iCount
sSubject = pop3.Messages.Item(i).Subject
Label1.Caption = "Reading message.." & sSubject
DoEvents
If InStr(sSubject, "China Purchase Orders") <> 0 Then 'email test
j = j + 1
ReDim Preserve sMsg(j)
sMsg(j) = pop3.Messages.Item(i).Body
Label1.Caption = "Reading mail message for order " & sSubject
If blah = 1 Then
Debug.Print ("Reading mail message for order " & sSubject)
Debug.Print ("Reading mail message for order " & sMsg(j))
End If
End If
Next
pop3.Disconnect
Set pop3 = Nothing
End SUb
--编辑#2
调试输出:阅读订单中国采购订单的邮件消息阅读订单包含的邮件_po~301993959
po_no~vendor~part_no~class~type_code~buyer~qty_ordered~measure~balance_o 'VBCRLF
n_order~cost~amt_ordered~order_date~delivery_date~ship_Date~receive_date 'VBCRLF
~open~wo_no 'VBCRLF
301993959~100000~88008K~探针'VBCRLF
8800~F~VAX~4.0~EA~4.0~100.3300~401.32000~011513~012313~012313~000000~Y~S'VBCRLF
托克'VBCRLF
301993959~100000~TFCI-010-50~WIRE 'VBCRLF
SPTEF~F~VAX~1.0~SP~1.0~12.6400~12.64000~011513~012313~012313~000000~Y~ST 'VBCRLF
奥克'VBCRLF
301993959~100000~TFIR-010-50~WIRE 'VBCRLF
SPTEF~F~VAX~1.0~SP~1.0~12.6400~12.64000~011513~012313~012313~000000~Y~ST 'VBCRLF
奥克'VBCRLF