| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 607 人关注过本帖
标题:过程太大,能否简化此代码,谢谢
取消只看楼主 加入收藏
向光前进
Rank: 1
等 级:新手上路
帖 子:16
专家分:7
注 册:2011-11-10
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:2 
过程太大,能否简化此代码,谢谢
Private Sub Command2_Click()
    Pic1.Cls
    Dim y()
    l = Val(Text3.Text)
    ReDim y(l * 1000)
    Max = 0
    Maxx = 0
    Min = 0
    Minx1 = 0
 If Combo1.Text = "简支梁" Then
    If Val(Text1.Text) = 1 Then
        If Val(Text2.Text) = 0 And Val(Text11.Text) = 0 Then
            p1 = Arr(1)
            xp1 = Brr(1)
            For i = 0 To l * 1000
                x = i / 1000
                If x < xp1 Then
                    y(i) = Mp11(l, xp1, p1, x)
                Else
                    y(i) = Mp12(l, xp1, p1, x)
                End If
                If y(i) > Max Then
                    Max = y(i)
                    Maxx = x
                End If
            Next i
  'frm扭转计算.Print Max
            坐标系1 l, Max, Maxx  '调用的上面的建坐标系的函数,很好
            For i = 0 To l * 1000
                x = i / 1000
                Pic1.PSet (x, y(i))
                If i Mod (50 * l) = 0 Then Pic1.Line (x, y(i))-(x, 0), vbBlack
            Next i
                Max = 0
                Maxx = 0
                Min = 0
                Minx1 = 0
                For i = 0 To l * 1000
                x = i / 1000
                Select Case x
                    Case Is <= xp1
                        y(i) = Fp11(l, xp1, p1, x)
                    Case Else
                        y(i) = Fp12(l, xp1, p1, x)
                End Select
                 If y(i) > Max Then
                    Max = y(i)
                    Maxx = x
                ElseIf y(i) < Min Then
                    Min = y(i)
                    Minx1 = x
                End If
            Next i
                 If Abs(Max) > Abs(Min) Then
                    坐标系3 l, Max, Maxx
                 Else
                    坐标系4 l, Min, Minx1
                 End If
               For i = 0 To l * 1000
                x = i / 1000
                 If i = 0 Then
                    Pic2.PSet (x, y(i))
                Else
                    Pic2.Line (x, y(i))-(x - 1 / 1000, y(i - 1)), vbBlack
                    If i = l * 1000 Then Pic2.Line (x, y(i))-(x, 0), vbBlack
                End If
                If i Mod (50 * l) = 0 Then
                    Pic2.Line (x, y(i))-(x, 0), vbBlue
                End If
            Next i
 ' Unload frm集中力偶
        ElseIf Val(Text2.Text) = 1 Then  '有一个集中力和一个均布力的时候
            p1 = Arr(1)
            xp1 = Brr(1)
            q1 = Crr(1)
            xq1 = Drr(1)
            lq1 = Err(1) 'err似乎是错误专用?
        If xp1 <= xq1 Then   '此处要有三种情况
            For i = 0 To l * 1000
                x = i / 1000
                Select Case x
                    Case Is < xp1
                        y(i) = Mp11(l, xp1, p1, x) + Mq11(l, xq1, lq1, q1, x)
                    Case Is < xq1
                        y(i) = Mp12(l, xp1, p1, x) + Mq11(l, xq1, lq1, q1, x)
                    Case Is < (xq1 + lq1)
                        y(i) = Mp12(l, xp1, p1, x) + Mq12(l, xq1, lq1, q1, x)
                    Case Else
                        y(i) = Mp12(l, xp1, p1, x) + Mq13(l, xq1, lq1, q1, x)
                End Select
                If y(i) > Max Then
                    Max = y(i)
                    Maxx = x
                End If
            Next i   'for...next i   不能与if语句交叉,否则会出错的
             坐标系1 l, Max, Maxx
            For i = 0 To l * 1000
                x = i / 1000
                Pic1.PSet (x, y(i))
                If i Mod (50 * l) = 0 Then Pic1.Line (x, y(i))-(x, 0), vbBlack
            Next i
                Max = 0
                Maxx = 0
                Min = 0
                Minx1 = 0
                For i = 0 To l * 1000
                x = i / 1000
                Select Case x
                    Case Is <= xp1
                        y(i) = Fp11(l, xp1, p1, x) + Fq11(l, xq1, lq1, q1, x)
                    Case Is <= xq1
                        y(i) = Fp12(l, xp1, p1, x) + Fq11(l, xq1, lq1, q1, x)
                    Case Is <= xq1 + lq1
                        y(i) = Fp12(l, xp1, p1, x) + Fq12(l, xq1, lq1, q1, x)
                    Case Else
                        y(i) = Fp12(l, xp1, p1, x) + Fq13(l, xq1, lq1, q1, x)
                End Select
                 If y(i) > Max Then
                    Max = y(i)
                    Maxx = x
                ElseIf y(i) < Min Then
                    Min = y(i)
                    Minx1 = x
                End If
            Next i
                 If Abs(Max) > Abs(Min) Then
                    坐标系3 l, Max, Maxx
                 Else
                    坐标系4 l, Min, Minx1
                 End If
               For i = 0 To l * 1000
                x = i / 1000
                 If i = 0 Then
                    Pic2.PSet (x, y(i))
                Else
                    Pic2.Line (x, y(i))-(x - 1 / 1000, y(i - 1)), vbBlack
                    If i = l * 1000 Then Pic2.Line (x, y(i))-(x, 0), vbBlack
                End If
                If i Mod (50 * l) = 0 Then
                    Pic2.Line (x, y(i))-(x, 0), vbBlue
                End If
            Next i
         ElseIf xp1 >= xq1 And xp1 <= (xq1 + lq1) Then
            For i = 0 To l * 1000
            x = i / 1000
            Select Case x
            Case Is < xq1
                 y(i) = Mp11(l, xp1, p1, x) + Mq11(l, xq1, lq1, q1, x)
            Case Is < xp1
                 y(i) = Mp11(l, xp1, p1, x) + Mq12(l, xq1, lq1, q1, x)
            Case Is < xq1 + lq1
                 y(i) = Mp12(l, xp1, p1, x) + Mq12(l, xq1, lq1, q1, x)
            Case Else
                y(i) = Mp12(l, xp1, p1, x) + Mq13(l, xq1, lq1, q1, x)
            End Select
                If y(i) > Max Then
                    Max = y(i)
                    Maxx = x
                End If
            Next i   'for...next i   不能与if语句交叉,否则会出错的
             坐标系1 l, Max, Maxx
            For i = 0 To l * 1000
                x = i / 1000
                Pic1.PSet (x, y(i))
                If i Mod (50 * l) = 0 Then Pic1.Line (x, y(i))-(x, 0), vbBlack
            Next i
                Max = 0
                Maxx = 0
                Min = 0
                Minx1 = 0
                For i = 0 To l * 1000
                x = i / 1000
                Select Case x
                    Case Is <= xq1
                        y(i) = Fp11(l, xp1, p1, x) + Fq11(l, xq1, lq1, q1, x)
                    Case Is <= xp1
                        y(i) = Fp11(l, xp1, p1, x) + Fq12(l, xq1, lq1, q1, x)
                    Case Is <= xq1 + lq1
                        y(i) = Fp12(l, xp1, p1, x) + Fq12(l, xq1, lq1, q1, x)
                    Case Else
                        y(i) = Fp12(l, xp1, p1, x) + Fq13(l, xq1, lq1, q1, x)
                End Select
                 If y(i) > Max Then
                    Max = y(i)
                    Maxx = x
                ElseIf y(i) < Min Then
                    Min = y(i)
                    Minx1 = x
                End If
            Next i
                 If Abs(Max) > Abs(Min) Then
                    坐标系3 l, Max, Maxx
                 Else
                    坐标系4 l, Min, Minx1
                 End If
               For i = 0 To l * 1000
                x = i / 1000
                 If i = 0 Then
                    Pic2.PSet (x, y(i))
                Else
                    Pic2.Line (x, y(i))-(x - 1 / 1000, y(i - 1)), vbBlack
                    If i = l * 1000 Then Pic2.Line (x, y(i))-(x, 0), vbBlack
                End If
                If i Mod (50 * l) = 0 Then
                    Pic2.Line (x, y(i))-(x, 0), vbBlue
                End If
            Next i
         Else
            For i = 0 To l * 1000
            x = i / 1000
            Select Case x
                    Case Is < xq1
                        y(i) = Mp11(l, xp1, p1, x) + Mq11(l, xq1, lq1, q1, x)
                    Case Is < xq1 + lq1
                        y(i) = Mp11(l, xp1, p1, x) + Mq12(l, xq1, lq1, q1, x)
                    Case Is < xp1
                        y(i) = Mp11(l, xp1, p1, x) + Mq13(l, xq1, lq1, q1, x)
                    Case Else
                        y(i) = Mp12(l, xp1, p1, x) + Mq13(l, xq1, lq1, q1, x)
                End Select
                   If y(i) > Max Then
                    Max = y(i)
                    Maxx = x
                End If
            Next i   'for...next i   不能与if语句交叉,否则会出错的
             坐标系1 l, Max, Maxx
            For i = 0 To l * 1000
                x = i / 1000
                Pic1.PSet (x, y(i))
                If i Mod (50 * l) = 0 Then Pic1.Line (x, y(i))-(x, 0), vbBlack
            Next i
                Max = 0
                Maxx = 0
                Min = 0
                Minx1 = 0
                For i = 0 To l * 1000
                x = i / 1000
                Select Case x
                    Case Is <= xq1
                        y(i) = Fp11(l, xp1, p1, x) + Fq11(l, xq1, lq1, q1, x)
                    Case Is <= xq1 + lq1
                        y(i) = Fp11(l, xp1, p1, x) + Fq12(l, xq1, lq1, q1, x)
                    Case Is <= xp1
                        y(i) = Fp11(l, xp1, p1, x) + Fq13(l, xq1, lq1, q1, x)
                    Case Else
                        y(i) = (-xp1 * p1) / l - (q1 * lq1 * (xq1 + (lq1 / 2))) / l
                End Select
                 If y(i) > Max Then
                    Max = y(i)
                    Maxx = x
                ElseIf y(i) < Min Then
                    Min = y(i)
                    Minx1 = x
                End If
            Next i
                 If Abs(Max) > Abs(Min) Then
                    坐标系3 l, Max, Maxx
                 Else
                    坐标系4 l, Min, Minx1
                 End If
               For i = 0 To l * 1000
                x = i / 1000
                 If i = 0 Then
                    Pic2.PSet (x, y(i))
                Else
                    Pic2.Line (x, y(i))-(x - 1 / 1000, y(i - 1)), vbBlack
                    If i = l * 1000 Then Pic2.Line (x, y(i))-(x, 0), vbBlack
                End If
                If i Mod (50 * l) = 0 Then
                    Pic2.Line (x, y(i))-(x, 0), vbBlue
                End If
            Next i
             End If
    End If
End If
搜索更多相关主题的帖子: 过程 谢谢 
2011-11-28 21:43
向光前进
Rank: 1
等 级:新手上路
帖 子:16
专家分:7
注 册:2011-11-10
收藏
得分:0 
以下是引用仁力在2011-12-1 16:51:41的发言:

把它拆开来,分拆成一个一个小的sub,就可以了。
高手,我学vb不长时间,现在还处在菜鸟阶段,高手能否帮忙举个例子,给简化一下代码啊?问了一个多星期没啥收获,跪求高手帮忙,万分感激,谢谢
2011-12-01 18:38
向光前进
Rank: 1
等 级:新手上路
帖 子:16
专家分:7
注 册:2011-11-10
收藏
得分:0 
回复 4楼 风吹过b
高手,您好,谢谢您之前给我的提示,谢谢您。
我学习vb时间不长参数的选择不会,所以想高手给举个具体的例子或者简化一下我的代码可以学习一下,可是发了帖子没怎么有回复的,谢谢高手您的回复,谢谢您
2011-12-02 15:21
快速回复:过程太大,能否简化此代码,谢谢
数据加载中...
 
   



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

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