1,216
社区成员
发帖
与我相关
我的任务
分享
'stack类模块代码:
Option Compare Database
Option Explicit
Dim StackColl As New Collection
Public Property Get Count() As Variant
Count = StackColl.Count
End Property
Public Sub Push(Var As Variant)
StackColl.Add (Var)
End Sub
Public Function fetch() As Variant
fetch = StackColl.Item(StackColl.Count)
StackColl.Remove (StackColl.Count)
End Function
Public Property Get AllString() As Variant
Dim strItem As Variant
For Each strItem In StackColl
AllString = AllString & "'" & strItem & "',"
Next
End Property
'Form_接龙模块代码:
Option Compare Database
Option Explicit
Private Sub 命令0_Click()
Me.显示接龙 = GetLink(Me.选择成语, Me.接龙长度)
End Sub
Public Function GetLink(StartWord As String, Lenth As Integer) As String
Dim MaxLen As Integer, i As Integer
Dim objStackA As New stack
Dim objStackB As New stack
Dim EndWord As String
Dim rst As Recordset
Randomize
objStackB.Push StartWord
Do While MaxLen < Lenth And objStackB.Count > 0
StartWord = objStackB.fetch
Set rst = CurrentDb().OpenRecordset("Select CM from cy where Head='" & Right(StartWord, 1) & "' AND CM Not In (''," & objStackA.AllString & ")" & IIf(Int(2 * Rnd) = 0, "", " Order by CM Desc"))
If Not rst.EOF Then
Do While objStackA.Count > 0
EndWord = objStackA.fetch
If Right(EndWord, 1) = Left(StartWord, 1) Then
objStackA.Push EndWord
Exit Do
End If
Loop
objStackA.Push StartWord
If objStackA.Count > MaxLen Then
GetLink = objStackA.AllString
MaxLen = objStackA.Count
End If
Do While Not rst.EOF
objStackB.Push rst![CM]
rst.MoveNext
Loop
End If
Loop
End Function