The code below works to set a variable CLetter based on the first letter of a new customer last name, input from the keyboard, if the first letter is 'A'. I need it to compare for A-J, not just A.
@echo off
setlocal ENABLEDELAYEDEXPANSION
set /p CName="Please enter new customer as LastName, FirstName: "
set CLetter=%CName:~0,1%
if "%CLetter%"=="A" (
set CGroup=Client Files A-J
) else (
set CGroup=Client Files K-Z
)
echo %CGroup%
pause
If...Then Not Working
Moderator: DosItHelp
Re: If...Then Not Working
test-1.bat
Code: Select all
@echo off
setlocal enabledelayedexpansion
set "StrAJ=ABCDEFGHIJ"
set /p CName="Please enter new customer as LastName, FirstName: "
set "CLetter=%CName:~0,1%"
if "!StrAJ:%CLetter%=!" neq "!StrAJ!" (
set "CGroup=Client Files A-J"
) else (
set "CGroup=Client Files K-Z"
)
echo,%CGroup%
pause
Re: If...Then Not Working
test-2.bat
Code: Select all
@echo off
set "StrAJ=ABCDEFGHIJ"
set /p CName="Please enter new customer as LastName, FirstName: "
set "CLetter=%CName:~0,1%"
echo,%StrAJ% | findstr /i "%CLetter%" >nul
if not errorlevel 1 (
set "CGroup=Client Files A-J"
) else (
set "CGroup=Client Files K-Z"
)
echo,%CGroup%
pause
Re: If...Then Not Working
Code: Select all
@echo off
set "StrAJ=ABCDEFGHIJ"
set /p CName="Please enter new customer as LastName, FirstName: "
set "CLetter=%CName:~0,1%"
set "CGroup=Client Files K-Z"
(echo,%StrAJ% | findstr /i "%CLetter%" >nul)&&set "CGroup=Client Files A-J"
echo,%CGroup%
pause
-
- Posts: 6
- Joined: 24 Apr 2023 11:13
Re: If...Then Not Working
Awesome! Thank you Batcher!