| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1010 人关注过本帖
标题:小白新来的,请教大神:为啥每次点击运行命令按钮,程序就无响应?
只看楼主 加入收藏
梵蒂冈f3
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2013-5-30
结帖率:100%
收藏
已结贴  问题点数:10 回复次数:4 
小白新来的,请教大神:为啥每次点击运行命令按钮,程序就无响应?
本人小白,谢谢大家的帮助~
程序界面如下:
[attach]71219[/attach]
程序代码如下:
Private Sub Command1_Click()
  Dim o, xi As Integer, g As Integer
  Dim u11, u12 As Integer, u21, u22, theat1 As Integer
  Dim q11, q12, q21, q22, q14, q15, theat2, h1, h2, n, sum1, sum2, sum, e As Integer
  
  Dim t1(1 To 6) As Integer                                        '2种方式的路径时间均值
  Dim t2(1 To 6) As Integer
  Dim d1(1 To 6) As Integer                                        '2种方式的路径时间标准差
  Dim d2(1 To 6) As Integer
  Dim C1(1 To 7) As Integer                                        '路段通行能力
  Dim C2(1 To 7) As Integer
  Dim t01(1 To 7) As Integer                                        '路段自由流时间
  Dim t02(1 To 7) As Integer
  Dim b1(1 To 6) As Integer                                        '2种方式的路径出行时间预算
  Dim b2(1 To 6) As Integer
  Dim p1(1 To 6) As Integer                                        '2种方式的需求在每条路径上的分配概率
  Dim p2(1 To 6) As Integer
  Dim f1(1 To 6) As Integer                                        '2种方式在每条路径上的流量
  Dim f2(1 To 6) As Integer
  Dim f(1 To 6) As Integer                                         '每条路径上的总流量
  Dim x(1 To 7) As Integer                                         '每条路段上的流量
  Dim ta1(1 To 7) As Integer                                       '2种方式的路段出行时间均值
  Dim ta2(1 To 7) As Integer
  Dim da1(1 To 7) As Integer                                       '2种方式的路段出行时间的方差
  Dim da2(1 To 7) As Integer
  Dim y(1 To 7) As Integer                                         '路段辅助流量
  Dim c(1 To 7) As Integer
  
  C1(1) = 3000                                                     '通行能力
  C1(2) = 2600
  C1(3) = 1200
  C1(4) = 1200
  C1(5) = 1200
  C1(6) = 1200
  C1(7) = 1200
  
  C2(1) = 2500
  C2(2) = 2500
  C2(3) = 1500
  C2(4) = 1500
  C2(5) = 1500
  C2(6) = 1500
  C2(7) = 1500
  
  t01(1) = 13                                                       '自由流时间
  t01(2) = 12
  t01(3) = 9
  t01(4) = 15
  t01(5) = 10
  t01(6) = 18
  t01(7) = 14
  
  t02(1) = 10
  t02(2) = 16
  t02(3) = 11
  t02(4) = 13
  t02(5) = 17
  t02(6) = 14
  t02(7) = 12
   
  g = 1.29                                                         '可靠度ρ=0.9时标准正态分布的分位数
  theta1 = 1                                                       '路径选择分散参数
  theta2 = 0.2                                                     '方式选择分散参数
  q14 = 2000                                                       '2个OD对的交通需求
  q15 = 2500
  h1 = 9                                                           '2种方式的吸引力
  h2 = 8
  e = Exp(-2)                                                      '迭代精度
   n = 1                                                           '迭代次数
   sum1 = 0
   sum2 = 0
  
  If Option1.Value = True Then                                      '判断路段a是否在路径k上
   o = 1
  End If
  If Option2.Value = True Then
    o = 0
  End If
                                                                    '初始化
   t1(1) = t01(1) + t01(4)                                          '路径时间均值
   t1(2) = t01(1) + t01(3) + t01(6)
   t1(3) = t01(2) + t01(6)
   t1(4) = t01(1) + t01(5)
   t1(5) = t01(1) + t01(3) + t01(7)
   t1(6) = t01(2) + t01(7)
   d1(1) = 0                                                        '路径时间标准差
   d1(2) = 0
   d1(3) = 0
   d1(4) = 0
   d1(5) = 0
   d1(6) = 0
   
   t2(1) = t02(1) + t02(4)                                          '路径时间均值
   t2(2) = t02(1) + t02(3) + t02(6)
   t2(3) = t02(2) + t02(6)
   t2(4) = t02(1) + t02(5)
   t2(5) = t02(1) + t02(3) + t02(7)
   t2(6) = t02(2) + t02(7)
   d2(1) = 0                                                       '路径时间标准差
   d2(2) = 0
   d2(3) = 0
   d2(4) = 0
   d2(5) = 0
   d2(6) = 0
   
  For i = 1 To 6                                                  '出行时间预算
   b1(i) = t1(i)
   b2(i) = t2(i)
  Next i
                                                                  'OD对(r,s)上方式m的负效用
  u11 = -1 / theta1 * Log(Exp(-theta1 * b1(1)) + Exp(-theta1 * b1(2)) + Exp(-theta1 * b1(3)))
  u12 = -1 / theta1 * Log(Exp(-theta1 * b1(4)) + Exp(-theta1 * b1(5)) + Exp(-theta1 * b1(6)))
  u21 = -1 / theta1 * Log(Exp(-theta1 * b2(1)) + Exp(-theta1 * b2(2)) + Exp(-theta1 * b2(3)))
  u22 = -1 / theta1 * Log(Exp(-theta1 * b2(4)) + Exp(-theta1 * b2(5)) + Exp(-theta1 * b2(6)))
                                                                  
                                                                  'OD对(r,s)上方式m的需求
  q11 = q14 * Exp(-theta2 * (u11 - h1)) / (Exp(-theta2 * (u11 - h1)) + Exp(-theta2 * (u21 - h2)))
  q12 = q15 * Exp(-theta2 * (u12 - h1)) / (Exp(-theta2 * (u12 - h1)) + Exp(-theta2 * (u22 - h2)))
  q21 = q14 - q11
  q22 = q15 - q12

  For i = 1 To 3                                                  '2种方式的需求在每条路径上的分配概率
   p1(i) = Exp(-theta1 * b1(i)) / (Exp(-theta1 * b1(1)) + Exp(-theta1 * b1(2)) + Exp(-theta1 * b1(3)))
   p2(i) = Exp(-theta1 * b2(i)) / (Exp(-theta1 * b2(1)) + Exp(-theta1 * b2(2)) + Exp(-theta1 * b2(3)))
  Next i
  For i = 4 To 6
   p1(i) = Exp(-theta1 * b1(i)) / (Exp(-theta1 * b1(4)) + Exp(-theta1 * b1(5)) + Exp(-theta1 * b1(6)))
   p2(i) = Exp(-theta1 * b2(i)) / (Exp(-theta1 * b2(4)) + Exp(-theta1 * b2(5)) + Exp(-theta1 * b2(6)))
  Next i
   
  For i = 1 To 3                                                   '2种方式在每条路径上的流量
    f1(i) = p1(i) * q11
    f2(i) = p2(i) * q21
  Next i
  For i = 4 To 6
    f1(i) = p1(i) * q12
    f2(i) = p2(i) * q22
  Next i
  
  For i = 1 To 6                                                   '每条路径上的总流量
   f(i) = f1(i) + f2(i)
  Next i
  
  x(1) = f(1) + f(2) + f(4) + f(5)                                 '每条路段上的总流量
  x(2) = f(3) + f(6)
  x(3) = f(2) + f(5)
  x(4) = f(1)
  x(5) = f(4)
  x(6) = f(2) + f(3)
  x(7) = f(5) + f(6)
   
