2016-11-17 1 views
0

Mein Batch-Skript funktionierte gut, bis ich versuchte, einige lange if-Anweisungen hinzuzufügen. Ich bin neu dazu und möchte, wenn jemand überprüfen könnte, was falsch ist. Ich versuche, einen Preiskalkulator zu erstellen, basierend auf welchem ​​Rang Sie sind.Stapel-Skript kann nicht funktionieren Wenn Anweisungen funktionieren

Heres der Abschnitt, der nicht funktioniert.

if "%drating%" < "1500" (set /a price=%price%+3) 
else if "%drating%" < "2000" (@set /a price=%price%+5) 
else if "%drating%" < "2500" (@set /a price=%price%+6) 
else if "%drating%" < "2700" (@set /a price=%price%+8) 
else if "%drating%" < "3000" (@set /a price=%price%+10) 
else if "%drating%" < "3300" (@set /a price=%price%+12) 
else if "%drating%" < "3500" (@set /a price=%price%+14) 
else if "%drating%" < "3800" (@set /a price=%price%+20) 
else if "%drating%" < "3900" (@set /a price=%price%+30) 
else if "%drating%" < "4000" (@set /a price=%price%+40) 
else if "%drating%" < "4100" (@set /a price=%price%+50) 
else (
echo There is no available price for %drating%. 
echo Press any key to exit. 
set /p exitkey= 
) 

heres, was ich nach magoo

tat
if "%drating%" LSS "1500" (set /a price=%price%+3 
) else (if "%drating%" LSS "2000" (set /a price=%price%+5 
) else (if "%drating%" LSS "2500" (set /a price=%price%+6 
) else (if "%drating%" LSS "2700" (set /a price=%price%+8 
) else (if "%drating%" LSS "3000" (set /a price=%price%+10 
) else (if "%drating%" LSS "3300" (set /a price=%price%+12 
) else (if "%drating%" LSS "3500" (set /a price=%price%+14 
) else (if "%drating%" LSS "3800" (set /a price=%price%+20 
) else (if "%drating%" LSS "3900" (set /a price=%price%+30 
) else (if "%drating%" LSS "4000" (set /a price=%price%+40 
) else (if "%drating%" LSS "4100" (set /a price=%price%+50 
) else (echo There is no available price for %drating%. 
echo Press any key to exit. 
set /p exitkey= 
exit 
) 
+1

Hilft, wenn Sie die Hilfe für den Befehl lesen, den Sie verwenden möchten. Öffnen Sie eine Eingabeaufforderung und geben Sie ein: 'if /?' – Squashman

+0

Ich habe es gelesen, keine Ahnung, was ich falsch gemacht habe, obwohl – Bruce219

+0

Wirklich !!!! Sie sehen das weniger als Symbol in der Hilfedatei. – Squashman

Antwort

0
if %drating% lss 1500 (set /a price=%price%+3 
) else (if %drating% lss 2000 (set /a price=%price%+5 
) else (
) 
) 

die lss Operator bedeutet "weniger". Sie müssen die Anführungszeichen weglassen, so dass ein numerischer Vergleich durchgeführt wird, wobei Anführungszeichen einen wörtlichen Vergleich durchführt.

Die else Klausel muss vorangehen und durch die entsprechenden Klammern, wie in der gleichen physischen Zeile angezeigt.

Alle Klammernpaare müssen ausgefüllt werden.

Wenn Sie eine @echo off Anweisung ausgeführt haben, wird echo der Befehl unterdrückt. Es ist normal, diese Anweisung am Anfang eines Stapels zu platzieren. Weitere @statement s sind nicht erforderlich - die @ unterdrückt einfach das Echo der aufgelösten Folgeanweisung.

+0

Nicht sicher, was ich jetzt tat, es funktioniert nicht:/ – Bruce219

+0

dont worry ich habe es! Danke. – Bruce219

1

Ich würde Ihren Code vereinfachen und es einfach so machen.

@echo off 
set "price=10" 
set "drating=4099" 
if %drating% lss 1500 (set /a "price+=3" &GOTO SKIP) 
if %drating% lss 2000 (set /a "price+=5" &GOTO SKIP) 
if %drating% lss 2500 (set /a "price+=6" &GOTO SKIP) 
if %drating% lss 2700 (set /a "price+=8" &GOTO SKIP) 
if %drating% lss 3000 (set /a "price+=10" &GOTO SKIP) 
if %drating% lss 3300 (set /a "price+=12" &GOTO SKIP) 
if %drating% lss 3500 (set /a "price+=14" &GOTO SKIP) 
if %drating% lss 3800 (set /a "price+=20" &GOTO SKIP) 
if %drating% lss 3900 (set /a "price+=30" &GOTO SKIP) 
if %drating% lss 4000 (set /a "price+=40" &GOTO SKIP) 
if %drating% lss 4100 (set /a "price+=50" &GOTO SKIP) 

echo There is no available price for %drating%. 
pause 
GOTO :EOF 

:SKIP 
echo drating=%drating% price=%price% 

pause 
Verwandte Themen