- Messages
- 1,564
- Country
The need to store strings is an issue sometimes faced when coding in XML, particularly when designing a gauge that utilizes the gps module (for example, when making an FMS). Options to store string data include:
1. Use of XML String Operators ord chr and scat to store and retrieve the ascii code equivalent of individual string characters in L:Vars. This has been the standard approach.
2. Macros that make use of the String Operators and enable more than one string character (up to 6) to be stored into a single L:Var. For example, Roman Stoviak has written a very clever set of macros that use String and Numerical Operators to store up to 6 string characters into L:Vars. http://forum.avsim.net/topic/299204-storing-string-data/
3. The internal registers, e.g., s0 … s49, with the limitation that these registers are wiped clean every update cycle.
4. Doug Dawson's String to memory dll module. Doug bottomless bag of cool tricks includes a prototype (September 2011) module that will allow strings to be stored into memory. Tested in FSX. Requires the loading of the dll module (but you won't need the macros from 2.). Please refer to Doug's posts further down in this thread.
5. Tom Aguilo's XMLTOOLS. This powerful module provides many additional functions to XML gauges. The XMLVARS class allows storage of string values.
6. XML read/write to hard disk. Robbie McElrath has completed a dll module that enables very easy file read/write capability: XML--> HDD--> XML. Accommodates strings and numbers, works with all text and .csv file formats, FS9 and FSX. Available on the BlackBox website and also bundled with XMLTOOLS. http://forum.avsim.net/topic/299204-storing-string-data/
A variation on 2), Robbie provides the following macros that utilize String and Bit Operators to manipulate strings and store the result into L:Vars.
Features of these macros:
a) Strings of up to 64 alphanumeric characters, including spaces, in length can be stored in a single, L:Var. All ascii special characters: !, @, #, $, % etc. etc. except "&", "/", "\", "<", and " ' " (single quote) are accommodated in addition to all of the alphanumerics.
b) The L:Var can have any name and there can be any number of such 'string' L:Vars in a gauge. The 'string' L:Vars can be read by any XML gauge of your panel set, similar to normal L:Vars.
c) Functional Backspace
d) FS9, FSX, P3D 32 and 64
THE MACROS. There are 12 of them, but once they are copied and pasted into your gauge, you’re set (and these are an update to the original macros posted in the AVSIM Forum link above):
USING THE MACROS. This is the easy part.
1. CONVERTING STRING DATA INTO AN L:Var
The user just needs to choose an arbitrary L:Var name, such as StringLVar1. No need to include units. Entering data via “typing” on an FMS keypad image in your gauge is a simple variation of this. You only need to adjust the M:Key reference in the ReadKB macro. The last line of the ReadKB macro would read @Read4(@1_1, L:LKey) rather than @Read4(@1_1, M:Key). Then, in the <Mouse> section, for a click on the letter "A" for example:
2. DISPLAYING THE 'STRING' L:Var:
3. PASSING A 'STRING' L:Var:
4. CLEARING THE 'STRING' L:Var:
Later today, I will attach a simple, fully functional “test gauge” that can be used to check out the use and capabilities of these string macros.
Appreciate feedback and comments – especially if unintended side effects are found.
Cheers,
Bob
1. Use of XML String Operators ord chr and scat to store and retrieve the ascii code equivalent of individual string characters in L:Vars. This has been the standard approach.
2. Macros that make use of the String Operators and enable more than one string character (up to 6) to be stored into a single L:Var. For example, Roman Stoviak has written a very clever set of macros that use String and Numerical Operators to store up to 6 string characters into L:Vars. http://forum.avsim.net/topic/299204-storing-string-data/
3. The internal registers, e.g., s0 … s49, with the limitation that these registers are wiped clean every update cycle.
4. Doug Dawson's String to memory dll module. Doug bottomless bag of cool tricks includes a prototype (September 2011) module that will allow strings to be stored into memory. Tested in FSX. Requires the loading of the dll module (but you won't need the macros from 2.). Please refer to Doug's posts further down in this thread.
5. Tom Aguilo's XMLTOOLS. This powerful module provides many additional functions to XML gauges. The XMLVARS class allows storage of string values.
6. XML read/write to hard disk. Robbie McElrath has completed a dll module that enables very easy file read/write capability: XML--> HDD--> XML. Accommodates strings and numbers, works with all text and .csv file formats, FS9 and FSX. Available on the BlackBox website and also bundled with XMLTOOLS. http://forum.avsim.net/topic/299204-storing-string-data/
A variation on 2), Robbie provides the following macros that utilize String and Bit Operators to manipulate strings and store the result into L:Vars.
Features of these macros:
a) Strings of up to 64 alphanumeric characters, including spaces, in length can be stored in a single, L:Var. All ascii special characters: !, @, #, $, % etc. etc. except "&", "/", "\", "<", and " ' " (single quote) are accommodated in addition to all of the alphanumerics.
b) The L:Var can have any name and there can be any number of such 'string' L:Vars in a gauge. The 'string' L:Vars can be read by any XML gauge of your panel set, similar to normal L:Vars.
c) Functional Backspace
d) FS9, FSX, P3D 32 and 64
THE MACROS. There are 12 of them, but once they are copied and pasted into your gauge, you’re set (and these are an update to the original macros posted in the AVSIM Forum link above):
Code:
<Macro Name="Read4">
(@1_4, number) 7 << 0xFFFFFFF & (@1_3, number) 21 >> 0x7F & | (>@1_4, number)
(@1_3, number) 7 << 0xFFFFFFF & (@1_2, number) 21 >> 0x7F & | (>@1_3, number)
(@1_2, number) 7 << 0xFFFFFFF & (@1_1, number) 21 >> 0x7F & | (>@1_2, number)
(@1_1, number) 7 << 0xFFFFFFF & (@2, number) @3 0x7F & | (>@1_1, number)
</Macro>
<Macro Name="ReadKB">
@Read4(@1_4, @1_3_4, 21 >>)
@Read4(@1_3, @1_2_4, 21 >>)
@Read4(@1_2, @1_1_4, 21 >>)
@Read4(@1_1, M:Key)
</Macro>
<Macro Name="Read4Str">
(@1_4, number) 7 << 0xFFFFFFF & (@1_3, number) 21 >> 0x7F & | (>@1_4, number)
(@1_3, number) 7 << 0xFFFFFFF & (@1_2, number) 21 >> 0x7F & | (>@1_3, number)
(@1_2, number) 7 << 0xFFFFFFF & (@1_1, number) 21 >> 0x7F & | (>@1_2, number)
(@1_1, number) 7 << 0xFFFFFFF & @2 0x7F & | (>@1_1, number)
</Macro>
<Macro Name="ReadStr">
@Read4(@1_4, @1_3_4, 21 >>)
@Read4(@1_3, @1_2_4, 21 >>)
@Read4(@1_2, @1_1_4, 21 >>)
@Read4Str(@1_1, r)
</Macro>
<Macro Name="Backspace4">
(@1_1, number) 7 >> (@1_2, number) 0x7F & 21 << | (>@1_1, number)
(@1_2, number) 7 >> (@1_3, number) 0x7F & 21 << | (>@1_2, number)
(@1_3, number) 7 >> (@1_4, number) 0x7F & 21 << | (>@1_3, number)
(@1_4, number) 7 >> (@2_1, number) 0x7F & 21 << | (>@1_4, number)
</Macro>
<Macro Name="Backspace">
@Backspace4(@1_1, @1_2)
@Backspace4(@1_2, @1_3)
@Backspace4(@1_3, @1_4)
@Backspace4(@1_4, L:PleaseBeZero)
</Macro>
<Macro Name="Clear4">
0 (>@1_1, number) 0 (>@1_2, number) 0 (>@1_3, number) 0 (>@1_4, number)
</Macro>
<Macro Name="Clear">
@Clear4(@1_1) @Clear4(@1_2) @Clear4(@1_3) @Clear4(@1_4)
</Macro>
<Macro Name="ToString1">
(@1, number) 21 >> 0x7F & chr
(@1, number) 14 >> 0x7F & chr scat
(@1, number) 7 >> 0x7F & chr scat
(@1, number) 0x7F & chr scat
</Macro>
<Macro Name="ToString4">
@ToString1(@1_4) @ToString1(@1_3) @ToString1(@1_2) @ToString1(@1_1) scat scat scat
</Macro>
<Macro Name="ToString">
@ToString4(@1_4) @ToString4(@1_3) @ToString4(@1_2) @ToString4(@1_1) scat scat scat
</Macro>
<Macro Name="FromString">
:221 d slen 0 > if{ d 0 symb ord @ReadStr(@1) d slen 1 - 1 r ssub g221 }
</Macro>
USING THE MACROS. This is the easy part.
1. CONVERTING STRING DATA INTO AN L:Var
- Entering one character at a time such as in direct keyboard entry, automatically concatenating as you type. The use of <On Key="Ascii"> will enable keyboard entry of "-" and "." as well as all the other alphanumerics:
Code:
<On Key="Ascii"> <!-- Keyboard Entry -->
<Visible>(L:KeyboardEntryEnabled1, bool)</Visible>
@ReadKB(L:StringLVar1)
</On>
<On Key="Backspace"> <!-- Backspace -->
<Visible>(L:KeyboardEntryEnabled1, bool)</Visible>
@Backspace(L:StringLVar1)
</On>
Code:
<Area Left="25" Top="220" Width="15" Height="15">
<Cursor Type="Hand" />
<Click>
'A' ord (>L:LKey, enum)
@ReadKB(L:StringLVar1)
</Click>
</Area>
- Entering a string of characters all at once. If you want to store something like:
Code:
@Clear(L:BAM_VOR_ICAO)
'VED BAM' @FromString(L:BAM_VOR_ICAO)
or
@Clear(L:Nav1Name)
(A:NAV1 NAME, string) @FromString(L:Nav1Name)
Code:
<String>%(@ToString(L:StringLVar1))%!s!</String>
Code:
@ToString(L:BAM_VOR_ICAO) (>C:fs9gps:WaypointVorIcao)
Code:
@Clear(L:StringLVar1)
Later today, I will attach a simple, fully functional “test gauge” that can be used to check out the use and capabilities of these string macros.
Appreciate feedback and comments – especially if unintended side effects are found.
Cheers,
Bob
Last edited: