⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gray.frm

📁 格雷码的代码,能选择格雷码的个数,用VB写的,界面良好
💻 FRM
字号:
VERSION 5.00
Object = "{3B7C8863-D78F-101B-B9B5-04021C009402}#1.2#0"; "RICHTX32.OCX"
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form Form1 
   BackColor       =   &H00E0E0E0&
   Caption         =   "Form1"
   ClientHeight    =   4425
   ClientLeft      =   1725
   ClientTop       =   1890
   ClientWidth     =   7680
   LinkTopic       =   "Form1"
   OLEDropMode     =   1  'Manual
   Picture         =   "gray.frx":0000
   ScaleHeight     =   4425
   ScaleWidth      =   7680
   Begin VB.TextBox Text3 
      Height          =   495
      Left            =   6240
      TabIndex        =   9
      Text            =   "Text3"
      Top             =   720
      Visible         =   0   'False
      Width           =   615
   End
   Begin MSComctlLib.ProgressBar ProgressBar1 
      Height          =   255
      Left            =   3480
      TabIndex        =   8
      Top             =   3120
      Width           =   3015
      _ExtentX        =   5318
      _ExtentY        =   450
      _Version        =   393216
      Appearance      =   1
      Enabled         =   0   'False
      OLEDropMode     =   1
   End
   Begin VB.CommandButton Command2 
      Caption         =   "end"
      Height          =   375
      Left            =   5880
      MouseIcon       =   "gray.frx":A797
      MousePointer    =   99  'Custom
      TabIndex        =   6
      Top             =   2400
      Width           =   1095
   End
   Begin VB.Timer Timer2 
      Left            =   2160
      Top             =   2040
   End
   Begin VB.Timer Timer1 
      Left            =   2760
      Top             =   2040
   End
   Begin VB.TextBox Text2 
      Height          =   375
      Left            =   4200
      TabIndex        =   4
      Text            =   "Text2"
      Top             =   840
      Width           =   975
   End
   Begin VB.TextBox Text1 
      BackColor       =   &H00FFFFFF&
      Height          =   375
      Left            =   4200
      TabIndex        =   2
      Text            =   "Text1"
      Top             =   360
      Width           =   975
   End
   Begin RichTextLib.RichTextBox RichTextBox1 
      Height          =   3735
      Left            =   240
      TabIndex        =   1
      Top             =   0
      Width           =   1455
      _ExtentX        =   2566
      _ExtentY        =   6588
      _Version        =   393217
      TextRTF         =   $"gray.frx":AAA1
   End
   Begin VB.CommandButton Command1 
      Caption         =   "start"
      Height          =   375
      Left            =   5880
      MouseIcon       =   "gray.frx":AB30
      MousePointer    =   99  'Custom
      TabIndex        =   0
      Top             =   1560
      Width           =   1095
   End
   Begin VB.Label Label4 
      BackStyle       =   0  'Transparent
      Caption         =   "complete!"
      ForeColor       =   &H00FF00FF&
      Height          =   255
      Left            =   3480
      TabIndex        =   10
      Top             =   3600
      Width           =   975
   End
   Begin VB.Image Image1 
      Appearance      =   0  'Flat
      Height          =   480
      Left            =   2160
      Picture         =   "gray.frx":AE3A
      Top             =   3360
      Width           =   480
   End
   Begin VB.Label Label3 
      ForeColor       =   &H0000FF00&
      Height          =   300
      Left            =   3000
      TabIndex        =   7
      Top             =   3480
      Width           =   330
   End
   Begin VB.Label Label2 
      BackStyle       =   0  'Transparent
      Caption         =   "number:"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   10.5
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00FF00FF&
      Height          =   375
      Left            =   2880
      TabIndex        =   5
      Top             =   840
      Width           =   855
   End
   Begin VB.Label Label1 
      BackStyle       =   0  'Transparent
      Caption         =   "n:"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   15.75
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00FF00FF&
      Height          =   375
      Left            =   2880
      TabIndex        =   3
      Top             =   360
      Width           =   375
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Public str As Variant
Public k
Public k1, n1


