Link to home
Start Free TrialLog in
Avatar of Lynchie435
Lynchie435

asked on

Setting Variables Inside A Variable

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#.
ASKER CERTIFIED SOLUTION
Avatar of HainKurt
HainKurt
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Lynchie435
Lynchie435

ASKER

Cheers Bud, was concerned about performance issues.