- ©«¤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
|
¦^´_ 1# boblovejoyce
¯ó¯ó§¹¦¨¦p¤Uµ{¦¡¡A
¦]¬°VBªº¥¿«hªí¹F¦¡¥\¯à®z¤FÂI
©Ò¥H¤S¦Û¤v¼g¤F FindCloseBracket §ä¥X¤Ç°tªº¥k¬A¸¹¦ì¸m- Sub Test()
- Dim fn As Integer, allText As String, indexClose As Long
- 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
-
- Sheets.Add
- Cells(1, 1).Resize(, 3) = Array("net", "check", "portRef")
- Dim oRegex As Object: Set oRegex = CreateObject("vbscript.regexp")
- 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+([^\s()]*)" '(net ¶}ÀY¡A®·®»¤U¤@Ó«DªÅ¥Õ©Î()ªº¦r²Õ
- Set oMch = .Execute(allText)
-
- .Pattern = "\(portRef\s+([^\s()]*)" '(portRef ¶}ÀY¡A®·®»¤U¤@Ó«DªÅ¥Õ©Î()ªº¦r²Õ
- i = 2
- For Each x In oMch
- endindex = FindCloseBracket(allText, x.firstIndex)
- Set oMch2 = .Execute(Mid(allText, x.firstIndex, endindex - x.firstIndex + 1))
- Cells(i, 1) = x.subMatches(0)
- j = 3
- 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
- Cells(i, j) = y.subMatches(0)
- j = j + 1
- Next
- Cells(i, 2) = IIf(oMch2.Count < 2 Or (hasVDD And hasGND), "X", "O")
-
- i = i + 1
- Next
- 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
- DoEvents
- Loop
- FindCloseBracket = 0
- End Function
½Æ»s¥N½X |
|