将VB代码转换为VB.Net代码 [英] Convert VB Code into VB.Net Code

查看:144
本文介绍了将VB代码转换为VB.Net代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Private Sub SaveTemp_Click()
Dim blob() As Byte
blob = Templ.Serialize
blob1 = blob
Open CommonDialog1.FileName For Binary As #1
Put#1,,blob
Close#1
End Sub





我收到了保存模板的代码。问题是我正在使用vb.net,这个代码是针对vb的。有人可以帮我转换这些代码吗?



I got this code for saving templates. The problem is I'm using vb.net and this code is for vb. Can someone help me convert this codes?

推荐答案

这是可怕的代码,为什么要转换它?我会说废弃它并适当地重写。



转换该代码所需的大部分信息都从你的帖子中丢失了。比如,什么是Temp1,什么是blob1?两者都是可怕的变量名称,并且缺少类型信息。



此外,此代码在尝试使用它之前不会对变量数据进行验证。例如,如果CommonDialog.FileName返回一个空字符串会发生什么?
It's terrible code, why would you want to convert it? I'd say scrap it and rewrite appropriately.

Most of the information required to convert that code is missing from your post. Like, what is "Temp1" and what is "blob1"? Both as horrible variable names to begin with and the type information is missing.

Also, this code does no validation on the variable data before trying to use it. For example, what happens if CommonDialog.FileName returns an empty string?


如评论中所述,您可能只需重新编写它,因为它不会直接转换为。网络。



你想在网上寻找 SaveFileDialog类 [ ^ ]这是你可以要求用户选择一个名称来保存文件的方法。



那么也许你会想要使用 BinaryWriter类 [ ^ ]将您的ojbect写成二进制文件。



我建议你google for c#examples,因为与VB相比有这么多。例如,c#SaveFileDialog example,因为C#和VB.Net在语法上非常相似,你应该可以使用这些例子。
As mentioned in comments, you'll likely need to just re-write it since this won't convert straight into .Net.

You'll want to look for examples online of the SaveFileDialog Class[^] which is how you can ask the user to pick a name to save the file as.

Then perhaps you'll want to use the BinaryWriter Class[^] to write your ojbect out as a binary file.

I would suggest you google for c# examples because there are so many compared to VB. For example, "c# SaveFileDialog example" and since C# and VB.Net are quite similar in syntax you should likely be able to use the examples.


这篇关于将VB代码转换为VB.Net代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