The MASM Forum

Projects => MasmBasic & the RichMasm IDE => Topic started by: jj2007 on June 10, 2022, 10:11:19 AM

Title: *.INI files
Post by: jj2007 on June 10, 2022, 10:11:19 AM
include \masm32\MasmBasic\MasmBasic.inc
  Init
  .if !Ini$()                           ; no ini file found, let's create one
        SetIni$ "crtDate", fDate$()
        SetIni$ "crtTime", fTime$()
  .endif
  PrintLine "Created  ", Ini$("crtDate"), ", ", Ini$("crtTime")
  SetIni$ "modTime", Cat$(fDate$()+", "+fTime$())
  PrintLine "Modified ",  Ini$("modTime")
EndOfCode


Output (12 minutes later):
Created  10.06.2022, 01:56:41
Modified 10.06.2022, 02:09:00


Building the attached source requires MasmBasic of 10 June 2022 (http://masm32.com/board/index.php?topic=94.0)

P.S.: This is meant for settings, i.e. short names and values in the format name=value. There is a limit of 100 kBytes. Names and values can be Unicode, encoded as Utf8 (i.e. Chinese or Russian are not a problem, see below).

Be careful with embedded CrLf - not impossible, but you need a workaround with Replace$() (https://www.jj2007.eu/MasmBasicQuickReference.htm#Mb1079):
  Let edi=FileRead$("\Masm32\menus.ini") ; qEditor's menus
  SetIni$ "меню редактора", Replace$(edi, CrLf$, "[CrLf$]")
  PrintLine cfm$("\nqEditor menus:\n"),  Replace$(Left$(Ini$("меню редактора"), 200), "[CrLf$]", CrLf$), "..."