首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

初学者第一次提问,各位大人多帮忙

2012-01-01 
菜鸟第一次提问,各位大人多帮忙啊我用vb6写过些程序,现在在学vb.net。先下了个例子,是关于图像的,叫potovis

菜鸟第一次提问,各位大人多帮忙啊
我用vb6写过些程序,现在在学vb.net。
先下了个例子,是关于图像的,叫potovisonhttp://msdn.microsoft.com/smartclient/codesamples/fotovision/default.aspx
我用的是vs2005,打开这个项目后自动转换,然后发现提示有81个警告,举几个例子:
第一个:
Protected Overrides Sub OnClosing(ByVal e As System.ComponentModel.CancelEventArgs)
If DialogResult = DialogResult.OK Then
[Global].Settings.SetValue(SettingKey.ServicePassword, _
DataProtection.Encrypt(textPassword.Text, DataProtection.Store.User))
End If

MyBase.OnClosing(e)
End Sub

其中DialogResult.OK建议要用Windows.Forms.DialogResult.OK,信息是“通过实例访问共享成员、常量成员、枚举成员或嵌套类型,将不计算限量表达式。”

第二个:
Private Sub GetInfo()
Dim image As Bitmap
Try
image = New Bitmap(_pathCur)
textCurrent.Text = GetPhotoInfo(_pathCur, image)
pictCurrent.Image = PhotoHelper.GetThumbnail(image, pictCurrent.Width)
image.Dispose()
image = New Bitmap(_pathNew)
textNew.Text = GetPhotoInfo(_pathNew, image)
pictNew.Image = PhotoHelper.GetThumbnail(image, pictNew.Width)
Catch ex As Exception
Finally
If Not (image Is Nothing) Then image.Dispose()
End Try
End Sub
最后一行的image说是“变量在赋值前被使用,可能会在运行时导致空引用异常。”

第三个:
Public Shared Function IsValidAlbumName(ByVal name As String) As Boolean
Dim reg As Regex
If reg.IsMatch(name, Consts.InvalidAlbumPattern) Then Return False
If name.Length = 0 OrElse name.Length > Consts.MaxAlbumLength Then Return False
If name.StartsWith(".") OrElse name.EndsWith(".") Then Return False
Return True
End Function

提示“未使用局部变量reg”

第四个:
Public Function Display(ByVal parent As Control) As DragDropEffects
contextMenu.Show(parent, parent.PointToClient(parent.MousePosition))
Application.DoEvents()

Return _effect
End Function

这个是我最不理解的,它提示将parent.MousePosition换成Control.MousePosition,警告内容同第一个例子。


[解决办法]
Quick Details
File Name:FotoVision.exe
Version:1.1
Date Published:6/23/2004

注意版本...显然是VS2003项目...
[解决办法]
第二个:
Dim image As Bitmap = Nothing
第三个:
删除 Dim reg As Regex
直接用 Regex.IsMatch

热点排行