Private Sub agerule()
If sexisman = True Then
  If age <= 50 Then
    power = age
  Else
    power = 100 - age
  End If
  If age <= 60 Then
  politics = age
  Else
  politics = 60
  End If
  If age <= 30 Then
  intelligence = age
  Else
  intelligence = 60 - age
  End If
  If age <= 40 Then
  command = age
  Else
    If 40 < age <= 60 Then
    command = 40
    Else
    command = 100 - age
    End If
  End If
  If age <= 30 Then
  beauty = age
  Else
  beauty = 60 - age
  End If
Else
  If age <= 30 Then
  power = age
  Else
    If 30 < age <= 60 Then
    power = 30
    Else
    power = 90 - age
    End If
  End If
  If age <= 50 Then
  politics = age
  Else
  politics = 50
  End If
  If age <= 30 Then
  intelligence = age
  Else
    If 30 < age <= 40 Then
    intelligence = 30
    Else
    intelligence = 70 - age
    End If
  End If
  If age <= 30 Then
  command = age
  Else
  command = 30
  End If
  If age <= 24 Then
  beauty = 2 * age
  Else
    If 24 < age <= 30 Then
    beauty = 48
    Else
    beauty = 78 - age
    End If
  End If
End If
End Sub
变量说明  age 年龄 beauty 魅力 power 武力 intelligence 智力 command 统率 politics 政治 sexisman 性别  true 男性 false 女性
算法描述  分析 年龄因性别的不同对各项能力的影响
问题所在 ,凡设计到elseif 的分支if语句 ,减法运算无法实现 。
举例 女性的beuty减法计算失效。 

解决方案 »

  1.   

    明显的错误了如果age小于或等于50则power=age,否则powser=100-age,你这里和后面的的设计就存在问题了If age <= 50 Then
        power = age
      Else
        power = 100 - age
      End If
      If age <= 60 Then
      politics = age
      Else
      politics = 60
      End If
      If age <= 30 Then
      intelligence = age
      Else
      intelligence = 60 - age
      End If我不知道你要做的是不是这样:
    If age <= 50 Then
        power = age
    Elseif age <= 60 Then
    '    your code
    elseif xxxx
    ....
    else
        power = 100 - age
    End If如果是这样应该是从小的开始判断,再说一点,写软件重在一个活的思路,一个好的代码风格。
    你的思路很杂,一看就知道是没有看过多少数据结构,没有看过程序开发基础知识的人。
    你就相当于写流水账,想到什么就写什么,没有一个方案,没有一个框来写的
      

  2.   

    这个用得着这么嵌套吗?一个属性就是一个IFTHEN。ELSE。ENDIF。
    为什么弄得这么麻烦。
      

  3.   

    我的天 ,我要疯了 。
    我把各项能力分开写了, 
    结果第一次测试  
    女性的魅力  就  出了问题
    当年龄等于31时 , 魅力还是停在了 上限48 
    应该是78-31=47的
    If sexisman = True Then     '性别对魅力的影响
       If age <= 30 Then
       beauty = age
       ElseIf 30 < age <= 40 Then
       beauty = 30
       Else
       beauty = 70 - age
       End If
    Else
       If age <= 24 Then
       beauty = 2 * age
       Else
         If 24 < age <= 30 Then
         beauty = 48
         Else
         beauty = 78 - age
         End If
       End If
    End If
    End Sub
      

  4.   

    ElseIf 30 < age <= 40 Then ???
    If 24 < age <= 30 Then ???
    好好看看VB逻辑判断语句的语法吧^_^
      

  5.   

    哎,问题终于解决了, 还是出了语法错误啊, 感谢caozhy的提醒 
      30<age<50  要 改成  if age<30 and age>20 
    不过还是很感谢给我提意见的人 ,的确数据结构很重要 。