[英]How can I make two scripts into one?
請閱讀以下模板:
PID Status LPID
10 Closed 25
11 Open 25
31 Open 31
25 Closed 25
54 Open 31
17 Open 17
20 Closed 31
88 closed 77
77 closed 77
201 open 202
205 open 500
現在,當PID!= LPID時,該PID被定義為CPID(子進程ID),否則為PPID(父進程ID)
現在我正在尋找一個代碼,該代碼將告訴哪個是父級,哪個是子級,這意味着將它們標記在另一張工作表中。同時,我想列出所有CPID,在同一行中有PPID,如果任何PPID有子進程他們自己。 輸出如下所示
PID Type Of Process? Child List
10 Child
11 Child
31 Parent 54 20
25 Parent 10 11
54 Child
17 Parent
20 Child
88 Child
77 Parent 88
我已經使用VBScript編寫了代碼,但是用實際的表格來說太慢了。 對於2500個數據來說,它需要將近1個小時。因此,我想要一個比我更快的過程。
您能在這里使用VBscript幫助嗎?
代碼1:
Set objExcel1 = CreateObject("Excel.Application")'Object for W2W Report Dump
strPathExcel1 = "D:\VA\CopyofGEWingtoWing_latest_dump_21112012.xls"
objExcel1.Workbooks.open strPathExcel1
Set objSheet1 = objExcel1.ActiveWorkbook.Worksheets(2)
Set objSheet2 = objExcel1.ActiveWorkbook.Worksheets(1)
IntRow1=1
Do While objSheet1.Cells(IntRow1, 1).Value <> ""
IntRow2=4
IntChildListColumn=3
If objSheet1.Cells(IntRow1,2).Value="Parent" Then
Do While objSheet2.Cells(IntRow2, 1).Value <> ""
If objSheet2.Cells(IntRow2,11).Value=objSheet1.Cells(IntRow1,1).Value And objSheet2.Cells(IntRow2,11).Value <> objSheet2.Cells(IntRow2,1).Value Then
objSheet1.Cells(IntRow1,IntChildListColumn).Value=objSheet2.Cells(IntRow2,1).Value
IntChildListColumn=IntChildListColumn+1
End If
IntRow2=IntRow2+1
Loop
End If
IntRow1=IntRow1+1
Loop
代碼2:
Flag=0
IntColTemp=1
IntRowTemp=3
Set objExcel1 = CreateObject("Excel.Application")'Object for Condition Dump
strPathExcel1 = "D:\VA\CopyofGEWingtoWing_latest_dump_21112012.xls"
objExcel1.Workbooks.open strPathExcel1
Set objSheet1 = objExcel1.ActiveWorkbook.Worksheets(1)
Set objSheet2 = objExcel1.ActiveWorkbook.Worksheets(2)
IntRow1=4
IntRow2=1
Do While objSheet1.Cells(IntRow1, 1).Value <> ""
objSheet2.Cells(IntRow2, 1).Value = objSheet1.Cells(IntRow1, 1).Value
IntColTemp=1
Flag=0
'This will travarse to the Parent Business Process ID column horizantally in the excel.
Do While Flag=0
If objSheet1.Cells(IntRowTemp,IntColTemp).Value="Parent Business Process ID" Then
Flag=1
End If
IntColTemp=IntColTemp+1
Loop
IntColTemp=IntColTemp-1
'MsgBox(IntColTemp)
Strcmp1=trim(objSheet1.Cells(IntRow1, 1).Value)
Strcmp2=trim(objSheet1.Cells(IntRow1,IntColTemp).Value)
If Strcmp1=Strcmp2 Then
objSheet2.Cells(IntRow2, 2).Value="Parent"
Else
objSheet2.Cells(IntRow2, 2).Value="child"
End If
IntRow1=IntRow1+1
IntRow2=IntRow2+1
Loop
編輯看到兩個ID 201和205具有子-父關系,但是子ID將需要出現在輸出列中,但父202和500不應出現在輸出列表中,因為主表中沒有烯202 close/open 202
和500 open/close 500
兩種想法/策略:
在代碼中:
Option Explicit
Class cP
Public m_sRel
Public m_dicC
Private Sub Class_Initialize()
m_sRel = "Child"
Set m_dicC = CreateObject("Scripting.Dictionary")
End Sub
Public Function show()
show = m_sRel & " " & Join(m_dicC.Keys)
End Function
End Class
Dim oFS : Set oFS = CreateObject("Scripting.FileSystemObject")
Dim oXls : Set oXls = CreateObject("Excel.Application")
Dim oWb : Set oWb = oXls.Workbooks.Open(oFs.GetAbsolutePathName(".\00.xlsx"))
Dim aData : aData = oWb.Worksheets(1).Range("$A2:$C10")
Dim dicP : Set dicP = CreateObject("Scripting.Dictionary")
Dim nRow
For nRow = LBound(aData, 1) To UBound(aData, 1)
Set dicP(aData(nRow, 1)) = New cP
Next
For nRow = LBound(aData, 1) To UBound(aData, 1)
If aData(nRow, 1) = aData(nRow, 3) Then
dicP(aData(nRow, 1)).m_sRel = "Parent"
Else
dicP(aData(nRow, 3)).m_dicC(aData(nRow, 1)) = 0
End If
Next
Dim nP
For Each nP In dicP.Keys()
WScript.Echo nP, dicP(nP).show()
Next
oWb.Close
oXls.Quit
輸出:
10 Child
11 Child
31 Parent 54 20
25 Parent 10 11
54 Child
17 Parent
20 Child
88 Child
77 Parent 88
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.