VB代码求注释
这是贪吃蛇的代码,因为上课没认真听结果都看不懂...现在老师要求给贪吃蛇注释代码.请求各位哥哥姐姐们帮帮小弟吧....
PS:尽可能的每行都要注释..拜托了 >.<
Option Explicit
Dim COL As Integer, CTCO As Integer
Dim CTS As Integer
Private Sub Form_Activate()
SUCCESS = sndPlaySound(App.Path + "\\sound\\start.WAV", &H1)
End Sub
Private Sub Form_Load()
Load FrmSna
CTS = 1
FrmSna.Timer1.Enabled = False
Label1.Top = Picture1.Top + Picture1.Height
CTCO = 2
COL = 0
Me.Picture = LoadPicture("")
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Shape1.Visible = False
End Sub
Private Sub Label1_Click()
Timer1.Enabled = False
Picture1.Visible = False
End Sub
Private Sub OP1_Click()
Me.Hide
FrmSna.Timer1.Enabled = True
FrmSna.Show
End Sub
Private Sub OP1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Shape1.Visible = True
Shape1.Top = 960
End Sub
Private Sub OP2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Shape1.Visible = True
Shape1.Top = 1440
End Sub
Private Sub OP3_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Shape1.Visible = True
Shape1.Top = 1920
End Sub
Private Sub OP2_Click()
Label1.Top = Picture1.Top + Picture1.Height
Picture1.Visible = True
Timer1.Enabled = True
Label1.Caption = Space(10) & "贪吃蛇" & Space(16) & "贪吃蛇小游戏!" & Chr(13) & "操作说明:方向键控制方向、Escape暂停" & Chr(13) & "ZYX"
End Sub
Private Sub Picture1_Click()
Timer1.Enabled = False
Picture1.Visible = False
End Sub
Private Sub Timer1_Timer()
Label1.Top = Label1.Top - 10
If S.Left + S.Width > Me.ScaleLeft + Me.Width Then CTS = 2
If S.Left < Me.ScaleLeft Then CTS = 1
If CTS = 1 Then S.Left = S.Left + 50
If CTS = 2 Then S.Left = S.Left - 50
End Sub
Private Sub Timer2_Timer()
'标题的淡出淡入
If CTCO = 1 Then COL = COL - 5
If CTCO = 2 Then COL = COL + 5
If COL > 240 Then CTCO = 1
If COL < 10 Then CTCO = 2
TXT.ForeColor = RGB(COL, COL, COL)
End Sub
答案:Option Explicit
'如果变量不被定义,在该模块中禁止使用!
Dim COL As Integer, CTCO As Integer '定义变量
Dim CTS As Integer
'定义变量
'可以这样写: dim COL ,CTCO ,CTS as integer
Private Sub Form_Activate()
'当窗口激活时
SUCCESS = sndPlaySound(App.Path + "\\sound\\start.WAV", &H1) '把 SUCCESS 作为返回值 ,并执行 sndPlaySound 子程序或自定义函数
End Sub
Private Sub Form_Load()
'当窗口读取时
Load FrmSna
'读取FRMSNA
CTS = 1
'赋值1到CTS
FrmSna.Timer1.Enabled = False '禁用窗体frmSNA的TIMER1
Label1.Top = Picture1.Top + Picture1.Height '标签LABEL1与窗体顶的距离 = PICTURE1的顶的距离+ PICTURE1的高度
CTCO = 2
'把2赋值到CTCP
COL = 0
'同理
Me.Picture = LoadPicture("")
'设置窗体的图像
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) '当鼠标在窗体上移动时
Shape1.Visible = False
'shape1不可见
End Sub
Private Sub Label1_Click() '当鼠标点击label1的时候
Timer1.Enabled = False
'禁用timer1
Picture1.Visible = False
'同理,禁用Picture1
End Sub
Private Sub OP1_Click()
'当鼠标点击OP1的时候
Me.Hide
'隐藏"我"
FrmSna.Timer1.Enabled = True 'frmSNA的timer1控件不可用
FrmSna.Show
'frmSna显示
End Sub
Private Sub OP1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) '当鼠标在OP1上移动时
Shape1.Visible = True
'shape1可见
Shape1.Top = 960
'shape1与顶的距离为960
End Sub
Private Sub OP2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) '当鼠标在OP2上移动时
Shape1.Visible = True
'shape1可见
Shape1.Top = 1440
'shape1与顶的距离为1440
End Sub
Private Sub OP3_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) '当鼠标在OP3上移动时
Shape1.Visible = True
'shape1可见
Shape1.Top = 1920
'shape1与顶的距离为1920
End Sub
Private Sub OP2_Click()
'单机OP2的时候
Label1.Top = Picture1.Top + Picture1.Height 'LABEL1与窗体顶的距离 = PICTURE1的顶的距离+ PICTURE1的高度
Picture1.Visible = True
'PICTURE1为可见
Timer1.Enabled = True
'timer1为可见
Label1.Caption = Space(10) & "贪吃蛇" & Space(16) & "贪吃蛇小游戏!" & Chr(13) & "操作说明:方向键控制方向、Escape暂停" & Chr(13) & "ZYX" 'label1的caption属性值为 = ..
'space(10) 、Space(16)为输出空格。chr(13)也表空格
'
'
End Sub
Private Sub Picture1_Click() '当点击PCITURE1时
Timer1.Enabled = False
'Timer1不可用
Picture1.Visible = False 'picture1不可见
End Sub
Private Sub Timer1_Timer()
'触发timer1 执行的代码
Label1.Top = Label1.Top - 10
'label1往下移十个单位
If S.Left + S.Width > Me.ScaleLeft + Me.Width Then CTS = 2 '如果s与顶的距离+S的宽度大于 "我"窗体的左水平坐标+"我"的宽则CTS =2
If S.Left < Me.ScaleLeft Then CTS = 1 '如果s与容器左边的距离小于"我"的左水平坐标,则CTS =1
If CTS = 1 Then S.Left = S.Left + 50
'如果CTS =1则S向左移50个单位
If CTS = 2 Then S.Left = S.Left - 50 '如果CTS =2则S向右移50个单位
End Sub
Private Sub Timer2_Timer() '当触发Timer2的时候
'标题的淡出淡入
If CTCO = 1 Then COL = COL - 5 '如果CTCO=1 则COL减5
If CTCO = 2 Then COL = COL + 5 '如果CTCO=2 则COL加5
If COL > 240 Then CTCO = 1
'如果COL大于240 CTCO则等于1
If COL < 10 Then CTCO = 2
'如果COL小于10 CTCO则等于2
TXT.ForeColor = RGB(COL, COL, COL) 'txt的文本色或者图片背景色为RGB(col,col,col)
End Sub 。。。
给个例子慢慢体会!
模块文件registry.bas
Declare Function RegSetValue Lib "advapi32.dll" Alias "RegSetValueA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal dwType As Long, ByVal lpData As String, ByVal cbData As Long) As Long
Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Declare Function RegQueryValue Lib "advapi32.dll" Alias "RegQueryValueA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal lpValue As String, lpcbValue As Long) As Long
Enum RootKey
HKEY_CLASSES_ROOT =
上一个:什么叫做VB
下一个:VB高手来一下