"iano" <Ia*****@gmail. com> wrote in message news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
I am trying to clone a VB6 app in Vb.Net as a learning exercise. For
this effort I am not using Visual Studio.Net. So Far I have a form
with a label, combobox and a command button. As I have done in VB6, I
like to keep form code in the form and other code in a separate module
so it is easier to reuse.
As I understand it, regular modules do not exist in VB.net so
I added a class to the project and called it MoreCode. It seemed to me
that I could execute methods in the class by using
MoreCode.DoSome thing( argument list).
But so far, I have not succeeded in getting the VB compiler to
recognize the MoreCode class.
Please tell me in as much detail as possible (or point to an example)
that illustrate what is needed.
Thanks in Advance,
IanO
Here's something I did from some other examples I found online to encrypt and decrypt text:
the new myEncryptDecryp t class
Imports System.Security .Cryptography
Imports System.Text
Imports System.IO
Public Class MyEncryptDecryp t
' Encrypt the text
Public Shared Function EncryptText(ByV al strText As String) As String
Return Encrypt(strText , "&%#@?,:*")
End Function
'Decrypt the text
Public Shared Function DecryptText(ByV al strText As String) As String
Return Decrypt(strText , "&%#@?,:*")
End Function
'The function used to encrypt the text
Private Shared Function Encrypt(ByVal strText As String, ByVal strEncrKey As String) As String
Dim byKey() As Byte = {}
Dim IV() As Byte = {&H12, &H34, &H56, &H78, &H90, &HAB, &HCD, &HEF}
Try
byKey = System.Text.Enc oding.UTF8.GetB ytes(Left(strEn crKey, 8))
Dim des As New DESCryptoServic eProvider
Dim inputByteArray( ) As Byte = Encoding.UTF8.G etBytes(strText )
Dim ms As New MemoryStream
Dim cs As New CryptoStream(ms , des.CreateEncry ptor(byKey, IV), CryptoStreamMod e.Write)
cs.Write(inputB yteArray, 0, inputByteArray. Length)
cs.FlushFinalBl ock()
Return Convert.ToBase6 4String(ms.ToAr ray())
Catch ex As Exception
Return ex.Message
End Try
End Function
'The function used to decrypt the text
Private Shared Function Decrypt(ByVal strText As String, ByVal sDecrKey As String) As String
Dim byKey() As Byte = {}
Dim IV() As Byte = {&H12, &H34, &H56, &H78, &H90, &HAB, &HCD, &HEF}
Dim inputByteArray( strText.Length) As Byte
Try
byKey = System.Text.Enc oding.UTF8.GetB ytes(Left(sDecr Key, 8))
Dim des As New DESCryptoServic eProvider
inputByteArray = Convert.FromBas e64String(strTe xt)
Dim ms As New MemoryStream
Dim cs As New CryptoStream(ms , des.CreateDecry ptor(byKey, IV), CryptoStreamMod e.Write)
cs.Write(inputB yteArray, 0, inputByteArray. Length)
cs.FlushFinalBl ock()
Dim encoding As System.Text.Enc oding = System.Text.Enc oding.UTF8
Return encoding.GetStr ing(ms.ToArray( ))
Catch ex As Exception
Return ex.Message
End Try
End Function
End Class
Then I call it this way:
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click
strtext = TextBox1.Text
TextBox2.Text = MyEncryptDecryp t.EncryptText(s trtext)
Button2.Enabled = True
End Sub
Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button2.Click
strtext = TextBox2.Text
TextBox3.Text = MyEncryptDecryp t.DecryptText(s trtext)
End Sub
strtext is what is passed to the myEncryptDecryp t Class.
Each function is called( Decrypt or Encrypt) and strtext is passed to that function. Once I got it figured out correctly,
whenever
I type in myEncryptDecryp t. then Intelli-sense would show,,,,,,,,,,D ecrypt & Encrypt as the choices and then after the
( , Like this: TextBox2.Text = myEncryptDecryp t.Decrypt(strte xt) <<<<<<< the string I wanted to decrypt.
So, that is my basic understanding of how to do a Class. I am not real good at it, but, I think this will give you the general
idea.
james