Solved

Setting Variables Inside A Variable

Posted on 2014-11-28
2
72 Views
Last Modified: 2014-12-01
I have a VB.NET application I have built and in a section of it I store a HTML Template in Plain Text (With An Editor) so that if anybody has to make on the fly changes they can do without editing the code.

The HTML is then saved to My.Settings.xyz and stored as an Application Setting so that when the Application (Which is only ran on 1 particular PC) it retains the last updated HTML Template.

The HTML Template itself is populated with 'keywords' which are variables that are gathering from a SQL query that is ran at run-time.

How can I change the values of the variables inside the My.Settings.XYZ String?

UPDATE

I can essentially do this to 'rectify' the matter.

       
If GlobalVariables.strAffinity = "AutoSaint" And GlobalVariables.strTranType = "NB" Then
            GlobalVariables.strHTML = My.Settings.AS_NB_HTML.ToString.Replace("GlobalVariables.strPolRef", GlobalVariables.strPolRef)
            'GlobalVariables.strHTML = "<style type='text/css'> body,td,th {    font-family: Arial, Helvetica, sans-serif;  font-size: 12px; } body </style> </head>  <body> <table align='center' cellpadding='0' cellspacing='0' width='708' style='width:676px;'>   <tr><td width='706'><img src=http://imglib.fresh.co.uk/htmlemail/autosaint/header-new.gif' alt='Autosaint - Call 01527 758 158' /></td>   </tr> <tr><td style='border-left:solid 3px #335967; border-right:solid 3px #335967;'>  <table width='700' cellpadding='0' cellspacing='0'>       <tr><td width='410' valign='top' style='padding-left:10px; width:390px;'>         <p><font face='Arial, Helvetica, sans-serif'>Dear " & CustDetails.Title & ",</font></p> <p><font size='+1' face='Arial, Helvetica, sans-serif'><strong>Thanks for choosing Autosaint Insurance!</strong></font></p> <p><font face='Arial, Helvetica, sans-serif'>What a great choice you&acute;ve made, we were awarded Personal Lines Broker of the Year 2012 &amp; 2013 so you know you&acute;re in safe hands. We&acute;re looking forward to servicing your policy and hope to do so for many years to come.</font></p> <p><font face='Arial, Helvetica, sans-serif'>You will notice there are a number of documents attached to this mail.</font></p>              <img src='http://imglib.fresh.co.uk/htmlemail/autosaint/title-read.gif' alt='Do I Need To Read All Of The Attachments'  />         <p><font face='Arial, Helvetica, sans-serif'>Yes! &ndash; We cannot stress enough just how important it is that you open and check ALL of these documents, the information contained within forms the basis of your contract with the Insurer. If when you have checked them you notice that there are mistakes you must contact us straight away, errors could mean your policy is invalid. You can contact us on <strong>01527 758 169</strong>.</font></p>                 <img src='http://imglib.fresh.co.uk/htmlemail/autosaint/title-print.gif' alt='DO I NEED TO PRINT ALL THE DOCUMENTS?'  />         <p><font face='Arial, Helvetica, sans-serif'>No! &ndash; Most are just for your information so you may wish to save them to your computer, however there may be documents that require your URGENT attention, some of these may need printing so you can complete a declaration or sign a document. The documents listed below must be given your immediate attention and returned to us within 10 days to avoid your policy being cancelled.</font></p>             <p><font face='Arial, Helvetica, sans-serif'>" & CustDetails.CHASList & "</font></p> <img src='http://imglib.fresh.co.uk/htmlemail/autosaint/title-return.gif' alt='HOW DO I RETURN MY DOCUMENTS TO YOU?'  />         <p><font face='Arial, Helvetica, sans-serif'><strong>Email</strong> &ndash; Scan your documents (or try taking a photo of them with your smart phone or digital camera if you don&acute;t have a scanner) and attach them to an email to <a href='mailto:autosaint.documents@fresh.co.uk'>autosaint.documents@fresh.co.uk.</a></font></p> <p><font face='Arial, Helvetica, sans-serif'><strong>Post</strong> &ndash; Please do not send original official documents such as your driving licence by post.  Items like this should be photocopied and sent to us. Post should be addressed to:</font></p>          <p><font face='Arial, Helvetica, sans-serif'>Autosaint</font><font face='Arial, Helvetica, sans-serif'><br />   Fresh Insurance <br />      Burnt Meadow Road<br />      North Moons Moat<br />      Redditch<br />      B98 9PA</font></p> <p><font face='Arial, Helvetica, sans-serif'><img src='http://imglib.fresh.co.uk/htmlemail/autosaint/claimsheader.gif' alt='' width='400' height='40'></font></p> <p>In the event of an incident please contact our claims experts on:<br> <strong>01527 758 352&nbsp;<br> <br> (<a href='http://imglib.fresh.co.uk/htmlemail/autosaint/asclaims.vcf'>Contact Card Link</a>)</strong></p></td>     <td width='230' valign='top' style='padding:0px 0 0 0px; width:230px;'>       <table width='230' cellpadding='0' cellspacing='0'>                       <tr><td width='230'><img src='http://imglib.fresh.co.uk/htmlemail/autosaint/header-ref.gif' alt='Your First Reference' /></td>               </tr>         <tr><td style='border-left:solid 1px #e4e3e3; border-right:solid 1px #e4e3e3; padding:0px 0 0;' align='center'><p><font size='+1' face='Arial, Helvetica, sans-serif'><strong>" & GlobalVariables.strPolRef & "</strong></font></p></td></tr>         <tr><td><img src='http://imglib.fresh.co.uk/htmlemail/autosaint/box-bottom.gif'  /></td></tr>         </table>         <table width='230px' cellpadding='0' cellspacing='0'>         <tr><td><img src='http://imglib.fresh.co.uk/htmlemail/autosaint/header-cover.gif' alt='Cover Details' /></td></tr>         <tr><td style='border-left:solid 1px #e4e3e3; border-right:solid 1px #e4e3e3; padding:0px 0px 0;'>           <p><font face='Arial, Helvetica, sans-serif'>Cover Date: " & CustDetails.InceptionDate & "<br />                 Insurer: " & CustDetails.Insurer & "<br />                 Cover: " & CustDetails.Cover & "<br />                 Drivers: " & CustDetails.Drivers & "<br />                 No Claims: " & CustDetails.NCBYrs & " Years</font></p>                </td></tr>         <tr><td><img src='http://imglib.fresh.co.uk/htmlemail/autosaint/box-bottom.gif'  /></td></tr>         </table>             <table width='230px' cellpadding='0' cellspacing='0'>         <tr><td><img src='http://imglib.fresh.co.uk/htmlemail/autosaint/header-vehicle.gif' alt='Vehicle Details' /></td></tr>         <tr><td style='border-left:solid 1px #e4e3e3; border-right:solid 1px #e4e3e3; padding:0px 0px 0;'>           <p><font face='Arial, Helvetica, sans-serif'>Make: " & CustDetails.Make & "<br />             Model: " & CustDetails.Model & "<br />             Registration:" & CustDetails.Reg & "</font></p> <div style='padding:0 25px; border:solid 1px #000; width:125px; background:yellow;' align='center'> <p style='margin:5px 0; text-transform:uppercase;'><font size='+2' face='Arial, Helvetica, sans-serif'><strong>" & CustDetails.Reg & "</strong></font></p> </div>         </td></tr>         <tr><td><img src='http://imglib.fresh.co.uk/htmlemail/autosaint/box-bottom.gif'  /></td></tr>         </table>             <table width='230' cellpadding='0' cellspacing='0'>                           <tr><td width='230'><img src='http://imglib.fresh.co.uk/htmlemail/autosaint/header-premium.gif' alt='Premium Details' /></td>                   </tr>         <tr><td style='border-left:solid 1px #e4e3e3; border-right:solid 1px #e4e3e3; padding:0px 0px 0;'>             <p align='left'><font face='Arial, Helvetica, sans-serif'>Insurer Premium: £" & CustDetails.InsurerPrem & "" & CustDetails.Fees & "</font><font face='Arial, Helvetica, sans-serif'>" & CustDetails.BrokerDiscount & "<br><strong>Optionals</strong></font><br>                                 <font face='Arial, Helvetica, sans-serif'>Accident Management Service: " & CustDetails.LegalCover & "<br />                       Breakdown Cover: " & CustDetails.BreakdownCover & "<br />Key Cover: " & CustDetails.KeyCover & "<br>Excess Protection: " & CustDetails.ExcessProt & "</font><br>Windscreen Cover: " & CustDetails.WindscreenCover & "<br>Gadget Cover: " & CustDetails.GadgetCover & "<br>                                     Hard Copy Documents: " & CustDetails.PostageFee & "" & CustDetails.InstalmentFee & "" & CustDetails.AutosaintBox & "" & CustDetails.CCCharge & "<br> Total: " & CustDetails.TotalAmount & "</p></td></tr>         <tr><td><img src='http://imglib.fresh.co.uk/htmlemail/autosaint/box-bottom.gif'  /></td></tr>         </table> <p><img src='http://imglib.fresh.co.uk/htmlemail/autosaint/contacts.gif' alt='Contact Us - Sales 01344 286 194 - 01344 286199'  /></p> <p><img src='http://imglib.fresh.co.uk/htmlemail/autosaint/nrofdocs.gif'> </p></td></tr>     </table> </td></tr> <tr><td><img src='http://imglib.fresh.co.uk/htmlemail/autosaint/containerBottom-new.gif' /></td></tr> <tr><td>    <table width='676px' style='width:676px;'>                  <td width='136'><div align='center'><img src='http://www.fresh.co.uk/HTML/images1/logo-car.gif' alt='1' /></div></td> <td width='1'>&nbsp;</td> <td width='160'><div align='center'><img src='http://www.fresh.co.uk/HTML/images1/logo-fleet.gif' alt='3' /></div></td>              <td width='236'><div align='center'><img src='http://www.fresh.co.uk/HTML/images1/logo-commercial.gif' alt='2' /></div></td>              <td width='119'><div align='center'><img src='http://www.fresh.co.uk/HTML/images1/logo-win-broker.gif' alt='Insurance Times Winner 2012' /></div></td>                 <tr><td colspan='7'><p><font face='Arial, Helvetica, sans-serif'>&copy " & DateTime.Now.Year.ToString() & " Autosaint Insurance, a trading name of Fresh Insurance Services Group Ltd., Burnt Meadow Road, Moons Moat Ind. Est, Redditch, B98 9PA. Registered in England & Wales, No. 4515272.</font></p>                                          <p><font face='Arial, Helvetica, sans-serif'>Authorised and regulated by the Financial Conduct Authority. FCA Registration No. 306202.</font><font color='white'>(FITPE)</font></p>         </td></tr>     </table> </td></tr> </table></body> </html> </html>"
        End If

Open in new window


However my concern there is that there are 35 odd variables I would be doing a REPLACE on. Surely from a programming point of view it is a no no, anybody else have any ides?

Someone coded this for C#

http://www.codeproject.com/Articles/310525/The-ReplaceMany-Method 

Which looks like it'd do what I require but I have no idea about C#.
0
Comment
Question by:Lynchie435
2 Comments
 
LVL 51

Accepted Solution

by:
HainKurt earned 500 total points
ID: 40470842
http://www.codeproject.com/Articles/310525/The-ReplaceMany-Method

is not better than using many replace :)

use 35 times, no big deal...

if you want, you can add all those into app.config file, open the configuration keys, loop and replace...

if you do this zillions of times, and trying to make it run a bit faster, you can try that code, but for your 35 replace, don't worry... add 35 lines and forget about it...
0
 

Author Closing Comment

by:Lynchie435
ID: 40473820
Cheers Bud, was concerned about performance issues.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

947 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now