Option Base 1
Public Function graysort(n)
 k = 1
For i = 1 To (n + 1)
k = k * 2
Next i
 
 Dim m
 Dim c() As String
 m = k / 2
 ReDim c(1 To m)
 Dim d() As String
 ReDim d(1 To k / 2)
 For i = 1 To k / 2
  d(i) = str(i)
  
  c(i) = d(i) & "1"
  str(i) = str(i) & "0"
 Next i
 For i = k / 2 + 1 To k
  str(i) = c(m)
  m = m - 1
 Next i
 
End Function

Public Function gray(n)

k1 = n
If n = 2 Then
 str(1) = "00"
 str(2) = "01"
 str(3) = "11"
 str(4) = "10"

'For i = 1 To k
'RichTextBox1.Text = RichTextBox1.Text + str(i) + Chr(13)
'Next i
End If
If n >= 3 Then

gray (n - 1)
graysort (k1)
k1 = k1 + 1
End If

End Function

'Public Function cl()
'c = Split(RichTextBox1.Text, Chr(13))
'Text3.Text = c(0)
'For j = 0 To (UBound(c) - 1)
'i = 1
'Do While (Mid(c(j), i, 1) = Mid(c(j + 1), i, 1))
' i = i + 1
'Loop
'With RichTextBox1
' .SelStart = InStr(RichTextBox1.Text, c(j)) + i - 1
' .SelLength = 1
' .SelColor = &HFF&
 '.SelStart = InStr(RichTextBox1.Text, c(j + 1)) + i - 1
 '.SelLength = 1
' .SelColor = &HFF&
'End With

'Next j
'End Function

Private Sub command1_Click()

n1 = 0
k = 1
For i = 1 To Val(Text1.Text)
k = k * 2
Next i
Text2.Text = k

n = Val(Text1.Text)
ReDim str(1 To k)

If n = 2 Then
 str = Array("00", "01", "11", "10")
 'str(2) = "01"
 'str(3) = "11"
 'str(4) = "10"
For i = 1 To 4
RichTextBox1.Text = RichTextBox1.Text + str(i) + Chr(13)
Next i
End If


 If n >= 3 Then
   gray (n)
  For i = 1 To k
   RichTextBox1.Text = RichTextBox1.Text + str(i) + Chr(13)
  Next i
 End If
Timer1.Interval = 1000
ProgressBar1.Min = 0
ProgressBar1.Max = Val(Text2.Text)

End Sub




Private Sub Command2_Click()
End
End Sub

Private Sub Form_Load()
Text1.Text = ""
Text2.Text = ""

RichTextBox1.Text = ""

Text1.TabIndex = 0
n = Val(Text1.Text)
Timer1.Interval = 0
Timer2.Interval = 150
Label4.Visible = False
End Sub




Private Sub Timer1_Timer()
j = 1

If (j <= Len(RichTextBox1.Text) / (Val(Text1.Text) + 1) - 15) Then
  With RichTextBox1
     .SelStart = 0
     .SelLength = Val(Text1.Text) + 1
     .SelText = ""
     n1 = n1 + 1
     ProgressBar1.Value = n1 + 15
  End With
Label3.Caption = n1 + 15
j = j + 1
If n1 + 15 = Val(Text2.Text) Then Label4.Visible = True




End If
    
      



End Sub

Private Sub Timer2_Timer()
Form1.Cls
Form1.FontSize = 2


For r = 1 To 100
CurrentX = Form1.Width * Rnd
CurrentY = Form1.Height * Rnd
  Print 1
 
 
Next r
 CurrentX = CurrentX * Rnd
 CurrentY = CurrentY * Rnd
 
 Form1.ForeColor = &HFF0000 * Rnd
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -