VB Upgrade help

punk_roks11

New member
Joined
Sep 25, 2006
Messages
2
Programming Experience
1-3
hi, i'm new to vb.net and i am having some trouble upgrading from vb6. I'm trying to copy a form and everything in it to vb.net and am having some troubles. The original code is as follows:
VB.NET:
Private mblnEncryptKeyPressed As Boolean
Private mclsEncryptor As clsEncryption
Private Property Get Encryptor() As clsEncryption
If mclsEncryptor Is Nothing Then mclsEncryptor = New clsEncryption
Encryptor = mclsEncryptor
End Property
Private Sub cmdClear_Click()
txtRegnKey.Text = ""
txtVSN.Text = ""
mblnEncryptKeyPressed = False
End Sub
Private Sub cmdEncrypt_Click()
Dim strVersion As String
mblnEncryptKeyPressed = True
Screen.MousePointer = vbHourglass
strVersion = " V" & Trim(txtVersion.Text)
If Trim(txtVSN.Text) <> "" Then
txtRegnKey.Text = Encryptor.Encrypt(Trim(txtVSN.Text), strVersion)
Clipboard.Clear()
Clipboard.SetText(txtRegnKey.Text)
End If
Screen.MousePointer = vbDefault
cmdEncrypt.Enabled = False
mblnEncryptKeyPressed = False
End Sub
Private Sub Form_Load()
cmdEncrypt.Enabled = False
mblnEncryptKeyPressed = False
End Sub
Private Sub Form_Unload(ByVal Cancel As Integer)
mclsEncryptor = Nothing
End Sub
Now i have managed to change most of it but am struggling with the top private property. Everytime i put that in it says i need a main sub cos it starts to act like a command line application. This is the code that i have converted and fixed so far:
VB.NET:
Imports System.Security.Cryptography
PublicClass Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
PublicSubNew()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
EndSub
'Form overrides dispose to clean up the component list.
ProtectedOverloadsOverridesSub Dispose(ByVal disposing AsBoolean)
If disposing Then
IfNot (components IsNothing) Then
components.Dispose()
EndIf
EndIf
MyBase.Dispose(disposing)
EndSub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer. 
'Do not modify it using the code editor.
FriendWithEvents txtVersion As System.Windows.Forms.TextBox
FriendWithEvents txtVSN As System.Windows.Forms.TextBox
FriendWithEvents txtRegnKey As System.Windows.Forms.TextBox
FriendWithEvents cmdEncrypt As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> PrivateSub InitializeComponent()
Me.txtVersion = New System.Windows.Forms.TextBox
Me.txtVSN = New System.Windows.Forms.TextBox
Me.txtRegnKey = New System.Windows.Forms.TextBox
Me.cmdEncrypt = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'txtVersion
'
Me.txtVersion.Location = New System.Drawing.Point(48, 48)
Me.txtVersion.Name = "txtVersion"
Me.txtVersion.Size = New System.Drawing.Size(208, 20)
Me.txtVersion.TabIndex = 0
Me.txtVersion.Text = "TextBox1"
'
'txtVSN
'
Me.txtVSN.Location = New System.Drawing.Point(48, 80)
Me.txtVSN.Name = "txtVSN"
Me.txtVSN.Size = New System.Drawing.Size(208, 20)
Me.txtVSN.TabIndex = 1
Me.txtVSN.Text = "TextBox1"
'
'txtRegnKey
'
Me.txtRegnKey.Location = New System.Drawing.Point(48, 112)
Me.txtRegnKey.Name = "txtRegnKey"
Me.txtRegnKey.Size = New System.Drawing.Size(208, 20)
Me.txtRegnKey.TabIndex = 2
Me.txtRegnKey.Text = "TextBox1"
'
'cmdEncrypt
'
Me.cmdEncrypt.Location = New System.Drawing.Point(104, 160)
Me.cmdEncrypt.Name = "cmdEncrypt"
Me.cmdEncrypt.Size = New System.Drawing.Size(80, 32)
Me.cmdEncrypt.TabIndex = 3
Me.cmdEncrypt.Text = "Button1"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Controls.Add(Me.cmdEncrypt)
Me.Controls.Add(Me.txtRegnKey)
Me.Controls.Add(Me.txtVSN)
Me.Controls.Add(Me.txtVersion)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
EndSub
#EndRegion
Private mclsEncryptor As Encryptor
PrivateProperty Encryptor() As Encryptor
Get
If mclsEncryptor IsNothingThen mclsEncryptor = New Encryptor
Encryptor = mclsEncryptor
EndGet
Set(ByVal Value As Encryptor)
EndSet
EndProperty
PrivateSub cmdEncrypt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdEncrypt.Click
Dim strVersion As String
strVersion = " V" & Trim(txtVersion.Text)
If Trim(txtVSN.Text) <> "" Then
txtRegnKey.Text = Encryptor.Encrypt(Trim(txtVSN.Text), strVersion)
Clipboard.SetDataObject("")
Clipboard.SetDataObject(txtRegnKey.Text)
End If
EndSub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
End Sub
Private Sub Form_Unload(ByRef Cancel As Short)
'UPGRADE_NOTE: Object mclsEncryptor may not be destroyed until it is garbage collected. 
'Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1029"'
mclsEncryptor = Nothing
End Sub
End Class
Is there anyone that mite be able to help, i'm desperate. Thanks
 
Last edited by a moderator:
VB.NET:
Private mclsEncryptor As Encryptor
PrivateProperty Encryptor() As Encryptor
Get
If mclsEncryptor IsNothingThen mclsEncryptor = New Encryptor
Encryptor = mclsEncryptor
EndGet
Set(ByVal Value As Encryptor)
EndSet
EndProperty

Look to me like the above bit, should look like this...

VB.NET:
Private mblnEncryptKeyPressed As Boolean
Private mclsEncryptor As Encryptor
Private ReadOnly Property Encryptor() As Encryptor
Get
If mclsEncryptor Is Nothing
Then mclsEncryptor = New Encryptor
End If
Return mclsEncryptor
EndGet
EndProperty
 
Thanks, that helped.

One other problem when i was upgrading was the

VB.NET:
StrConv(plaintext, vbFromUnicode)

i gatherd it should be this:

VB.NET:
System.Text.UnicodeEncoding.Unicode.GetBytes(vstrPlainText)

would that be right.

Also this code:

VB.NET:
CopyMemory VarPtr(abBlock(0)), VarPtr(abData(iIndex)), 8&

to this:

VB.NET:
CopyMemory(BitConverter.ToInt32(abBlock, 0), BitConverter.ToInt32(abData, index), 8)

Any help would be great
 
Back
Top