- ©«¤l
- 1018
- ¥DÃD
- 15
- ºëµØ
- 0
- ¿n¤À
- 1058
- ÂI¦W
- 0
- §@·~¨t²Î
- win7 32bit
- ³nÅ骩¥»
- Office 2016 64-bit
- ¾\ŪÅv
- 50
- ©Ê§O
- ¨k
- ¨Ó¦Û
- ®ç¶é
- µù¥U®É¶¡
- 2012-5-9
- ³Ì«áµn¿ý
- 2022-9-28
|
¥»©«³Ì«á¥Ñ stillfish00 ©ó 2016-3-11 19:42 ½s¿è
¦^´_ 12# boblovejoyce
®¦¡AfirstIndex ³oÃä§Ú¿ù¤F¡Amatch¨ì²Ä¤@Ó¦r®É firstIndex = 0¡A©MVBA¤£¤@¼Ë¡AÃø©Ç¶]¨º»ò¤[¡Aקï¦p¤U
µM«á¦³¨Çrenameªº§Ú¤£ª¾n¨úþÓ¦WºÙ¡A³£¼g¨ì²Ä¤@Äæ- Sub Test()
- '== Read File ==
- Dim fn As Integer, allText As String
- Dim fname
- fname = Application.GetOpenFilename()
- If TypeName(fname) = "Boolean" Then Exit Sub
- fn = FreeFile()
- Open fname For Input As #fn
- allText = Input$(LOF(1), 1)
- Close #fn
-
- '== Parse Element ==
- Dim oRegex As Object: Set oRegex = CreateObject("vbscript.regexp")
- Dim oDic As Object: Set oDic = CreateObject("scripting.dictionary")
- Dim omch As Object, oMch2 As Object, x, i As Long, j As Long, endIndex As Long
- Dim hasVDD As Boolean, hasGND As Boolean
- With oRegex
- .Global = True
- .Pattern = "\(net\s+(\(rename.*\)|[^\s()]*)" '(net ¶}ÀY¡A®·®»¤U¤@Ó«DªÅ¥Õ©Î()ªº¦r²Õ©Îrename...
- Set omch = .Execute(allText)
-
- .Pattern = "\(portRef\s+([^\s()]*)" '(portRef ¶}ÀY¡A®·®»¤U¤@Ó«DªÅ¥Õ©Î()ªº¦r²Õ
- i = 1
- For Each x In omch
- endIndex = FindCloseBracket(allText, x.firstIndex + 1)
- If endIndex = 0 Then MsgBox "Fail to parse: " & vbNewLine & Mid(allText, (x.firstIndex + 1), 50) & "...": Exit Sub
- Set oMch2 = .Execute(Mid(allText, x.firstIndex + 1, endIndex - (x.firstIndex + 1) + 1))
-
- hasVDD = False: hasGND = False
- For Each y In oMch2
- If InStr(1, y.subMatches(0), "VDD", vbTextCompare) Then hasVDD = True
- If InStr(1, y.subMatches(0), "GND", vbTextCompare) Then hasGND = True
- Next
-
- If oMch2.Count < 2 Or (hasVDD And hasGND) Then 'portRef§C©ó¨âөΦP®É§tVDD¤ÎGND¦r¦ê
- oDic.Add i, x.subMatches(0)
- i = i + 1
- End If
- Next
- End With
-
- '== Output result ==
- Dim ar
- If oDic.Count = 0 Then MsgBox "All pass": Exit Sub
- ar = oDic.items
- With Sheets.Add
- Application.ScreenUpdating = False
- .[a1].Resize(UBound(ar) - LBound(ar) + 1) = OneDtoTwoD(ar)
- Application.ScreenUpdating = True
- End With
- End Sub
- ' s: input string
- ' i: index of begin bracket "("
- Function FindCloseBracket(ByRef s As String, ByVal i As Long) As Long
- Dim isInString As Boolean 'ex : ¹w¨¾Âù¤Þ¸¹¦r¦ê¤ºªº () »~§P
- i = i + 1 '±q¤U¤@Ó¦r¤¸¶}©l
- Do While i <= Len(s)
- Select Case Mid(s, i, 1)
- Case "("
- If Not isInString Then
- i = FindCloseBracket(s, i)
- If i = 0 Then Exit Do
- End If
- Case ")"
- If Not isInString Then
- FindCloseBracket = i
- Exit Function
- End If
- Case """"
- isInString = Not isInString
- Case Else
- End Select
- i = i + 1
- Loop
- FindCloseBracket = 0
- End Function
- Function OneDtoTwoD(ar, Optional base As Integer) As Variant 'transepose array of elements > 65535
- Dim i, retn()
- ReDim retn(base To base + UBound(ar) - LBound(ar), base To base) ' transe to base
- For i = LBound(ar) To UBound(ar)
- retn(i - LBound(ar) + base, base) = ar(i)
- Next
- OneDtoTwoD = retn
- End Function
½Æ»s¥N½X |
|