注册 登录
编程论坛 VB6论坛

VB新手求教两个问题

jeese9 发布于 2018-05-30 01:42, 1251 次点击
问题1:我要给一个变量赋值为1,让它持续1分钟或者2分钟之类(假设为X),然后使这个变量变为0,之后一直为0,求大神怎么编。
问题2:像下图这样能用VB语言使一个变量能以这样的趋势变化(具体值只要个大概,我会自己之后修改),大神最好能编两个不太接近的趋势。
只有本站会员才能查看附件,请 登录
2 回复
#2
wds12018-05-30 05:52
Public a

Private Sub Command1_Click()
MsgBox (a) '显示变量
End Sub

Private Sub Form_Load()
a = 1
Timer1.Interval = 1000 * 10 '定时器10秒
X1 = Array(0, 1000, 1100, 2500, 2800, 2900, 3100, 3300, 4300, 4400, 6000, 6200, 6300, 6400, 6600)
Y1 = Array(1000, 1000, 1500, 2000, 4000, 7000, 6000, 1000, 1000, 2200, 3200, 5000, 7000, 6000, 1500)
Show
For i = 0 To 13 '划线
Line (X1(i), Y1(i))-(X1(i + 1), Y1(i + 1)), vbRed
Next
End Sub

Private Sub Timer1_Timer()
a = 0
Timer1.Interval = 0 '10秒后关闭定时器
End Sub
#3
wufuzhang2018-06-05 11:17
回复 楼主 jeese9
窗体添加一个Timer控件和一个CWgraph控件(注册并加载Cwui.ocx)
只有本站会员才能查看附件,请 登录

Option Explicit
Dim i%, r%
Dim TimeX()
Dim YAxis1()
Dim YAxis2()

Private Sub Form_Load()
  Timer1.Interval = 1000
End Sub

Private Sub Timer1_Timer()
  i = i + 1
  ReDim Preserve TimeX(0 To i - 1)
  ReDim Preserve YAxis1(0 To i - 1)
  ReDim Preserve YAxis2(0 To i - 1)
  TimeX(i - 1) = i - 1
  If TimeX(i - 1) < 60 Then
     YAxis1(i - 1) = 1
  Else
     YAxis1(i - 1) = 0
  End If
  r = (i - 1) Mod 30
  If r = 0 Then
     YAxis2(i - 1) = 2
  ElseIf r >= 1 And r <= 11 Then
     YAxis2(i - 1) = 8
  ElseIf r > 11 And r <= 20 Then
     YAxis2(i - 1) = 10 - 0.2 * r
  ElseIf r > 20 And r < 30 Then
     YAxis2(i - 1) = 14 - 0.4 * r
  End If
  CWGraph1.Plots(1).PlotXvsY TimeX, YAxis1
  CWGraph1.Plots(2).PlotXvsY TimeX, YAxis2
End Sub
1