Create real Console mode programs in SB

Pappa Lapub 191 Reputation points
2021-02-16T19:40:38.52+00:00

about create-real-console-mode-programs-in-sb

there's an other way to build a CLI App in SB with AMC_patcher-CLI

instead of AppModeChange.exe GUI in one go.

So the essential lines in a eg. SB12Comp.bat file would be like

supposed that:
AMC.exe is anywhere in your %PATH%
%SB12% stands for your SB projects folder, where the .sb files are stored
Also adjust the the path for eg,
C:\Program Files (x86)\Microsoft\SmallBasic12\SmallBasicCompiler.exe to the path, where your SBCompiler is stored.

@ECHO OFF  
:: https://github.com/TAbdiukov/AMC_patcher-CLI  
:: AppModeChanger patcher - CLI  
IF "%~1"=="" GOTO Syntax  
IF "%~1"=="-?" GOTO Syntax  
IF "%~1"=="/?" GOTO Syntax  
IF /I "%~1"=="-h" AMC.EXE & COLOR & GOTO :EOF  
  
IF NOT EXIST "%~f1" ECHO File "%~1" NOT found! & GOTO :EOF  
IF /I NOT "%~x1"==".sb" ECHO NO .sb source file given! & GOTO :EOF  
IF /I NOT "%~dp1"=="%SB12%\" ECHO Source file NOT in SB12 project folder! & GOTO :EOF  
  
ECHO %~ftza1  
ECHO.  
  
@"C:\Program Files (x86)\Microsoft\SmallBasic12\SmallBasicCompiler.exe" "%~f1"  
::ECHO ERR: %ERRORLEVEL%  
:: OK	: 0 errors.  
:: ERR	: xx errors.  
IF NOT EXIST "%~dpn1.exe" ECHO Compilation ERROR! && GOTO :EOF  
ERASE /F "%~dpn1.pdb"  
IF "%~2"=="3" @AMC.EXE "%~dpn1.exe" 3  
IF /I "%~2"=="cui" @AMC.EXE "%~dpn1.exe" 3  
GOTO :EOF  
  
:Syntax  
ECHO.  
ECHO Compiles .sb files to .exe under SB12, as GUI (Default) or CUI App (SBConsole).  
ECHO Usage %~nx0  [Path\]File.sb [Mode]  [-?,/?]  
ECHO ------- Mode: 2..GUI (Default), 3..CUI, uso. (s. amc.exe /?)  
ECHO         -h     Shows orig. Help about amc.exe.  

Since SB12 the used TextWindow command works different as in SB11, when you use a ConsoleHost like ConsoleZ, (Console2) etc. and the CUI App will fall out of the Console window.

To avoid this i compiled a SBConsole extension to be used instead of TextWindow commands:
So like:
TextWindow.WriteLine(...)
becomes
SBConsole.WriteLine(...)

SBConsole commands are like TextWindow commands, but will stay in the ConsoleHost as a real CLI app.
If you only use a simple CMD window you dont need this and can further use TextWindow commands for a console application.

SBConsole.zip (6.49KB)
f1ap2t
(you'll need to translate the xml tag infos to your language)

Small BASIC
Small BASIC
A programming language created by Microsoft that serves a stepping stone for beginners from block-based coding languages to more complex text-based languages.
280 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.