提问人:roy 提问时间:6/23/2022 最后编辑:roy 更新时间:6/25/2022 访问量:185
将 C# 转换为 vb.net 后出现错误语法错误、预期标识符等
after converting c# to vb.net there is an error Syntax error ,Identifier expected,etc
问:
是否有最好的代码解决方案,以便 vb.net 中没有错误? 转换中是否有可能出现错误? 我提供了一个共享链接,因为我连续未能发布代码 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
谢谢 千斤顶
答:
2赞
dr.null
6/24/2022
#1
在代码编辑器 vb.net 您可以使用 HTML 语言,只需输入元素的开始标签,例如 root 、hit,编辑器就会为您附加结束标签
。然后,可以调用以将 HTML 块返回为 .<html>
Enter</html>
</html>.ToString()
string
在函数中,将所有内容替换为:GenerateReceiptTemplate
Private Shared Function GenerateReceiptTemplate() As String
Return <html>
</html>.ToString()
End Function
在 c# 文件中,复制两个双引号之间的 HTML,并将其粘贴到块中。"..."
<html></html>
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
仅此而已。
注意:不确定 VS2010、VS2012 框架是否支持此功能。是时候继续前进了!
评论
1赞
Jimi
6/24/2022
或者,将整个内容放在双引号之间,这样您就不需要转换为字符串(对于 VB.Net 11 来说可能太多了)XElement
0赞
roy
6/24/2022
@dr.null ,我尝试了您的代码解决方案成功了,没有错误
0赞
roy
6/24/2022
@dr.null ,我使用代码解决方案确实没有错误,但项目和数量没有出现在打印输出中,但如果我将它与 c# 程序语言一起使用,它会显示
0赞
dr.null
6/25/2022
@Jack,如果需要附加变量值,请将它们包含在标签中。不过,我在您的代码中没有看到任何赋值或参数。请注意,您的函数是 ,那么您需要将其作为函数参数或通过 Shared 字段传递变量,或者删除 Shared 修饰符。此外,如果您结合 Jimi 的评论,结果是您问题的另一个答案。<%= variable %>
Shared
0赞
dr.null
6/25/2022
@Jack 要输出项目列表,这将是另一个问题。我们在此处修复了错误部分,作为您的问题和代码示例的标题建议。
评论
Total:
Cash:
Console.WriteLine(GenerateReceiptTemplate())
dr.null
WebBrowser1.Navigate("") Dim doc = WebBrowser1.Document.OpenNew(True) doc.Write(GenerateReceiptTemplate()) WebBrowser1.Refresh()
<html> ... </html>
.ToString()
vbCrLf