用VB 编的汉诺塔,在塔移动的过程中,实现了暂停功能后,请问如何使程序继续运行直到结束呢 ?请各个给个思路和方法。

解决方案 »

  1.   

    摘抄的例子
    Option Explicit'This is an old east asian problem and saga has it that the world is doomed when this
    'is finished by monks who are transferring 64 golden disks (manually !!) - so
    'we can rest assured that the world will live a long time yet.'The objective is to move all disks from tower A to tower C with the constraint that
    'a larger disk can never be placed on a smaller one. To this end tower B may be used
    'as an interim station for the disks - but here the same rule prevails.'This shows recursive programming techniques.  Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)  Const FromTower                          As Long = 1
      Const ViaTower                           As Long = 2
      Const ToTower                            As Long = 3
      
      Const MinDisks                           As Long = 1
      Const MaxDisks                           As Long = 16
      
      Dim NumDisks                             As Long
      Dim TowerHeight(FromTower To ToTower)    As Long
      Dim DiskNumber(FromTower To ToTower, _
                     MinDisks To MaxDisks)     As Long
      Dim XPosn(FromTower To ToTower)          As Long
      Dim YPosn                                As Long
      Dim DiskHeight                           As Long
      Dim NumMoves                             As Long
      Dim CurrentDisk                          As Long
      Dim Busy                                 As Boolean
      Dim StopRequested                        As BooleanPrivate Sub Command1_Click()
        
        If Not Busy Then
            Busy = True
            StopRequested = False
            Command2.Caption = "Stop"
            Text1_Change
            
            NumMoves = 0
            
    '       the err mechanism will be used to drop out of recursion
    '       if the user stops us, in the IDE you will have to set options
    '       to stop on unhandled errors only
            On Error Resume Next'       here we go
            MoveAllDisks NumDisks, FromTower, ViaTower, ToTower
            
            Busy = False
            Command2.Caption = "Exit"
        End If
        
    End SubSub MoveAllDisks(ByVal NumDisks, ByVal FromTower, ByVal ViaTower, ByVal ToTower)
    '   Move all disks from FromTower to ToTower using ViaTower as intermediate    Select Case NumDisks
          
          Case 1'       there is only one disk - just move it from FromTower to ToTower
            MoveOneDisk FromTower, ToTower
    '       this was the final stage of recursion
          
          Case Is > 1'       more than one disk - move all but the bottom disk from FromTower to ViaTower
    '       using ToTower as intermediate
            MoveAllDisks NumDisks - 1, FromTower, ToTower, ViaTower'       the bottom disk is now the only one remainig on FromTower
    '       all other disks are on ViaTower, and ToTower is empty'       move the bottom disk from FromTower to ToTower
            MoveOneDisk FromTower, ToTower
            
    '       FromTower is now empty and we use it as interim station for moving
    '       all the disks on ViaTower to ToTower
            MoveAllDisks NumDisks - 1, ViaTower, FromTower, ToTower
        
        End SelectEnd SubSub MoveOneDisk(ByVal TowerA, ByVal TowerB)
    '   Move one disk from TowerA to TowerB    NumMoves = NumMoves + 1
        lbl(1) = NumMoves
        
    '   wait a little
        Sleep scrDelay
        
    '   determine the disk to move = top disk of TowerA
        CurrentDisk = DiskNumber(TowerA, TowerHeight(TowerA))'   TowerB grows by 1
        TowerHeight(TowerB) = TowerHeight(TowerB) + 1'   move current disk on top of TowerB
        Disk(CurrentDisk).Move XPosn(TowerB) - Disk(CurrentDisk).Width \ 2, YPosn - TowerHeight(TowerB) * DiskHeight'   keep track of where the moved disk is now
        DiskNumber(TowerB, TowerHeight(TowerB)) = CurrentDisk'   TowerA shrinks by 1
        TowerHeight(TowerA) = TowerHeight(TowerA) - 1'   give Windows a chance
        DoEvents
        
        If StopRequested Then
    '       use Error mechanism to drop out of recursion
            Err.Raise 1
        End If
        
    End SubPrivate Sub Command2_Click()
        
        If Busy Then
            StopRequested = True
          Else
            Unload Me
        End If
        
    End SubPrivate Sub Form_Load()'   Coordinates for the Towers
        XPosn(FromTower) = 100
        XPosn(ViaTower) = 350
        XPosn(ToTower) = 600
        YPosn = ScaleHeight - 70
        
        DiskHeight = Disk(MinDisks).Height - 1
        Text1 = MaxDisks
        
    End SubPrivate Sub Form_Paint()
    '   printing on a form is not permanent - so we have to refresh it when the form is re-painted Dim i As Long
     
        FontBold = True
        For i = FromTower To ToTower
            CurrentX = XPosn(i) - 3 '(width of char) / 2  to center it
            CurrentY = YPosn + 1
            Print Mid$("ABC", i, 1);
        Next i
        
    End SubPrivate Sub Form_Unload(Cancel As Integer)
    '   no unloading while where busy
        
        Cancel = Busy
        
    End SubPrivate Sub Text1_Change()
        
        NumDisks = Val(Text1)
        Command1.Enabled = (NumDisks >= MinDisks And NumDisks <= MaxDisks)
        lbl(1) = ""
        lbl(2) = "of " & 2 ^ NumDisks - 1
        
    '   how high is each Tower
        TowerHeight(FromTower) = NumDisks
        TowerHeight(ViaTower) = 0
        TowerHeight(ToTower) = 0
        
    '   move all disks to FromTower and remember where they are
        For CurrentDisk = MinDisks To MaxDisks
            Disk(CurrentDisk).Move XPosn(FromTower) - Disk(CurrentDisk).Width \ 2, YPosn - CurrentDisk * DiskHeight
            DiskNumber(FromTower, CurrentDisk) = CurrentDisk
    '       hide any unused disks
            Disk(CurrentDisk).Visible = (CurrentDisk <= NumDisks)
        Next CurrentDisk
        DoEvents
        
    End SubPrivate Sub Text1_GotFocus()    Text1.SelStart = 0
        Text1.SelLength = 2
        
    End Sub
      

  2.   

    VERSION 5.00
    Begin VB.Form Hanoi 
       BackColor       =   &H80000005&
       BorderStyle     =   3  'Fester Dialog
       Caption         =   "Towers of Hanoi"
       ClientHeight    =   3615
       ClientLeft      =   30
       ClientTop       =   315
       ClientWidth     =   10575
       LinkTopic       =   "Form1"
       MaxButton       =   0   'False
       MinButton       =   0   'False
       ScaleHeight     =   241
       ScaleMode       =   3  'Pixel
       ScaleWidth      =   705
       ShowInTaskbar   =   0   'False
       StartUpPosition =   2  'Bildschirmmitte
       Begin VB.PictureBox Picture1 
          Align           =   2  'Unten ausrichten
          Height          =   735
          Left            =   0
          ScaleHeight     =   675
          ScaleWidth      =   10515
          TabIndex        =   20
          TabStop         =   0   'False
          Top             =   2880
          Width           =   10575
          Begin VB.CommandButton Command2 
             Cancel          =   -1  'True
             Caption         =   "Exit"
             Height          =   330
             Left            =   3525
             TabIndex        =   2
             Top             =   180
             Width           =   660
          End
          Begin VB.HScrollBar scrDelay 
             Height          =   240
             LargeChange     =   10
             Left            =   5265
             Max             =   1000
             TabIndex        =   3
             Top             =   225
             Width           =   1215
          End
          Begin VB.TextBox Text1 
             Alignment       =   1  'Rechts
             Height          =   285
             Left            =   1860
             MaxLength       =   2
             TabIndex        =   0
             Top             =   195
             Width           =   345
          End
          Begin VB.CommandButton Command1 
             Caption         =   "Start"
             Default         =   -1  'True
             Height          =   330
             Left            =   2565
             TabIndex        =   1
             Top             =   180
             Width           =   660
          End
          Begin VB.Label lbl 
             BackColor       =   &H00000000&
             BackStyle       =   0  'Transparent
             Caption         =   "Move"
             Height          =   195
             Index           =   0
             Left            =   8010
             TabIndex        =   25
             Top             =   255
             Width           =   405
          End
          Begin VB.Label lbl 
             Alignment       =   1  'Rechts
             BackColor       =   &H00000000&
             BackStyle       =   0  'Transparent
             Height          =   195
             Index           =   1
             Left            =   8475
             TabIndex        =   24
             Top             =   255
             Width           =   450
          End
          Begin VB.Label lbl 
             BackColor       =   &H00000000&
             BackStyle       =   0  'Transparent
             Height          =   195
             Index           =   2
             Left            =   8985
             TabIndex        =   23
             Top             =   255
             Width           =   720
          End
          Begin VB.Label Label1 
             AutoSize        =   -1  'True
             BackStyle       =   0  'Transparent
             Caption         =   "faster                               slower"
             Height          =   195
             Left            =   4785
             TabIndex        =   22
             Top             =   240
             Width           =   2235
          End
          Begin VB.Label Label2 
             BackStyle       =   0  'Transparent
             Caption         =   "Enter number of disks"
             Height          =   195
             Left            =   225
             TabIndex        =   21
             Top             =   240
             Width           =   1530
          End
       End
       Begin VB.PictureBox Disk 
          Appearance      =   0  '2D
          BackColor       =   &H00800080&
          ForeColor       =   &H80000008&
          Height          =   165
          Index           =   16
          Left            =   5220
          ScaleHeight     =   135
          ScaleWidth      =   885
          TabIndex        =   19
          TabStop         =   0   'False
          Top             =   225
          Visible         =   0   'False
          Width           =   915
       End
       Begin VB.PictureBox Disk 
          Appearance      =   0  '2D
          BackColor       =   &H00FF00FF&
          ForeColor       =   &H80000008&
          Height          =   165
          Index           =   15
          Left            =   5160
          ScaleHeight     =   135
          ScaleWidth      =   1005
          TabIndex        =   18
          TabStop         =   0   'False
          Top             =   375
          Visible         =   0   'False
          Width           =   1035
       End
       Begin VB.PictureBox Disk 
          Appearance      =   0  '2D
          BackColor       =   &H00800000&
          ForeColor       =   &H80000008&
          Height          =   165
          Index           =   14
          Left            =   5100
          ScaleHeight     =   135
          ScaleWidth      =   1125
          TabIndex        =   17
          TabStop         =   0   'False
          Top             =   525
          Visible         =   0   'False
          Width           =   1155
       End
       Begin VB.PictureBox Disk 
          Appearance      =   0  '2D
          BackColor       =   &H00FF8080&
          ForeColor       =   &H80000008&
          Height          =   165
          Index           =   13
          Left            =   5040
          ScaleHeight     =   135
          ScaleWidth      =   1245
          TabIndex        =   16
          TabStop         =   0   'False
          Top             =   675
          Visible         =   0   'False
          Width           =   1275
       End
       Begin VB.PictureBox Disk 
          Appearance      =   0  '2D
          BackColor       =   &H00808000&
          ForeColor       =   &H80000008&
          Height          =   165
          Index           =   12
          Left            =   4980
          ScaleHeight     =   135
          ScaleWidth      =   1365
          TabIndex        =   15
          TabStop         =   0   'False
          Top             =   825
          Visible         =   0   'False
          Width           =   1395
       End
      

  3.   

    Begin VB.PictureBox Disk 
          Appearance      =   0  '2D
          BackColor       =   &H00FFFF00&
          ForeColor       =   &H80000008&
          Height          =   165
          Index           =   11
          Left            =   4920
          ScaleHeight     =   135
          ScaleWidth      =   1485
          TabIndex        =   14
          TabStop         =   0   'False
          Top             =   975
          Visible         =   0   'False
          Width           =   1515
       End
       Begin VB.PictureBox Disk 
          Appearance      =   0  '2D
          BackColor       =   &H00004080&
          ForeColor       =   &H80000008&
          Height          =   165
          Index           =   10
          Left            =   4860
          ScaleHeight     =   135
          ScaleWidth      =   1605
          TabIndex        =   13
          TabStop         =   0   'False
          Top             =   1125
          Visible         =   0   'False
          Width           =   1635
       End
       Begin VB.PictureBox Disk 
          Appearance      =   0  '2D
          BackColor       =   &H000040C0&
          ForeColor       =   &H80000008&
          Height          =   165
          Index           =   9
          Left            =   4800
          ScaleHeight     =   135
          ScaleWidth      =   1725
          TabIndex        =   12
          TabStop         =   0   'False
          Top             =   1275
          Visible         =   0   'False
          Width           =   1755
       End
       Begin VB.PictureBox Disk 
          Appearance      =   0  '2D
          BackColor       =   &H000080FF&
          ForeColor       =   &H80000008&
          Height          =   165
          Index           =   8
          Left            =   4740
          ScaleHeight     =   135
          ScaleWidth      =   1845
          TabIndex        =   11
          TabStop         =   0   'False
          Top             =   1425
          Visible         =   0   'False
          Width           =   1875
       End
       Begin VB.PictureBox Disk 
          Appearance      =   0  '2D
          BackColor       =   &H00008080&
          ForeColor       =   &H80000008&
          Height          =   165
          Index           =   7
          Left            =   4680
          ScaleHeight     =   135
          ScaleWidth      =   1965
          TabIndex        =   10
          TabStop         =   0   'False
          Top             =   1575
          Visible         =   0   'False
          Width           =   1995
       End
       Begin VB.PictureBox Disk 
          Appearance      =   0  '2D
          BackColor       =   &H0000C0C0&
          ForeColor       =   &H80000008&
          Height          =   165
          Index           =   6
          Left            =   4620
          ScaleHeight     =   135
          ScaleWidth      =   2085
          TabIndex        =   9
          TabStop         =   0   'False
          Top             =   1725
          Visible         =   0   'False
          Width           =   2115
       End
       Begin VB.PictureBox Disk 
          Appearance      =   0  '2D
          BackColor       =   &H0080FFFF&
          ForeColor       =   &H80000008&
          Height          =   165
          Index           =   5
          Left            =   4560
          ScaleHeight     =   135
          ScaleWidth      =   2205
          TabIndex        =   8
          TabStop         =   0   'False
          Top             =   1875
          Visible         =   0   'False
          Width           =   2235
       End
       Begin VB.PictureBox Disk 
          Appearance      =   0  '2D
          BackColor       =   &H00000080&
          ForeColor       =   &H80000008&
          Height          =   165
          Index           =   4
          Left            =   4500
          ScaleHeight     =   135
          ScaleWidth      =   2325
          TabIndex        =   7
          TabStop         =   0   'False
          Top             =   2025
          Visible         =   0   'False
          Width           =   2355
       End
       Begin VB.PictureBox Disk 
          Appearance      =   0  '2D
          BackColor       =   &H000000C0&
          ForeColor       =   &H80000008&
          Height          =   165
          Index           =   3
          Left            =   4440
          ScaleHeight     =   135
          ScaleWidth      =   2445
          TabIndex        =   6
          TabStop         =   0   'False
          Top             =   2175
          Visible         =   0   'False
          Width           =   2475
       End
       Begin VB.PictureBox Disk 
          Appearance      =   0  '2D
          BackColor       =   &H000000FF&
          ForeColor       =   &H80000008&
          Height          =   165
          Index           =   2
          Left            =   4380
          ScaleHeight     =   135
          ScaleWidth      =   2565
          TabIndex        =   5
          TabStop         =   0   'False
          Top             =   2325
          Visible         =   0   'False
          Width           =   2595
       End
       Begin VB.PictureBox Disk 
          Appearance      =   0  '2D
          BackColor       =   &H008080FF&
          ForeColor       =   &H80000008&
          Height          =   165
          Index           =   1
          Left            =   4320
          ScaleHeight     =   135
          ScaleWidth      =   2685
          TabIndex        =   4
          TabStop         =   0   'False
          Top             =   2475
          Visible         =   0   'False
          Width           =   2715
       End
    End
    Attribute VB_Name = "Hanoi"
    Attribute VB_GlobalNameSpace = False
    Attribute VB_Creatable = False
    Attribute VB_PredeclaredId = True
    Attribute VB_Exposed = False
      

  4.   

    2楼->3楼->1楼的顺序把内容复制到记事本中,然后另存为hanoi.frm(不带Txt后缀)文件,双击打开,然后执行即可
      

  5.   

    faint,找不到ftp,只好...要是不行,给个mail发给你source