473,654 Members | 3,115 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.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

Nov 21 '05 #1
8 1213

"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



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.WriteLi ne("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.WriteLi ne("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.PrintH ello()
"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

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.func tion(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 CboServersSelec tedIndexChanged (sender As System.Object, e
As System.EventArg s)
Dim strConn As String
Dim MoreCode as New MoreCodecls

strConn = MoreCode.strDBC onnection(Me.cb oServers,"SomeN ame")
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
33862
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 capabilities, unfortunately. I'd like to know if it may be possible to add a powerful macro system to Python, while keeping its amazing syntax, and if it could be possible to add Pythonistic syntax to Lisp or Scheme, while keeping all of the...
14
2298
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 __init__(self, name):
18
1765
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
2521
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 by their authors. There are lots of them out there but this selection cuts out the junk. If you know of any other good books that are freely available please post a link to them here and I'll consider adding them to the site.
11
4310
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
2325
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 resolution, isn't it?) and when calling, just omit parameter when you want to use defaults: a_func(, , 3)
2
1360
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 like the below: # Example creating html tree '*!*' is an operator that creates an new node '*=*' is an operator that sets an attribute.
2
2155
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 to the ElementNSImpl class, I do: myElement = doc.createElement('elementName') docRootNode.appendChild(myElement)
6
1240
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 usual JS sites I use as resources. In a place where I expected to see "document.getElementById('elementId')", instead the Microsoft example use the syntax "$get('elementid')". So I tried it in some of my code and it seems to work fine. Can...
0
8376
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8290
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8708
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8594
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7307
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6161
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5622
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4149
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1596
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.