;Local $Str = FileRead('test.txt')
Local $Str = _
'济南市中大观园 3701001' & @CRLF & _
'济南市中经七路 3701002' & @CRLF & _
'济南市中六里山 3701003' & @CRLF & _
'济南市中七里山 3701004' & @CRLF & _
'济南市中二七村 3701005' & @CRLF & _
'济南市中玉函路 3701006' & @CRLF & _
'青岛市南金湖路 3702001' & @CRLF & _
'青岛市南中山路 3702002' & @CRLF & _
'青岛市a江苏路 3702003' & @CRLF & _
'青岛市a八大关 3702004' & @CRLF & _
'青岛市b八大湖 3702005' & @CRLF & _
'青岛市b湛山 3702006' & @CRLF & _
'青岛市b八大峡a 3702007'
Local $sR = StringRegExp($Str, '(?m)^([^\h]{2})([^\h]{2})([^\h]{2,})\h+\d+', 3)
Local $a1[UBound($sR) / 3], $a2[UBound($sR) / 3], $a3[UBound($sR) / 3]
Local $x = 0, $data1 = '请选择|'
For $i = 0 To UBound($sR) - 1 Step 3
$a1[$x] = $sR[$i]
$a2[$x] = $sR[$i + 1]
$a3[$x] = $sR[$i + 2]
$x += 1
Next
For $i = 0 To UBound($a1) - 1
If Not IsDeclared('_' & $a1[$i]) Then
$data1 &= $a1[$i] & '|'
Assign('_' & $a1[$i], 0)
EndIf
Next
GUICreate('级联test-Afan', 220, 150)
$Combo1 = GUICtrlCreateCombo("", 20, 10, 180, 25, 0x0003)
GUICtrlSetData(-1, $data1, '请选择')
$Combo2 = GUICtrlCreateCombo('', 20, 40, 180, 25, 0x0003)
$Combo3 = GUICtrlCreateCombo('', 20, 70, 180, 25, 0x0003)
$Button = GUICtrlCreateButton('读取', 50, 100, 120, 20)
GUISetState()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case -3
Exit
Case $Combo1, $Combo2
Go()
Case $Button
If GUICtrlRead($Combo1) = '请选择' Then ContinueLoop
$tmp = GUICtrlRead($Combo1) & GUICtrlRead($Combo2) & GUICtrlRead($Combo3)
$var = StringRegExp($Str, $tmp & '\h+(\d+)', 3)
If Not @error Then MsgBox(64, '数据', '单位名称:' & $tmp & @LF & '单位代码:' & $var[0])
EndSwitch
WEnd
Func Go()
If GUICtrlRead($nMsg) = '请选择' Then
GUICtrlSetData($Combo2, '')
GUICtrlSetData($Combo3, '')
Return
EndIf
Local $xx = 0
For $i = $nMsg - 3 To 1
SetData($i, $xx)
$xx += 1
Next
EndFunc ;==>Go
Func SetData($x, $m)
Local $rd = GUICtrlRead($nMsg + $m)
Local $df, $data, $_rd, $_next
Switch $x
Case 0
$_rd = $a1
$_next = $a2
Case 1
$_rd = $a2
$_next = $a3
EndSwitch
For $i = 0 To UBound($a1) - 1
If ($_rd[$i] = $rd) And (Not IsDeclared('_' & $_next[$i])) Then
$data &= $_next[$i] & '|'
Assign('_' & $_next[$i], 0)
If $df = '' Then $df = $_next[$i]
EndIf
Next
GUICtrlSetData($nMsg + 1 + $m, '|' & $data, $df)
EndFunc ;==>SetData