2016-07-10 3 views
-1

私はこの場合、ユーザーがデータを入力する必要があります。私が必要とするのは、ユーザが0より大きく100までの数字を入力できるようにすることです。たとえば、please enter number from 0 to 100のようなメッセージを表示してから、その番号を入力する必要がある場所を再度表示します。ユーザーが100以上の金額を入力しないようにする方法

は例えば、端末内Console.Write("Español: ")は次のとおりです。ユーザーは100以上に入る

Español: ' the user should enter the number here 

場合は、これを表示する:

Please enter number from 0 to 100. Español: ' here enter the number again 

私は次のコードのようにこれを行うに考えていましたIf ... Elseと一緒ですが、もっと良い方法がありますか?ここで

実際のコードです:だから

Sub Main() 
     Dim Español1 As Integer 
     Dim Matematicas1 As Integer 
     Dim Ciencias1 As Integer 
     Dim EstudiosSociales1 As Integer 
     Dim Ingles1 As Integer 
     Dim ArtesPlasticas1 As Integer 
     Dim ArtesIndustriales1 As Integer 

    Select Case Menu 

    Case 2 

     Console.Write("Ingrese las notas: ") 
     Console.ReadLine() 

     Console.Write("Español: ") 
     ' I was thinking on doing this 
     If Console.ReadLine() >= 100 Then 
      Console.Write("La nota debe ser 100 o menos: ") 
      Español1 = Console.ReadLine() 
     Else 
      Español1 = Console.ReadLine() 
     End If 

     If Español1 = True Then 
      Console.Write("Matematicas: ") 
      Matematicas1 = Console.ReadLine() 
     End If 

     Console.Write("Ciencias: ") 
     Ciencias1 = Console.ReadLine() 

     Console.Write("Estudios Sociales: ") 
     EstudiosSociales1 = Console.ReadLine() 

     Console.Write("Ingles: ") 
     Ingles1 = Console.ReadLine() 

     Console.Write("Artes plasticas: ") 
     ArtesPlasticas1 = Console.ReadLine() 

     Console.Write("Artes Industriales: ") 
     ArtesIndustriales1 = Console.ReadLine() 

     Console.Clear() 

    End Select 

End Sub 

、任意の提案ですか?

+1

これはvb.netタグですか? – lokusking

+0

これはVBAではなく、VBだけです。 VBAではConsole.WriteLineなどは使用できません。 –

+1

@BennoGrimm私はすでにそれを修正します。ありがとう! – NietzscheProgrammer

答えて

1

私は本当にVBで経験していないんだけど、これを試してみてください。

Dim n as Integer 

n = Console.WriteLine() 

Do While n >= 100 
    Console.WiteLine("Enter new Value:") 'Sorry, no pienso la lengua español :(
    n = Console.ReadLine() 
Loop 

編集3.0 配列subjectsにあなたのサブジェクト名を追加します。

Sub Main() 
Dim subjects As Array = {"Math", "English", "German"} 'Three example names 
Dim subjectsInt As New Dictionary(Of String, Integer) 
Dim i, input As Integer 
Dim check, FirstTry As Boolean 

For i = 0 To (subjects.Length - 1) 
    check = False 
    FirstTry = True 

    Do 

     If FirstTry = True Then 
      Console.WriteLine(subjects(i) & ": ") 
      FirstTry = False 
     Else 
      Console.WriteLine("Please enter a value between 1 and 100" & " (" & subjects(i) & "):") 
     End If 

     input = Console.ReadLine() 

     If input <= 100 And input > 0 Then 
      subjectsInt.Add(subjects(i), input) 
      check = True 
     End If 

    Loop While check = False 

Next 

For i = 0 To (subjects.Length - 1) 
    Console.WriteLine(subjects(i) & ": " & subjectsInt(subjects(i))) 
Next 

Console.ReadLine() 
End Sub 
+0

私のコードにどのように適応させることができますか?私は試していますが、できません;/ – NietzscheProgrammer

+0

「私は思っていました...」+6行 –

+0

「式は値を生成しません」 – NietzscheProgrammer

0

私は不幸にもVBAを知らない。しかし、私はすべての言語が同じであると信じています。サイクル中にdo {}を行い、その間に条件が満たされているかどうかを確認します。そしてそれらが満たされるまで、あなたはコンソールからの読書を続けます。あなたのVBAで良く見える:)

関連する問題