在变量内设置变量

时间:2014-11-27 17:15:25

标签: vb.net variables

我有一个我已经构建的VB.NET应用程序,并且在其中的一部分中我将HTML模板存储在纯文本中(使用编辑器),这样如果任何正文必须进行动态更改,则无需编辑代码。

然后将HTML保存到My.Settings.xyz并存储为应用程序设置,以便当应用程序(仅在1台特定PC上运行)时,它会保留最后更新的HTML模板。

HTML模板本身填充了'关键字'这是从运行时运行的SQL查询中收集的变量。

如何更改My.Settings.XYZ字符串中的变量值?

更新

我基本上可以做到这一点来纠正'这件事。

        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

然而我担心的是,我会做35个奇数变量。当然从编程的角度来看,这是不是没有,其他人有任何想法吗?

有人将此编码为C#

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

看起来它做了我需要的但我不知道C#。

1 个答案:

答案 0 :(得分:0)

您可以通过指定新值来更改设置并立即保存。如果没有,它将在应用程序关闭时保存。希望这可以帮助。请参阅参考:http://msdn.microsoft.com/en-us/library/shytyc55.aspx

Dim ABC As String = "newStringVal"
My.Settings.XYZ = ABC
My.Settings.Save()