-1

is there a best code solution so that there is no error in the vb.net?. is there a possibility of an error in the conversion? I provide a share link because I failed continuously to post the code c #.

LINK GOOGLE DRIVE CODE C#

'code output in VB.NET
Private Shared Function GenerateReceiptTemplate() As String
            Return "
                <center>
                    <font size='24px'><b>WcDonalds</b></font><br/> ''>' expected
                    <span>wcdonalds@gmail.com</span> 'Attribute specifier is not a complete statement. Use a line continuation to apply the attribute to the following statement.
                </center> 'Identifier expected
                <br/><br/> ''>' expected
                <table width='100%'> ''>' expected
                    <thead>
                        <tr>
                            <th align='left'>Product Name</th> ''>' expected
                            <th>Quantity</th> 'Attribute specifier is not a complete statement. Use a line continuation to apply the attribute to the following statement.
                            <th align='right'>Subtotal</th> ''>' expected
                        </tr> 'Identifier expected
                    </thead> 'Identifier expected
                    <tbody>
                        <Orders/> ''>' expected
                    </tbody> 'Identifier expected
                </table> 'Identifier expected
                <br/> ''>' expected
                <center>---------------------------------------</center> 'Attribute specifier is not a complete statement. Use a line continuation to apply the attribute to the following statement.
                <br/> ''>' expected

                Total: <b><Total/></b><br/> ''>' expected
                Cash: <b><Cash/></b><br/> ''>' expected
                Change: <b><Change/></b><br/> ''>' expected
                <br/> ''>' expected
                Transaction ID: #<Id/><br/> 'Syntax error & Method arguments must be enclosed in parentheses & 'Transaction' is a type and cannot be used as an expression & 'If', 'ElseIf', 'Else', 'End If', 'Const', or 'Region' expected & 'ID' is not declared. It may be inaccessible due to its protection level
                Cashier: <Cashier/><br/> ''>' expected
                Date: <Date/><br/> 'Keyword is not valid as an identifier & 'Date' is a type and cannot be used as an expression & '.' expected

                <br/> ''>' expected
                <center>---------------------------------------</center> 'Attribute specifier is not a complete statement. Use a line continuation to apply the attribute to the following statement.
                <br/> ''>' expected

                <center><b>Thanks for visiting WcDonalds</b></center> 'Attribute specifier is not a complete statement. Use a line continuation to apply the attribute to the following statement.
                " 'Syntax error
        End Function

thanks jack

