在vbscript中找到10个最大的数字

问题描述 投票:-2回答:1

我刚刚创建了vbscript代码,以便从10个输入数字中找到最大的数字。它仅适用于1到10之间的数字。为什么?

<html>
<head>
    <title>Enter 10 numbers to find the largest number</title>
    <meta http-equiv="x-ua-compatible" content="IE=10">
</head>

<body>
<script language = "vbscript" type = "text/vbscript">
    Dim n1 
    Dim n2
    Dim n3
    Dim n4
    Dim n5
    Dim n6
    Dim n7
    Dim n8
    Dim n9
    Dim n10
    Dim largest
    n1=inputBox("please Enter the  number1 ","number1")
    n2=inputBox("please Enter the  number2 ","number2")
    n3=inputBox("please Enter the  number3 ","number3")
    n4=inputBox("please Enter the  number4 ","number4")
    n5=inputBox("please Enter the  number5 ","number5")
    n6=inputBox("please Enter the  number6 ","number6")
    n7=inputBox("please Enter the  number7 ","number7")
    n8=inputBox("please Enter the  number8 ","number8")
    n9=inputBox("please Enter the  number9 ","number9")
    n10=inputBox("please Enter the  number10 ","number10")

    If (n1>n2 AND num1>vnum3 AND n1>n4 AND n1>n5 AND n1>n6 AND n1>n7 AND n1>n8 AND n1>n9 AND n1>n10 ) then
         document.write("this is the largest number " & n1 & ", Enjoy VBscript")
    ElseIf (n2>n1 AND n2>n3 AND n2>n4 AND n2>n5 AND n2>n6 AND n2>n7 AND n2>n8 AND n2>n9 AND n2>n10 ) Then
         document.write("this is the largest number " & n2 & ", Enjoy VBscript")
    ElseIf (n3>n1 AND n3>n2 AND n3>n4 AND n3>n5 AND n3>n6 AND n3>n7 AND n3>n8 AND n3>n9 AND n3>n10 ) Then
         document.write("this is the largest number " & n3 & ", Enjoy VBscript")
    ElseIf (n4>n1 AND n4>n3 AND n4>n2 AND n4>n5 AND n4>n6 AND n4>n7 AND n4>n8 AND n4>n9 AND n4>n10 ) Then
         document.write("this is the largest number " & n4 & ", Enjoy VBscript")
    ElseIf (n5>n1 AND n5>n3 AND n5>n4 AND n5>n2 AND n5>n6 AND n5>n7 AND n5>n8 AND n5>n9 AND n5>n10 ) Then
         document.write("this is the largest number " & n5 & ", Enjoy VBscript")
    ElseIf (n6>n1 AND n6>n3 AND n6>n4 AND n6>n5 AND n6>n2 AND n6>n7 AND n6>n8 AND n6>n9 AND n6>n10 ) Then
         document.write("this is the largest number " & n6 & ", Enjoy VBscript")
    ElseIf (n7>n1 AND n7>n3 AND n7>n4 AND n7>n5 AND n7>n6 AND n7>n2 AND n7>n8 AND n7>n9 AND n7>n10 ) Then
         document.write("this is the largest number " & n7 & ", Enjoy VBscript")
    ElseIf (n8>n1 AND n8>n3 AND n8>n4 AND n8>n5 AND n8>n6 AND n8>n7 AND n8>n2 AND n8>n9 AND n8>n10 ) Then
         document.write("this is the largest number " & n8 & ", Enjoy VBscript")
    ElseIf (n9>n1 AND n9>n3 AND n9>n4 AND n9>n5 AND n9>n6 AND n9>n7 AND n9>n8 AND n9>n2 AND n9>n10 ) Then
         document.write("this is the largest number " & n9 & ", Enjoy VBscript")
    ElseIf (n10>n1 AND n10>n3 AND n10>n4 AND n10>n5 AND n10>n6 AND n10>n7 AND n10>n8 AND n10>n9 AND n10>n2 ) Then
         document.write("this is the largest number " & n10 & ", Enjoy VBscript")
    Else
         document.write("this is the largest number is  " & number10 & ", Enjoy VBscript")
    End If
</script>
</body>
</html>
vbscript
1个回答
-2
投票

这将事物放入循环并使用一个排序的对象。

'Getting the 10 numbers
Dim Thing(10)
For x = 0 to 9
    Thing(x) = InputBox("Something")
Next

Set rs = CreateObject("ADODB.Recordset")
With rs
    'Setting up a one field database containing a single precision field called Numbers
    .Fields.Append "Number", 4 
    .Open

    'Adding the data
    For x = 0 to 9
        .AddNew
        .Fields("Number").value = Thing(x)
        .UpDate
    Next

    'Sorting descending on number field
    .Sort = "Number DESC"

    'Now write it
    MsgBox .Fields("Number").Value
    'And the second one
    .MoveNext
    MsgBox .Fields("Number").Value

    'And all the rest
    For x = 0 to 7
        .MoveNext
        MyStr = MyStr & .Fields("Number").Value & vbcrlf
    Next
    MsgBox MyStr
End With
© www.soinside.com 2019 - 2024. All rights reserved.