473,503 Members | 3,715 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

?syntax to recognize code in a 2nd file

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.DoSomething( 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

Nov 21 '05 #1
8 1205

"iano" <Ia*****@gmail.com> wrote in message news:11**********************@g14g2000cwa.googlegr oups.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.DoSomething( 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 myEncryptDecrypt class


Imports System.Security.Cryptography

Imports System.Text

Imports System.IO

Public Class MyEncryptDecrypt

' Encrypt the text

Public Shared Function EncryptText(ByVal strText As String) As String

Return Encrypt(strText, "&%#@?,:*")

End Function

'Decrypt the text

Public Shared Function DecryptText(ByVal 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.Encoding.UTF8.GetBytes(Left(strEncrKey , 8))

Dim des As New DESCryptoServiceProvider

Dim inputByteArray() As Byte = Encoding.UTF8.GetBytes(strText)

Dim ms As New MemoryStream

Dim cs As New CryptoStream(ms, des.CreateEncryptor(byKey, IV), CryptoStreamMode.Write)

cs.Write(inputByteArray, 0, inputByteArray.Length)

cs.FlushFinalBlock()

Return Convert.ToBase64String(ms.ToArray())

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.Encoding.UTF8.GetBytes(Left(sDecrKey, 8))

Dim des As New DESCryptoServiceProvider

inputByteArray = Convert.FromBase64String(strText)

Dim ms As New MemoryStream

Dim cs As New CryptoStream(ms, des.CreateDecryptor(byKey, IV), CryptoStreamMode.Write)

cs.Write(inputByteArray, 0, inputByteArray.Length)

cs.FlushFinalBlock()

Dim encoding As System.Text.Encoding = System.Text.Encoding.UTF8

Return encoding.GetString(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(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

strtext = TextBox1.Text

TextBox2.Text = MyEncryptDecrypt.EncryptText(strtext)

Button2.Enabled = True

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

strtext = TextBox2.Text

TextBox3.Text = MyEncryptDecrypt.DecryptText(strtext)

End Sub

strtext is what is passed to the myEncryptDecrypt 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 myEncryptDecrypt. then Intelli-sense would show,,,,,,,,,,Decrypt & Encrypt as the choices and then after the

( , Like this: TextBox2.Text = myEncryptDecrypt.Decrypt(strtext) <<<<<<< 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



Nov 21 '05 #2
It looks like you're looking for Shared Subs and Shared Functions. These
are functions you can call without instantiating an instance of the object.
Here's a quick example to show the difference between a Shared Sub and a
Regular Class Method Sub:

' This class has to be instantiated to invoke the PrintHello method
Public Class SomeCode
Public Sub PrintHello()
Console.WriteLine("Hello World")
End Sub
End Class

' This class' Shared PrintHello method can be called without a
' MoreCode object being instantiated
Public Class MoreCode
Public Shared Sub PrintHello()
Console.WriteLine("Hello World")
End Sub
End Class

To call these functions, you would use code similar to the following:

' We instantiate a SomeCode object before we can call it's
' PrintHello() method
Dim s As New SomeCode
s.PrintHello()

' We don't need to instantiate a MoreCode object to call it's
' PrintHello() method
MoreCode.PrintHello()
"iano" <Ia*****@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.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.DoSomething( 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

Nov 21 '05 #3
Iano,

When you want to use your MoreCode class in your other Class, than you can
make from your class an object. Instance it.

dim myMoreCode as New MoreCode.

Now you can use that object with myMoreCode.function(mystring).

This myMoreCode object, will be removed when your function that creates this
goes out of scope (reaches the end sub).

Strange when you are used too classic coding. Yes, however it keeps your
programs nice small at run time. Althoughs OOP uses more overhead what you
should have to forget to think about, because you don't win real time to
avoid that.

I hope this helps,

Cor
Nov 21 '05 #4

Cor, your explantion helps a lot.
However, I managed to get a syntax error.

Rather than use myMoreCode in the executable part of the code, I
changed the
definition to:

Imports System

Namespace MoreCodecls <-- Should this be the same as the Class Name?

Public Class MoreCodecls

Public Sub New()

End Sub

Public Function strDBConnection(ByVal strServer As String, _
ByVal strDataBase As String) As String
....
and when I attempted to call the code from the form
Private Sub CboServersSelectedIndexChanged(sender As System.Object, e
As System.EventArgs)
Dim strConn As String
Dim MoreCode as New MoreCodecls

strConn = MoreCode.strDBConnection(Me.cboServers,"SomeName")
messagebox.Show(strConn)

End Sub
I got an error BC30182 in the line Dim MoreCode as New MoreCodecls

Hopefully, one more answer and I'll be able to complete this program.

IanO

Nov 21 '05 #5
Iano,

That class is it a seperated project (a dll class libary by instance) (and
than you need to set a reference) or a class in the same project?

Cor
Nov 21 '05 #6
As far as I am concerned it is in the same project.

But since I am such a beginner with dot Net, I may have done
*something* that makes the compiler think it is separate.

IanO

Nov 21 '05 #7
Iano,

Than try to paste it on the same page (beneath it) as is your program, than
you know it for sure.

I hope this helps,

Cor
Nov 21 '05 #8
In the meantime, I discovered
Public Module MiscFunctions
my other code

End Module

and the code is running!
Thanks Cor, I'll be trying the class again in a week or so.

IanO

Nov 21 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

699
33319
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
14
2280
by: Sandy Norton | last post by:
If we are going to be stuck with @decorators for 2.4, then how about using blocks and indentation to elminate repetition and increase readability: Example 1 --------- class Klass: def...
18
1754
by: Chris Mantoulidis | last post by:
There is a LARGE number of syntax styles in most (if not all) programming languages. For example, one syntax style (my current one): .... int main() { for (int i = 0; i < 50; i++) {
23
2494
by: Carter Smith | last post by:
http://www.icarusindie.com/Literature/ebooks/ Rather than advocating wasting money on expensive books for beginners, here's my collection of ebooks that have been made freely available on-line...
11
4293
by: Dale | last post by:
How to recognize whether file has XML format or not? Here is the code segment: XmlDocument* pDomDocument = new XmlDocument(); try { pDomDocument->Load(strFileName ) ; } catch(Exception* e) {
21
2307
by: Dmitry Anikin | last post by:
I mean, it's very convenient when default parameters can be in any position, like def a_func(x = 2, y = 1, z): ... (that defaults must go last is really a C++ quirk which is needed for overload...
2
1350
by: glomde | last post by:
Hi I would like to extend python so that you could create hiercical tree structures (XML, HTML etc) easier and that resulting code would be more readable. The syntax i would like is something...
2
2143
by: redcic | last post by:
Hi all, I would like to build a xml file using Xerces. I know how to build a single node at a time. For example, with 'doc' belonging to the DocumentImpl class and with 'docRootNode' belonging...
6
1228
by: John Kotuby | last post by:
Hi all, I was just looking at some example code in the VS2008 help for VB. In a JavaScript example I came across some syntax that I didn't recognize and could not find information about on the...
0
7192
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7064
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7261
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6974
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5559
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3158
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3147
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
369
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.