-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>[email protected]</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

17
  • 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. Commented Jun 23, 2022 at 16:51
  • 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 :) Commented Jun 24, 2022 at 13:24
  • 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() Commented Jun 24, 2022 at 14:36
  • 1
    What you have there is completely wrong. Keep the <html> ... </html> 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. Commented Jun 24, 2022 at 15:09
  • 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. Commented Jun 24, 2022 at 16:07

1 Answer 1

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>[email protected]</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!

Sign up to request clarification or add additional context in comments.

8 Comments

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)
@dr.null , I tried the code solution from you succeeded without error
@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
@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.
@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.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.