This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
vba:functions:heredoc [15.07.2014 09:34:03] yaslaw created |
vba:functions:heredoc [13.09.2018 16:59:47] (current) yaslaw |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== [VBA] heredoc() ====== | ====== [VBA] heredoc() ====== | ||
- | In VBA ist es leider fast nicht möglich, einen längeren fixen Text in eine Variable zu drücken ohne ihn unlesbar zu machen. heredoc() ist mein Versuch das zu vereinfachen. Dabei wird ein Text in der heredoc-Formatierung als Kommentar erfasst. heredoch() liest diesen dann aus und gibt ihn als String zurück. | + | In VBA ist es leider fast nicht möglich, einen längeren fixen Text in eine Variable zu drücken ohne ihn unlesbar zu machen. heredoc() ist mein Versuch das zu vereinfachen. Dabei wird ein Text in der heredoc-Formatierung als Kommentar erfasst. heredoc() liest diesen dann aus und gibt ihn als String zurück. |
+ | |||
+ | Die ausgelesenen Strings werden in einem Dictionary gecached. Wenn derselbe String nochmals abgefragt wird, muss so nicht mehr der VB-Code durchsucht werden. | ||
+ | |||
+ | > Das ganze ist zu aufwendig. Ich selber verwedne es nur sehr selten. Aber der Ansatz finde ich interessant. | ||
+ | |||
+ | {{:vba:functions:udf_heredoc.bas|download udf_heredoc.bas}} | ||
+ | |||
+ | ===== Definitionen ===== | ||
+ | <code vb>Public Function heredoc( _ | ||
+ | ByVal iModulName As String, _ | ||
+ | ByVal iName As String, _ | ||
+ | Optional ByVal iClearCache As Boolean = False _ | ||
+ | ) As String</code> | ||
+ | ***iModulName** Name des Moduls | ||
+ | ***iName** Name der Variable | ||
+ | ***iClearCache** Angabe, ob der Objektcache geleert werden soll | ||
===== Beispiel ===== | ===== Beispiel ===== | ||
+ | > Für die Ausgabe der Resultate verwendete ich die Funktion [[vba:functions:print_r:index]] | ||
+ | > Für den Test_3 verwende ich noch [[vba:functions:printf:index]] um die Möglichekit zu zeigen, mit Platzhalter zu arbeiten | ||
+ | |||
<code vb funcTest.bas>Option Explicit | <code vb funcTest.bas>Option Explicit | ||
Line 23: | Line 42: | ||
'TXT; | 'TXT; | ||
- | print_r heredoc(C_MODULE_NAME, "text_1", True), prShowType + prStringSingleQuotes | + | print_r heredoc(C_MODULE_NAME, "text_1"), prShowType + prStringSingleQuotes |
- | print_r heredoc(C_MODULE_NAME, "text_2", True), prShowType + prStringSingleQuotes | + | print_r heredoc(C_MODULE_NAME, "text_2"), prShowType + prStringSingleQuotes |
- | print_r heredoc(C_MODULE_NAME, "text_3", True), prShowType + prStringSingleQuotes | + | print_r heredoc(C_MODULE_NAME, "text_3"), prShowType + prStringSingleQuotes |
- | print_r sPrintF(heredoc(C_MODULE_NAME, "text_3", True), 2014, "Yaslaw"), prShowType + prStringSingleQuotes | + | print_r sPrintF(heredoc(C_MODULE_NAME, "text_3"), 2014, "Yaslaw"), prShowType + prStringSingleQuotes |
- | print_r heredoc(C_MODULE_NAME, "text_4", True), prShowType + prStringSingleQuotes | + | print_r heredoc(C_MODULE_NAME, "text_4"), prShowType + prStringSingleQuotes |
End Sub | End Sub |