TBMANLIB Package

Author: woeoio. Version: 1.0.0.29. On GitHub: woeoio/tbman, the repository of the TBMAN toolkit. This section documents version 1.0.0.29, published on TWINSERV on 9 February 2026 under the MIT licence. The repository has been developed since, and its current code may differ from that version.

The TBMANLIB contributed package is the library of TBMAN, a toolkit for twinBASIC programmers that grew out of the author’s VB6 library vbman. It is a collection of small helpers rather than a library with one theme: a JSON document class and parser, an HTTP client, a log writer, a stopwatch, timers, an INI file class and a CSV file class, a message-box helper, a window subclasser, and modules of functions for strings, arrays and bytes, UTF-8, dictionaries, files and folders and numbers. The package’s own description on TWINSERV is a tagline, a rapid development toolkit for twinBASIC.

Dim J As New cJson
Dim UserName As String
J.Decode "{""user"":{""name"":""Ann""},""scores"":[3,5]}"

UserName = J.Item("user")("name")
Debug.Print UserName
Debug.Print J.Item("scores")(2)
Debug.Print ToolsStr.InsertSpan(UserName, "-", 1)
Debug.Print J.Encode()
' Output:
' Ann
' 5
' A-n-n
' {"user":{"name":"Ann"},"scores":[3,5]}

What the package offers

  • JSON. cJson holds a JSON document: it reads a text or a file, gives access to its objects and arrays, builds new ones, and writes them as text or to a file. The parser and writer are the code of VBA-JSON, in ToolsJsonVba.
  • Logs. cLogs writes log lines to files in a folder tree by day or month, and can send each line to a list box, to a debugging tool or to a web page, with four levels.
  • HTTP. cHttpClient sends requests with WinHTTP and reads the answer as text, JSON, bytes or a file, and uploads and downloads files. ToolsHttp holds its enumerations and helpers for URLs and forms, ToolsHttpMimeType gives the media type of a file name, and Consts holds media-type constants.
  • Time. cTimeuse is a stopwatch with a millisecond count. cTimer raises an event at an interval, and cTimers is a numbered group of timers with one event.
  • Messages. cLayer shows a message box. cSubClass lets a program see the messages that a window receives.
  • INI and CSV files. cIni reads and writes INI files into a two-level dictionary. cCsv holds a table of text and reads and writes CSV files.
  • Text and bytes. cToolsStr trims, cuts and searches strings, makes %XX and \uXXXX escapes, splits text into lines, converts between strings and bytes, and makes random strings and GUIDs. ToolsArray finds, slices and splits byte arrays. ToolsUtf8 converts between UTF-8 bytes and strings. ToolsMath rounds up and picks random numbers. ToolsCN is meant to convert Chinese characters to pinyin.
  • Files and folders. ToolsFso completes paths and creates folders. cToolsStream reads and writes whole files as text in a chosen character set or as bytes.
  • Dictionaries. ToolsDic reads form text, merges and copies Scripting.Dictionary objects.
  • Ready-made instances. The module TBMAN has one shared instance of each main class, so a program can write TBMAN.Json or TBMAN.Logs without New. The module Tools has the instances ToolsStr and ToolsStream of the two classes of that name.

The classes are created with New, as in Dim J As New cJson. The members of a module are called with the name of the module in front, as in ToolsArray.FindByteArray(...); the string and stream functions are called through the instances of the module Tools, as in ToolsStr.TrimEx(...). The names of the package’s own members keep the author’s spelling, including the misspellings, such as DebugPring, LogFileNameByUer and TowLevelDicAssign; this documentation uses them as they are.

Components the package uses

The package is written on top of components that are not part of twinBASIC. Its references are the Microsoft Scripting Runtime, the Microsoft ActiveX Data Objects 2.8 library and the Microsoft WinHTTP Services 5.1 library, besides the VB and Common Controls compatibility packages of twinBASIC. Some members create other objects by name.

Component Used by
Scripting Runtime: Scripting.Dictionary cJson (RootItem), cIni and cCsv (their data), cHttpClient (headers and form values), ToolsDic, ToolsJsonVba
Scripting Runtime: Scripting.FileSystemObject cCsv, cIni, ToolsFso
ActiveX Data Objects: ADODB.Stream cToolsStream, so cJson.LoadFrom, cJson.SaveTo and the file members of cHttpClient
WinHTTP: WinHttp.WinHttpRequest.5.1 cHttpClient
WinHttp.WinHttpRequest.5.1, created by name cLogs.WebView
Scriptlet.TypeLib, created by name cToolsStr.GetGUID
imagehlp.dll (MakeSureDirectoryPathExists) cLogs.Save, ToolsFso.AutoMakeDir
kernel32.dll (GetTickCount, OutputDebugStringA, RtlMoveMemory, MultiByteToWideChar, WideCharToMultiByte) cTimeuse, cLogs.DbgView, ToolsArray, ToolsUtf8
user32.dll (SetTimer, KillTimer, GetWindowLong, SetWindowLong, CallWindowProc, ShellExecute from shell32.dll) cTimer, cSubClass, cHttpClient.ShowPage

The references of a package are not visible to the project that uses it. A program that names a type of these libraries in its own code, such as Dim D As New Scripting.Dictionary, adds the library to its own references; in a project that references only TBMANLIB the compiler refuses the name with TB5079, Unrecognized datatype symbol ‘Scripting’. A program can call members that return those objects without naming the type, for example J.Item("user")("name"), and can create an object by name with CreateObject.

32-bit and 64-bit programs

The package is built for 32-bit programs. The window procedure that cSubClass installs is passed to SetWindowLong as a Long, which a 64-bit program cannot hold.

The other components are available to 32-bit programs.

Known problems in version 1.0.0.29

Part of the code is unfinished, and the source holds test code and notes to the author. Where a member does not do what its name or comment says, the page of the member says so. The ones that matter most are these:

  • cToolsStream, and with it cJson.LoadFrom and cJson.SaveTo, leave the shared stream open after a text call, so that the next text call fails or writes over the old text. SaveFileAsText always returns False, and WriteLine always raises error 13.
  • cCsv: the functions that add columns and widths return False always, the value property cannot be set, removing a column other than the last one corrupts the saved file, and a character that the system code page lacks leaves an empty file.
  • cHttpClient accepts every certificate, RequestDataQuery loses the name of its first item, header values are cut at their first colon, so FollowRedirect cannot work, and its content type header does not follow a later change of the content type.
  • ToolsHttp.UrlDecodeUtf8 raises error 13 for any text with a %, UrlEncodUtf8 writes the characters from hex 80 to hex FFF wrongly, and ToolsCN.GetPinYin raises an error for any text with an English letter, a digit or a space in it.
  • cJson.Decode rejects an array that follows a line break.
  • cToolsStr.GetLastChar returns the first character, UniVbCrLf doubles a line feed, IsEmptyEx trims the variable it is given, and SplitLinesToCollection loses a last line of one character.
  • ToolsUtf8.DecodeToByteArray returns half of the bytes.
  • ToolsArray.SliceByteArray returns a wrong result when the start and the end are the same.
  • cLogs.Save sends the other outputs at the level Info, and the levels Debugger and Custom raise an error.
  • cTimer and cTimers objects that are enabled are not destroyed when the program releases them, and go on running.

Classes

  • cCsv – holds a table of text and reads and writes CSV files.
  • cHttpClient – sends HTTP and HTTPS requests with WinHTTP, and uploads and downloads files.
  • cIni – reads and writes INI files into a two-level dictionary.
  • cJson – holds a JSON document: reads and writes text and files, and builds objects and arrays.
  • cLayer – shows a message box.
  • cLogs – writes log lines to files and to other outputs, with levels.
  • cSubClass – sees the messages that a window receives, and can stop them.
  • cTimer – raises an event at an interval.
  • cTimers – a numbered group of timers with one event.
  • cTimeuse – a stopwatch in milliseconds.
  • cToolsStr – trims, searches, escapes and converts strings; random text and GUIDs.
  • cToolsStream – reads and writes whole files as text or bytes.

Modules

  • Consts – media types and header names of HTTP requests.
  • TBMAN – shared instances of the classes, and a version text.
  • Tools – the shared instances of cToolsStr and cToolsStream.
  • ToolsArray – finds, slices and splits arrays of bytes and longs.
  • ToolsCN – meant to convert Chinese characters to pinyin.
  • ToolsDic – form text, merging and copying of dictionaries.
  • ToolsFso – completes paths, tidies slashes and creates folders.
  • ToolsHttp – request methods and content types, URL encoding, form and header text.
  • ToolsHttpMimeType – the media type of a file name.
  • ToolsJsonVba – the VBA-JSON parser and writer, and the VBA-UTC date functions.
  • ToolsMath – rounds up, and picks random whole numbers.
  • ToolsUtf8 – converts between UTF-8 bytes and strings.

Types without members

Some types of the package have no members, or none that a program is meant to use, and have no page:

  • ToolsJsonUcs holds only the comment add your procedures here.
  • cSysTray holds only the comment add your member fields and procedures here. It is the type of TBMAN.SysTray.
  • ForDialog is an empty form. ToolsDialog has one public member, a String named LastError, and the rest of its code is commented out.
  • ToolsJScript has all its code commented out; it once created JavaScript objects with the Script Control, which the package no longer references.
  • Tests is the author’s demonstration code: UploadAndDownloadDemo and TestHttpClient upload and download files from a public test server on the internet, with paths on drive C: that a computer is unlikely to have. A program has no use for them.
  • mTimer and mCallBackSubClass are the internal modules behind cTimer and cSubClass. Their public members, the callbacks that Windows calls and the collections that register the objects, are not meant to be called by a program.

See Also