roy
  • 693
  • 2
  • 11
  • Yes to the first question and yes to the second. You need to give it a try. – Dave Doknjas Jun 23 '22 at 14:46
  • This code is totally unrelated to your original C# code you posted. – Dave Doknjas Jun 23 '22 at 14:49
  • @DaveDoknjas , The c# code I shared my google drive I want to convert to vb.net without any error at all – roy Jun 23 '22 at 14:55
  • Just remove the leading `@` and the trailing `;` from the string definition in the C# code. – Jimi Jun 23 '22 at 15:10
  • Does this answer your question? [Multiline strings in VB.NET](https://stackoverflow.com/questions/706382/multiline-strings-in-vb-net) – Charlieface Jun 23 '22 at 16:22
  • 2
    .. .and update your version of Visual Studio, if you're actually using v. 2012, that's too old. Visual Studio 2022 Community edition is free software. – Jimi Jun 23 '22 at 16:51
  • @Jimi , 'Just remove the leading @ and the trailing ; from the string definition in the C# code' . I tried the suggestion but it still didn't work – roy Jun 24 '22 at 13:10
  • 1
    Because you need at least VB.Net 14 (VS 2015) for that; you also don't have string interpolation (and many other common features: trying to push you, VS 2012 is **really** too old :) – Jimi Jun 24 '22 at 13:24
  • @Jimi , means this is due to vb.net version issue – roy Jun 24 '22 at 13:28
  • Of course. You'll find many other code snippets, here and everywhere else, directly written in VB.Net, that won't compile in your (*ancient*) version of the language. – Jimi Jun 24 '22 at 13:36
  • @Jimi , what's another solution without html tags because I walked in vs2012 with vb.net items with qty don't show up in print output but if I'm with vs2012 with c# then an item with qty appears in print output – roy Jun 24 '22 at 14:10
  • 1
    I'm not sure what you're saying here. What does *items with qty don't show up in print output* mean? You don't see the `Total:`, `Cash:` lines (which are just text)? If you write `Console.WriteLine(GenerateReceiptTemplate())`, using `dr.null`'s method, what do you see in the output panel? -- To show it in a webBrowser Control, you should write, e.g.,: `WebBrowser1.Navigate("") Dim doc = WebBrowser1.Document.OpenNew(True) doc.Write(GenerateReceiptTemplate()) WebBrowser1.Refresh()` – Jimi Jun 24 '22 at 14:36
  • @Jimi , You can see the code update I posted. I used multiline strings successfully but for the code I comment out from starting code ''Total:
    'I can't do multiline strings
    – roy Jun 24 '22 at 14:55
  • 1
    What you have there is completely wrong. Keep the ` ... ` tags (which is interpreted as start/end of an XElement, that's why you need to add `.ToString()` at the end) and simply add your code in between. No `vbCrLf`, no comments etc. – Jimi Jun 24 '22 at 15:09
  • @Jimi , you can screenshot first with html tag that does not display product name, quantity and total and the second screenshot uses code from me which is not perfect then I ask you for a solution to create a multiline string from the code that I commented out – roy Jun 24 '22 at 15:43
  • 1
    First thing, you should accept dr.null's answer, because it's correct in your context. Then, if you don't know how to use it to add in-lined values coming from nobody knows where, you need to post another question, pointing to this one. Changing the code or context of a question after it has been answered is not a good thing at all. -- Also, you have a better chance to explain what you're trying to do here, since what your previous comment is asking for - or what problem you might have - is not really clear -- You should install VS 2022, so you have multiline strings and string interpolation. – Jimi Jun 24 '22 at 16:07
  • @Jimi , ok I made the latest post sorry to edit this post wrong – roy Jun 24 '22 at 17:17

1 Answers1

2

In code editor you can use the HTML language, just enter the start tag
of an element like the root <html>, hit Enter and the editor will append the end tag </html> for you. You can then call </html>.ToString() to return the HTML block as string.

In the GenerateReceiptTemplate function, replace everything with:

Private Shared Function GenerateReceiptTemplate() As String
    Return <html>

            </html>.ToString()
End Function

From the file, Copy the HTML between the two double quotes "..." and paste it in the <html></html> block.

Private Shared Function GenerateReceiptTemplate() As String
    Return <html>
                <center>
                    <font size='24px'><b>WcDonalds</b></font><br/>
                    <span>wcdonalds@gmail.com</span>
                </center>
                <br/><br/>
                <table width='100%'>
                    <thead>
                        <tr>
                            <th align='left'>Product Name</th>
                            <th align='center'>Quantity</th>
                            <th align='right'>Subtotal</th>
                        </tr>
                    </thead>
                    <tbody>
                        <Orders/>
                    </tbody>
                </table>
                <br/>
                <center>---------------------------------------</center>
                <br/>

        Total: <b><Total/></b><%= qty %><br/>
        Cash: <b><Cash/></b><%= someSharedField %><br/>
        Change: <b><Change/></b><%= someParam %><br/>
                <br/>
        Transaction ID:   #<Id/><br/>
        Cashier: <Cashier/><br/>
        Date: <Date/><br/>

                <br/>
                <center>---------------------------------------</center>
                <br/>

                <center><b>Thanks For visiting WcDonalds</b></center>
            </html>.ToString()
End Function

That's it all.

Note: Not sure whether VS2010, VS2012 frameworks support this feature. Time to move on!

dr.null
  • 4,032
  • 3
  • 9
  • 12
  • 1
    Or, keep the whole thing between double-quotes, so you don't need to convert to string the `XElement` (still possibly *too much* for VB.Net 11) – Jimi Jun 23 '22 at 20:51
  • @dr.null , I tried the code solution from you succeeded without error – roy Jun 24 '22 at 13:11
  • @dr.null , I use the code solution from indeed there is no error but the item & qty in does not appear in the print output but if I use it with the c# program language it displays – roy Jun 24 '22 at 14:03
  • @Jack if you need to append variables values then enclose them in `<%= variable %>` tag. I don't see any assignment or params in your code though. Note, your function is `Shared`, then you need for this to pass the variables as function arguments or through Shared fields, or get rid of the Shared modifier. Also, if you combine Jimi's comments, the result is an another answer to your question. – dr.null Jun 24 '22 at 16:31
  • @Jack To output a list of items, that will be an another question. We fixed here the errors part as the title of your question and code example suggest. – dr.null Jun 24 '22 at 16:41
  • @dr.null , can you answer by using "&vbCrLf&" so it doesn't have a problem in the print output – roy Jun 24 '22 at 17:12
  • @dr.null , ok I made the latest post sorry to edit this post wrong – roy Jun 24 '22 at 17:17
  • @Jack No problem. Good luck Jacki. – dr.null Jun 24 '22 at 17:25