Start:
  For i = 1 To 7
   ta1(i) = t01(i) + 0.15 * t01(i) * x(i) / C1(i)                  '路段出行时间的均值
   ta2(i) = t02(i) + 0.15 * t02(i) * x(i) / C2(i)
   da1(i) = (0.15 * t01(i) / C1(i)) ^ 2 * (t01(i) - ta1(i)) ^ 2    '路段出行时间的方差
   da2(i) = (0.15 * t02(i) / C2(i)) ^ 2 * (t02(i) - ta2(i)) ^ 2
  Next i
  
   t1(1) = ta1(1) + ta1(4)                                         '方式1在各路径出行时间的均值
   t1(2) = ta1(1) + ta1(3) + ta1(6)
   t1(3) = ta1(2) + ta1(6)
   t1(4) = ta1(1) + ta1(5)
   t1(5) = ta1(1) + ta1(3) + ta1(7)
   t1(6) = ta1(2) + ta1(7)
   d1(1) = Sqr(da1(1) + da1(4))                                    '方式1在各路径出行时间的标准差
   d1(2) = Sqr(da1(1) + da1(3) + da1(6))
   d1(3) = Sqr(da1(2) + da1(6))
   d1(4) = Sqr(da1(1) + da1(5))
   d1(5) = Sqr(da1(1) + da1(3) + da1(7))
   d1(6) = Sqr(da1(2) + da1(7))
   
   t2(1) = ta2(1) + ta2(4)                                         '方式2在各路径出行时间的均值
   t2(2) = ta2(1) + ta2(3) + ta2(6)
   t2(3) = ta2(2) + ta2(6)
   t2(4) = ta2(1) + ta2(5)
   t2(5) = ta2(1) + ta2(3) + ta2(7)
   t2(6) = ta2(2) + ta2(7)
   d2(1) = Sqr(da2(1) + da2(4))                                    '方式2在各路径出行时间的标准差
   d2(2) = Sqr(da2(1) + da2(3) + da2(6))
   d2(3) = Sqr(da2(2) + da2(6))
   d2(4) = Sqr(da2(1) + da2(5))
   d2(5) = Sqr(da2(1) + da2(3) + da2(7))
   d2(6) = Sqr(da2(2) + da2(7))
   
  For i = 1 To 6                                                  '出行时间预算
   b1(i) = t1(i) + d1(i) * o
   b2(i) = t2(i) + d2(i) * o
  Next i
                                                                  'OD对(r,s)上方式m的负效用
  u11 = -1 / theta1 * Log(Exp(-theta1 * b1(1)) + Exp(-theta1 * b1(2)) + Exp(-theta1 * b1(3)))
  u12 = -1 / theta1 * Log(Exp(-theta1 * b1(4)) + Exp(-theta1 * b1(5)) + Exp(-theta1 * b1(6)))
  u21 = -1 / theta1 * Log(Exp(-theta1 * b2(1)) + Exp(-theta1 * b2(2)) + Exp(-theta1 * b2(3)))
  u22 = -1 / theta1 * Log(Exp(-theta1 * b2(4)) + Exp(-theta1 * b2(5)) + Exp(-theta1 * b2(6)))
                                                                  
                                                                  'OD对(r,s)上方式m的需求
  q11 = q14 * Exp(-theta2 * (u11 - h1)) / (Exp(-theta2 * (u11 - h1)) + Exp(-theta2 * (u21 - h2)))
  q12 = q15 * Exp(-theta2 * (u12 - h1)) / (Exp(-theta2 * (u12 - h1)) + Exp(-theta2 * (u22 - h2)))
  q21 = q14 - q11
  q22 = q15 - q12
   
  For i = 1 To 3                                                  '2种方式的需求在每条路径上的分配概率
   p1(i) = Exp(-theta1 * b1(i)) / (Exp(-theta1 * b1(1)) + Exp(-theta1 * b1(2)) + Exp(-theta1 * b1(3)))
   p2(i) = Exp(-theta1 * b2(i)) / (Exp(-theta1 * b2(1)) + Exp(-theta1 * b2(2)) + Exp(-theta1 * b2(3)))
  Next i
  For i = 4 To 6
   p1(i) = Exp(-theta1 * b1(i)) / (Exp(-theta1 * b1(4)) + Exp(-theta1 * b1(5)) + Exp(-theta1 * b1(6)))
   p2(i) = Exp(-theta1 * b2(i)) / (Exp(-theta1 * b2(4)) + Exp(-theta1 * b2(5)) + Exp(-theta1 * b2(6)))
  Next i
   
  For i = 1 To 3                                                   '2种方式在每条路径上的流量
    f1(i) = p1(i) * q11
    f2(i) = p2(i) * q21
  Next i
  For i = 4 To 6
    f1(i) = p1(i) * q12
    f2(i) = p2(i) * q22
  Next i
  
  For i = 1 To 6                                                   '每条路径上的总流量
   f(i) = f1(i) + f2(i)
  Next i
  
  y(1) = f(1) + f(2) + f(4) + f(5)                                 '路段上的辅助流量
  y(2) = f(3) + f(6)
  y(3) = f(2) + f(5)
  y(4) = f(1)
  y(5) = f(4)
  y(6) = f(2) + f(3)
  y(7) = f(5) + f(6)
  
 For i = 1 To 7
  c(i) = x(i)                                                       '将路段流量赋值给c(i)
  x(i) = x(i) + (y(i) - x(i)) / n                                   '加权后的路段流量
 Next i
  
 For i = 1 To 7
  sum1 = sum1 + c(i)
  sum2 = sum2 + (x(i) - c(i)) ^ 2
 Next i
 sum = Sqr(sum2) / (sum1 + 1)
  If sum < e Then                                                     '停止迭代检验
  GoTo Finish
  Else
    n = n + 1
  End If
  GoTo Start                                                          '返回第继续迭代
