Sets and returns different options for string conversions and comparisons; the function can also return system settings for nationality and language.
Mode [ All | BaseYear | Compare | Date | Format | Lang | StrSpace | Using | Val ] exp
exp = Mode[$]( All | BaseYear | Compare | Date | Format | Lang | StrSpace | Using | Val )
exp = Mode[$]( Language | Language English | Language Native | Lang List | Country | Country Eng | Country Native | Ctry | Ctry Code )
exp : all variable types
Mode sets a global option for converting values to strings and comparing values, while Mode() returns the current value of the global option.
- Mode All sexp
- sexp = Mode(All) Show
sexp : string expression
Sets and returns all Mode settings according to the contents of the string variable sexp.
The string is split into sections with a header followed by the value for each of the settings that can be changed using the individual Mode commands. The format of this string is as follows, with the header text in blue followed by the position of the corresponding value in red:
B$ffffC!vE#lllU"uuZ!d@cccc...[!s\%bbbbb
The sections in the order they appear are:
Mode Command | Header | Value Identifier | Notes |
---|---|---|---|
Format | B$ | ffff | |
Val | C! | v | |
Lang | E# | lll | |
Using | U" | uu | |
Date | Z! | d | |
Compare | @ | cccc... | This value is the only one with a variable length; the length (plus 32) is stored as the first character of the string and retrieved using Asc($) - 32. |
StrSpace | [! | s | This value is either 0 or 1. |
BaseDate | \% | bbbbb | The year value is always preceded by a space, hence the five digits. Any value less than 1900 is counted as 0. |
The Mode All string on a system set for the UK is B$.,:/C!.E#ENGU".,Z!.@&Binary[!1\% 1930.
Debug "Native Mode All settings:"; Mode(All)
Mode All "B$.,:/C!.E#ENGU"#34".,Z!.@&Binary[!1\% 1930"
Debug "Mode All once switched to UK settings:"; Mode(All)
Debug.Show
- Mode BaseYear iexp | sexp
- sexp = Mode(BaseYear) Show
iexp | : integer expression |
sexp | : string expression |
Sets or returns the year used as the base for dates entered with ValD and ValDate. These dates are defined with a two digit year value, meaning that the first two digits are unknown and this defined by this setting. Hence, the default (1930) signifies that all values from 30 to 99 with be preceded by 19 (1930 to 1999) but the values 00 to 29 will be in the following century and prefixed with 20 (2000 to 2029); similarly, if BaseYear is set to 2020, values 20 to 99 will signify 2020 to 2099 and values 00 to 19 will be 2100 to 2119.
The value can be entered as an integer or a string but is returned by the function as a string. The value passed by the command must be 1900 or later; if a value less than 1900 is entered then BaseYear is set to zero.
Local d = ValD("10/10/29")
Print d // 10.10.2029
Mode BaseYear "1920"
d = ValD("10/10/29")
Print d // 10/10/1929
This does not work for CDate() and DateValue(). Despite the base year, at least for Windows 98, also being 1930, since this is OLE dependent (located in oleaut32.dll), it cannot be adjusted.
- Mode Compare iexp | sexp
- sexp = Mode(Compare) Show
iexp | : integer expression |
sexp | : string expression |
Modifies the way string comparison is performed. The default option 0 (or "Binary") performs comparisons in the default manner: comparing each strings' character codes. The value 1 (or "Text") causes the comparisons to be case insensitive, hence no distinction is made between upper and lower case letters during comparisons ("A" = "a" and "Z" = "z").
The value passed in Mode Compare is usually an integer, except for the values -1 to 1 where a descriptive string can be entered instead (see table below); however, Mode(Compare) will return the value as a string only and, if the setting is between -1 and 1, the string descriptive will be returned instead. Hence:
Mode Compare 1 // Same as Mode Compare "Text"
If Mode(Compare) = "1" Then Debug "1" // This will be false...
If Mode(Compare) = "Text" Then Debug "Text" // ...but this will be true.
Below is a small table of values that can be used (the values linked to countries institute comparison unique to that nationality and a full list of the language 'Locale' codes can be found here):
Mode | Meaning |
---|---|
-3 | Converts both strings to lowercase (ignores case) |
-2 | Converts both strings to uppercase (ignores case) |
-1 | Unicode binary (VB default) |
0 or "Binary" | GFA-BASIC 32 default (binary) |
1 or "Text" | Text case-insensitive (includes accent characters) |
6, 1030 | Danish |
7, 1031 | German (Germany) |
8, 1033 | English (US) |
9, 1034 | Spanish |
10, 1035 | Finnish |
11, 1036 | French (France) |
15, 1039 | Icelandic |
19, 1043 | Dutch |
20, 1044 | Norwegian |
29, 1053 | Swedish |
2057 | English (UK) |
For Mode Compare "Text", the following text sort order is produced: (A=a) < ( À=à) < (B=b) < (E=e) < (Ê=ê) < (Z=z) < (Ø=ø)
The Mode Compare statement can appear anywhere in the code and effects all comparisons which are carried out following. Mode Compare sets the overall GFA-BASIC 32 comparison behavior and influences more than just the normal comparison operators. For instance, it affects the insertion of new Hash elements. To retrieve a hash element the Mode Compare must be the same as at the time the element was inserted.
- Mode Date sexp
- sexp = Mode(Date) Show
sexp : string expression
Sets or returns the format to be used with the Date$() and DateTime$() functions; GFA's string representation of a numerical date value produced by Date, Now and DateSerial() is also affected but ONLY in when using Debug and Trace (see example below).
Mode Date "." - date format "dd.mm.yyyy" (German)
Mode Date "/" - date format "mm/dd/yyyy" (US)
Mode Date "-" - date format "yyyy-mm-dd" (international)
To represent any other date format, use Format instead of Date$ and DateTime$; for example, to display a date in UK style, use Format(Date, "dd/mm/yyyy")
The effects of Mode Date can be seen in the following example. Note that the output from Print and Trace vary.
Debug.Show
Mode Date "."
ShowDates("Mode Date ""."":")
Mode Date "/"
ShowDates("Mode Date ""/"":")
Mode Date "-"
ShowDates("Mode Date ""-"":")
Procedure ShowDates(t$)
Debug t$ : Print t$
Trace Date : Print "Date: "; Date
Trace Now : Print "Now: "; Now
Trace Date$(Now) : Print "Date$(Now): "; Date$(Now)
Trace DateSerial((Year(Now), Month(Date), Day(Now), ))
Print "DateSerial((Year(Now), Month(Date), Day(Now),)): "; DateSerial((Year(Now), Month(Date), Day(Now),))
Trace DateTime$(Now) : Print "DateTime$(Now): "; DateTime$(Now)
Debug : Print
EndProcedure
- Mode Format sexp
- sexp = Mode(Format) Show
sexp : string expression
Sets or returns the separators (decimal and thousand numerical separators, and time and date separators) used in the Format function, without affecting the other regional settings in Windows.
The parameter sexp is up to four characters long: the first character is the decimal separator, the second is used to separate thousands, the third to separate hours, minutes and seconds in times, and the fourth to separate days, months and years in dates.
Mode Format ",.:." - Sets numerical, date and time separators for Germany
Mode Format ".,:/" - Sets numerical, date and time separators for US/UK
If an empty string is passed (Mode Format "") the Windows regional settings are loaded; if the string is shorter than four characters, the unspecified characters are replaced with the ones set for Windows.
Mode Format is set/reset automatically by Mode Lang.
Debug.Show
Global c As Double = 1000.1, d As Date = ValDate("16.09.15 10:46:23")
Local lang$ = Mode(Lang)
ShowFormat("Native settings:")
Mode Format ".,:-"
ShowFormat("Mode Format "#34".,:-"#34)
Mode Format ".,"
ShowFormat("Mode Format "#34".,"#34) // Note that the Time and Date revert to native settings
Mode Format ",.:."
ShowFormat("Mode Format "#34",.:."#34)
Mode Format ""
ShowFormat("Mode Format "#34#34) // Note that all separators return to native settings
Mode Lang "FRA"
ShowFormat("Mode Lang "#34"FRA"#34)
Mode Lang lang$
ShowFormat("Native settings once again:")
Procedure ShowFormat(t$)
Debug "Using " & t$
Debug " Decimals: " & Format(c, "#,###.00")
Debug " Dates: " & Format(d, "dd/mm/yyyy hh:mm:ss")
EndProcedure
- Mode Lang sexp | iexp
- sexp = Mode(Lang)
- sexp = Mode(Lang List)
- sexp = Mode(Language)
- sexp = Mode(Language Eng)
- sexp = Mode(Language Native)
- sexp = Mode(Country)
- sexp = Mode(Country Eng)
- sexp = Mode(Country Native)
- sexp = Mode(Ctry)
- sexp = Mode(Ctry Code) Show
sexp : string expression
Mode Lang sets and Mode{Lang} returns the language setting used by the Format function to return values according to a specific country: this includes numerical separator characters, time and date format, as well as the country's currency symbol. Mode Lang changes Mode Format.
For Mode Lang, sexp can take the following values.
AFK | Afrikaans | EUQ | Basque |
CAT | Catalan | DAN | Danish |
NLD | Dutch (Standard) | NLB | Dutch (Belgian) |
NEU | English (United States) | ENG | English (British) |
ENA | English (Australian) | ENC | English (Canadian) |
ENZ | English (New Zealand) | ENI | English (Ireland) |
ENS | English (South Africa) | FIN | Finnish |
FRA | UFrench (Standard) | FRB | French (Belgian) |
FRC | French (Canadian) | FRS | French (Swiss) |
FRL | French (Luxembourg) | DEU | German (Standard) |
DES | German (Swiss) | DEA | German (Austrian) |
DEL | German (Luxembourg) | DEC | German (Liechtenstein) |
ISL | Icelandic | BAH | Indonesian |
ITA | Italian (Standard) | ITS | Italian (Swiss) |
NOR | Norwegian (Bokmal) | NON | Norwegian (Nynorsk) |
PTB | Portuguese (Brazilian) | PTG | Portuguese (Standard) |
ESP | Spanish (TraditionalSort) | ESM | Spanish (Mexican) |
ESN | Spanish (MornSort) | SVE | Swedish |
TRK | Turkish | UKR | Ukrainian |
ROM | Romanian | RUS | Russian |
SKY | Slovak | SLV | Slovenian |
PLK | Polish | ELL | Greek |
HUN | Hungarian | SHL | Croatian |
CSY | Czech | BEL | Byelorussian |
BGR | Bulgarian | SQI | Albanian |
ESG | Spanish (Guatemala) | ESC | Spanish (Costa Rica) |
ESA | Spanish (Panama) | ESD | Spanish (Dominican Republic) |
ESV | Spanish (Venezuela) | ESO | Spanish (Colombia) |
ESR | Spanish (Peru) | ESS | Spanish (Argentina) |
ESF | Spanish (Ecuador) | ESL | Spanish (Chile) |
ESY | Spanish (Uruguay) | ESZ | Spanish (Paraguay) |
ENJ | English (Jamaica) | ENB | English (Caribbean) |
SRB | Serbian |
It is also possible to use four digit language codes (see Mode Compare for a small list) instead of the three letter code; however, Mode(Lang) always returns the three letter code.
Local lang$ = Mode(Lang)
Debug Mode(Format) // [native format]
Mode Lang "DEU"
Debug Mode( Language) // German (Germany)
Debug Mode(Format) // ,.:.
Mode Lang 1033
Debug Mode( Language) // English (United Kingdom)
Debug Mode(Format) // .,:/
Debug Mode(Lang) // ENG
Mode Lang lang$ // Reset to native format
Debug.Show
In addition to Mode(Lang), further information can be retrieved about the language and country settings using the auxiliary Mode functions listed below:
Mode(Lang List) | Lists the short name for the available countries for the OS. |
Mode(Language) | OS language (in the Netherlands: "Nederlands (Nederland)"). |
Mode(Language Eng) | OS language in English (in the Netherlands: "Dutch"). |
Mode(Language Native) | OS language in native (in the Netherlands: "Nederland"). |
Mode(Country) | OS country (in the Netherlands: "Nederland"). |
Mode(Country Eng) | OS country in English (in the Netherlands: "Netherlands"). |
Mode(Country Native) | OS country (in the Netherlands: "Nederland"). |
Mode(Ctry) | OS country in short (in the Netherlands: "NLD"). |
Mode(Ctry Code) | OS country code (in the Netherlands: "31"). |
NOTE: The functions that return Native values may be unintelligible if your system is not set up to support the native language in the internal ANSI table.
Local a As String, b As String, i As Int, lang$ = Mode(Lang), x%
a = Mode(Lang List)
For i = 1 To Len(a) Step 4
b = Space(65)
Mode Lang (Mid$(a, i))
Mid$(b, 1, 4) = Left$(Mode(Lang), 4)
Mid$(b, 8, 4) = Trim(Mode( Ctry Code))
Mid$(b, 16, 50) = Trim(Mode( Language))
Debug b
Next
Mode Lang lang$
Debug.Show
- Mode StrSpace sexp | flag
- sexp = Mode(StrSpace) flag Show
flag | : byte expression |
sexp | : string expression |
By default, GFABASIC32 is VB compliant and places a space in front of a numerical value when printing.
However, in order to create better compatibility with the 16 bit GFA-BASIC, this mode can be switched off with Mode StrSpace 0; changing this setting to 1 resets the VB compatible mode. The setting does not apply globally to the whole program, but until the next Mode StrSpace, so that both settings can be used in one program.
Mode StrSpace 0
Local a% = 5
Debug "A=" & a%
Mode StrSpace 1
Debug "A=" & a%
Mode StrSpace "1"
Debug "A=" & a%
Debug TypeName(Mode(StrSpace))
Debug.Show
- Mode Using sexp
- sexp = Mode(Using) Show
sexp : string expression
Sets and returns the decimal and thousands separation character for the Print Using command, which is independent of Mode Format and regional settings.
Local a% = 45677.89
Mode Using ".,"
Debug Using("#.###,##", a%) // 45.678,00
Mode Using ",."
Debug Using("#,###.##", a%) // 45,678.00
// Note that the order of the separators in the Using statement...
// ... must match those in the Using function otherwise this happens
Debug Using("#.###,##", a%) // 45678.000,00
- Mode Val sexp
- sexp = Mode(Val) Show
sexp : string expression
Sets and returns the decimal separation character for Val(); for example, by default this would be "." (period) but in Germany a "," (comma). This is automatically set by the global Language settings.
NOTE:1 As many data files use commas as data separators, it is usually better to change this setting before loading and saving if you live or work in a locale where the native decimal separator is also a comma.
NOTE 2: Even if this setting is not a "." (period), Val will recognise the period as a decimal separator as well as the character allocated to this setting (see example below).
Debug.Show
Mode Val "." : Debug "Using Mode Val ""."""
Trace Val("-,123") // Prints 0
Trace Val("-.123") // Prints -0.123
Debug.Print
Mode Val "," : Debug "Using Mode Val "","""
Trace Val("-,123") // Prints -0.123
Trace Val("-.123") // Prints -0.123
Date$, Format, Str, Time$, Using, Val
{Created by Sjouke Hamstra; Last updated: 15/01/2023 by James Gaite}