加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

【转】VB6和VB.Net的常用代码对比

(2012-04-10 22:38:35)
标签:

it

分类: vb.net

版权属于原作者

* DoEvents

VB6
DoEvents

VB.Net
System.Windows.Forms.Application.DoEvents

* App Object

Get the full application filepath

VB6
App.Path & App.EXEName

VB.Net
System.Reflection.Assembly.GetExecutingAssembly.Location.ToString

Get the app's instance

VB6
App.hInstance

VB.Net
System.Runtime.InteropServices.Marshal.GetHINSTANCE _( _
System.Reflection.Assembly.GetExecutingAssembly.GetModules() (0)).ToInt32()

Check for a previous instance

VB6
App.PrevInstance

VB.Net
Function PrevInstance() As Boolean
If Ubound(Diagnostics.Process.GetProcessesByName( _
Diagnostics.Process.GetCurrentProcess).ProcessName)) > 0 Then
Return True
Else
Return False
End If

End Sub


* Graphics

Load a picture

VB6
Picture1.Picture = LoadPicture(path)

VB.Net
Dim img As Image = Image.FromFile(path)
Picture1.Image = img

Load a icon

VB6
Me.Icon = LoadPicture(path)

VB.Net
Dim ico As New Icon(path)
Me.Icon = ico



* File I/0

Read from a file

VB6
Open path For Input As #1
Line Input #1, buffer
Close #1


VB.Net
Dim fs As FileStream = File.Open(path, FileMode.OpenOrCreate, _
FileAccess.Read)
Dim sr As New StreamReader(fs)
Buffer = sr.ReadLine
sr.Close


Write to a file

VB6
Open path For Output As #1
Write #1, buffer
Close #1


VB.Net
Dim fs As FileStream = File.Open(path, FileMode.OpenOrCreate, _
FileAccess.Write)
Dim sr As New StreamWriter(fs)
sr.Write(buffer)
sr.Close


* Errors

Check for an error

VB6
On Error Goto errhandler
...
errhandler:
MsgBox(err.Description)


VB.Net
Try
...
Throw New Exception("error description goes here")
...
Catch e as Exception
MsgBox(e.Description)
End Try



* Events

Handling an event

In VB.Net, there is a new keyword called AddHandler. AddHandler makes handling events a snap.

AddHandler object.event, AddressOf procedure

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有