Finish:
   Text1.Text = q11
   Text2.Text = q21
   Text3.Text = q12
   Text4.Text = q22
   Text5.Text = q11 / q14
   Text6.Text = 1 - Text5.Text
   Text7.Text = q12 / q15
   Text8.Text = 1 - Text7.Text
   Text9.Text = x(1)
   Text10.Text = x(2)
   Text11.Text = x(3)
   Text12.Text = x(4)
   Text13.Text = x(5)
   Text14.Text = x(6)
   Text15.Text = x(7)
   Text16.Text = n
End Sub


[ 本帖最后由 梵蒂冈f3 于 2013-5-30 23:38 编辑 ]
搜索更多相关主题的帖子: 标准差 
2013-05-30 11:30
梵蒂冈f3
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2013-5-30
收藏
得分:0 
大家帮忙看看吧、、是不是for 语句不对?
2013-05-30 12:13
wxflw
Rank: 6Rank: 6
等 级:侠之大者
帖 子:325
专家分:435
注 册:2012-1-29
收藏
得分:10 
你按F8调试看看哪里出错了再说

学习--------------学习-------------------学习--------------------!!
2013-05-30 20:32
梵蒂冈f3
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2013-5-30
收藏
得分:0 
回复 3楼 wxflw
按F8调试了都没问题,
2013-05-30 23:36
梵蒂冈f3
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2013-5-30
收藏
得分:0 
谢谢大家。已经解决了~定义的时候定义的类型错了。换成Double就OK了。
2013-05-31 01:29
快速回复:小白新来的,请教大神:为啥每次点击运行命令按钮,程序就无响应?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.025442 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved