vb中设计有字幕的label向右移动,碰到右边边界后向左移动,循环。。。
PrivateSubCommand1_Click()Timer1=TrueEndSubPrivateSubForm_Load()x=1EndSubPrivateSubTi...
Private Sub Command1_Click()Timer1 = True
End Sub
Private Sub Form_Load()x = 1End Sub
Private Sub Timer1_Timer()Dim a As IntegerLabel1.Left = Label1.Left + 10 * aIf Label1.Left >= Form1.Width - Label1.Width Thena = -1Else: a = 1End IfTimer1 = FalseEnd Sub
我运行后label并没有移动,哪里出了问题呢?
Private Sub Command1_Click()Timer1 = True
End Sub
Private Sub Form_Load()x = 1End Sub
Private Sub Timer1_Timer()Dim a As IntegerLabel1.Left = Label1.Left + 10 * aIf Label1.Left >= Form1.Width - Label1.Width Thena = -1Else: a = 1End IfTimer1 = FalseEnd Sub 展开
End Sub
Private Sub Form_Load()x = 1End Sub
Private Sub Timer1_Timer()Dim a As IntegerLabel1.Left = Label1.Left + 10 * aIf Label1.Left >= Form1.Width - Label1.Width Thena = -1Else: a = 1End IfTimer1 = FalseEnd Sub
我运行后label并没有移动,哪里出了问题呢?
Private Sub Command1_Click()Timer1 = True
End Sub
Private Sub Form_Load()x = 1End Sub
Private Sub Timer1_Timer()Dim a As IntegerLabel1.Left = Label1.Left + 10 * aIf Label1.Left >= Form1.Width - Label1.Width Thena = -1Else: a = 1End IfTimer1 = FalseEnd Sub 展开
展开全部
已测试通过
Dim flag As Boolean
Private Sub Timer1_Timer()
Call yidong
End Sub
Sub yidong()
If flag = False Then
Label1.Left = Label1.Left + 10
If Label1.Left >= Form1.Width - Label1.Width Then
flag = True
End If
Else
Label1.Left = Label1.Left - 10
If Label1.Left = 0 Then
flag = False
End If
End If
End Sub
Dim flag As Boolean
Private Sub Timer1_Timer()
Call yidong
End Sub
Sub yidong()
If flag = False Then
Label1.Left = Label1.Left + 10
If Label1.Left >= Form1.Width - Label1.Width Then
flag = True
End If
Else
Label1.Left = Label1.Left - 10
If Label1.Left = 0 Then
flag = False
End If
End If
End Sub
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
问题在于:
1、变量不是定义好的,每次都是清掉的;
2、你只判断了向左过界,没有回去的;
我帮你改了一下,你看下:
Private a As Integer '全局定义 Private Sub Command1_Click()If Timer1 = True Then Timer1 = FalseElse Timer1 = TrueEnd IfEnd Sub Private Sub Form_Load()a = 1Timer1 = FalseTimer1.Interval = 10End SubPrivate Sub Timer1_Timer()
Label1.Left = Label1.Left + 10 * aIf a = 1 ThenIf Label1.Left >= Form1.Width - Label1.Width - 20 Then a = -1ElseIf Label1.Left <= 10 Then a = 1End IfEnd Sub
1、变量不是定义好的,每次都是清掉的;
2、你只判断了向左过界,没有回去的;
我帮你改了一下,你看下:
Private a As Integer '全局定义 Private Sub Command1_Click()If Timer1 = True Then Timer1 = FalseElse Timer1 = TrueEnd IfEnd Sub Private Sub Form_Load()a = 1Timer1 = FalseTimer1.Interval = 10End SubPrivate Sub Timer1_Timer()
Label1.Left = Label1.Left + 10 * aIf a = 1 ThenIf Label1.Left >= Form1.Width - Label1.Width - 20 Then a = -1ElseIf Label1.Left <= 10 Then a = 1End IfEnd Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
a是过程变量,每次执行过程时,重新被定义,默认值为0 ,所以不可能动的,放到外面吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你可以不用这个啊。直接用时钟,简单又方便
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询