473,406 Members | 2,549 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Csharp's version of "VB Modules"

pod
298 100+
Here is my story,

When I wrote functions in Access using VB, I created functions in Modules where I could access them easily by just calling the name of the function. The same option exist in Windows Application using VB

The option "Modules" appear when I right-click on the project and select "Add" in VB but not in C#

Now I create Windows Application using C#.

My question is, ...
if I want to seperate my functions in different "modules" as in VB, what should I create, a new class, a new component?

thanks


Perry
Nov 5 '07 #1
21 1376
Plater
7,872 Expert 4TB
You mean classes?
Hehe chalk another one up for vb's strange naming conventions.

Add a new class file to your project
Nov 5 '07 #2
balabaster
797 Expert 512MB
You mean classes?
Hehe chalk another one up for vb's strange naming conventions.

Add a new class file to your project
Yeah, this is one of those areas where C# doesn't distinguish the difference between modules and classes but VB does. They do have subtle differences - for instance you can invoke a method within a module without having to specify the module name, whereas you can't with a class, and to provide (virtually) the same functionality you declare a method as shared instead of just public. The way you would do this is using shared methods so that you can invoke them using the following concept (but obviously in C#)

VB
Expand|Select|Wrap|Line Numbers
  1. Public Class MyClass1 
  2.   Public Shared Function MyMethod(ByVal Param1 As String) As String
  3.     Return SomeStringValue
  4.   End Function
  5. End Class
  6.  
  7. Dim MyString As String = MyClass1.MyMethod(MyParam)
C#
Expand|Select|Wrap|Line Numbers
  1. public class MyClass1{ 
  2.   public static string MyMethod(string Param1){
  3.     return SomeStringValue;
  4.   }
  5. }
  6.  
  7. string MyString = MyClass.MyMethod1(MyParam);
Make sure your method doesn't rely on any class-wide variables etc.
Nov 5 '07 #3
Plater
7,872 Expert 4TB
I'm not sure I see the difference between your VB code and the C# code? Or was that the point?
I thought "module" was just VBs way of like static class or something?
Nov 6 '07 #4
r035198x
13,262 8TB
Classes define templates for instantiating objects while modules cannot be instantiated. In C#, every method/variable must belong to a class (encapsulation).
Module data is like global variables which everyone is free to play around with. Class fields, however, are accessible according to the access modifier specified when they were defined.

It helps to use object oriented principles when programming in C#.
Nov 6 '07 #5
Plater
7,872 Expert 4TB
static classes cannot be instanciated.

I also didn't think VBNET had the ability to store code outside of any sort of class. (I know old school BASIC and it's derivatives were like that, using functions and subs, but that was pretty much "everything's in ONE class")
Nov 6 '07 #6
r035198x
13,262 8TB
static classes cannot be instanciated.
... neither can abstract classes.
The point is that classes can be instantiated while modules cannot.

static classes cannot be instanciated.

I also didn't think VBNET had the ability to store code outside of any sort of class. (I know old school BASIC and it's derivatives were like that, using functions and subs, but that was pretty much "everything's in ONE class")
Read this comparison.
Nov 6 '07 #7
Plater
7,872 Expert 4TB
So you can achieve close to the same functionality with static classes, the main difference is you have to type an extra word beforehand (staticclass.staticmember)

Doesn't seem like a horrible travesty to have better organization
Nov 6 '07 #8
r035198x
13,262 8TB
So you can achieve close to the same functionality with static classes, the main difference is you have to type an extra word beforehand (staticclass.staticmember)

Doesn't seem like a horrible travesty to have better organization
The best approach would depend on the "functions" that the OP wants to put in there. Perhaps they could be better organized into methods inside instantiable classes and be mabe available only to objects which have a reference to those objects.

I'm just worried about the overuse of statics by .NETTers these days to avoid good program design.
Nov 6 '07 #9
Plater
7,872 Expert 4TB
The over-use of statics would be no different then the over-use of modules.
Nov 6 '07 #10
r035198x
13,262 8TB
The over-use of statics would be no different then the over-use of modules.
It wouldn't. That's why I stay as far away from VB as my keyboard allows me and curse everytime I look at a .NET program.
Nov 6 '07 #11
Plater
7,872 Expert 4TB
I've seen you naysay C# and VB(and vb.net), so what *DO* you program in?
Java and C# are almost interchangable (minus the crazy microsoft stuff) so I'd say java is out. C++ is just an awful mess too ("too many fingers in the pot" I'd say)
Perl is so unrestricted and doesn't get much use outside of being a backend script for web. The latter applies to PHP as well.

Python?
Nov 6 '07 #12
r035198x
13,262 8TB
I've seen you naysay C# and VB(and vb.net), so what *DO* you program in?
Java and C# are almost interchangable (minus the crazy microsoft stuff) so I'd say java is out. C++ is just an awful mess too ("too many fingers in the pot" I'd say)
Perl is so unrestricted and doesn't get much use outside of being a backend script for web. The latter applies to PHP as well.

Python?
Actually I don't like writting programs in any language at all.
Programs never do what you tell them to do.
I feel better writting Java programs though (because I get paid for it).
Python is not very interesting (to me). I never liked interpreted (and non free form) languages anyway.
Nov 6 '07 #13
balabaster
797 Expert 512MB
Actually I don't like writting programs in any language at all.
Programs never do what you tell them to do.
I feel better writting Java programs though (because I get paid for it).
Python is not very interesting (to me). I never liked interpreted (and non free form) languages anyway.
Au contraire mon ami - programs do exactly what you tell them to. They're just not smart enough to interpret things in the way that maybe we would as humans. Treat it like a 3 year old that doesn't understand sarcasm or deadpan humour and you'll do just fine ;)
Nov 6 '07 #14
Plater
7,872 Expert 4TB
I always considered java interpreted. Since it pretty much has a CLR (java runtime anyone) and to run java programs you have to start a java instance with your program as an argument.
Nov 6 '07 #15
balabaster
797 Expert 512MB
I always considered java interpreted. Since it pretty much has a CLR (java runtime anyone) and to run java programs you have to start a java instance with your program as an argument.
I think it was the Java model that Microsoft mimicked when designing the CLR...I've noticed since I started programming in C# that Java makes a lot more sense than it used to...of course, it's like a micky mouse language. All real programmers use .NET :oP
Nov 6 '07 #16
pod
298 100+
well ... thank you all for this enlighting exchange, I hope one day I'll be able to understand it all :)

seriously it confirmed what I was already doing.

I created a bunch of custom functions that I use in multiple apps, and now instead of calling a function by its name, I now use the long name

customFunctions.stringFunctionsClass.myfunction(.. .)

which is fine, not terse but OK.

Merci
Nov 6 '07 #17
balabaster
797 Expert 512MB
I'm not sure I see the difference between your VB code and the C# code? Or was that the point?
I thought "module" was just VBs way of like static class or something?
Yeah, it wasn't to highlight the differences, I just tend to post code in both languages (unless I'm in a rush). Not so much to distinguish any difference between the languages conceptually, but to make it easier for people that don't program in both languages.

...and I guess that a VB module is very similar to a static class, the only slight difference is that with a module you can reference the method without referencing the module name whereas with a static class you can't...so you have to write it out longhand.
Nov 6 '07 #18
r035198x
13,262 8TB
Au contraire mon ami - programs do exactly what you tell them to. They're just not smart enough to interpret things in the way that maybe we would as humans. Treat it like a 3 year old that doesn't understand sarcasm or deadpan humour and you'll do just fine ;)
You haven't seen them slow down for no apparent reason and develop memory leaks just to spite you?



I always considered java interpreted. Since it pretty much has a CLR (java runtime anyone) and to run java programs you have to start a java instance with your program as an argument.
Of course technically all languages are interpreted but I meant languages which don't have to be compiled to an intermediate language ... and in which programs are able to modify themselves while they are running ...
Nov 7 '07 #19
balabaster
797 Expert 512MB
You haven't seen them slow down for no apparent reason and develop memory leaks just to spite you?
3 year olds? ... lol
Nov 7 '07 #20
Plater
7,872 Expert 4TB
You haven't seen them slow down for no apparent reason and develop memory leaks just to spite you?
If by memory leaks you mean urination, yes 3year olds slow down just enough to do that somwhere

Of course technically all languages are interpreted but I meant languages which don't have to be compiled to an intermediate language ... and in which programs are able to modify themselves while they are running ...
Well that's what I meant. Java programs are compiled to a special java language. Then the java runtime interprets that language. Just like a .NET, only difference is that .net's get a .exe extension and call the runtime withen themselves, where as with java you have to tell the OS which program to run your java files (geez it's been so long I don't even remember java extensions... jar?)


(And yes I fully believe C# is a direct rip from java)
Nov 7 '07 #21
r035198x
13,262 8TB
If by memory leaks you mean urination, yes 3year olds slow down just enough to do that somwhere


Well that's what I meant. Java programs are compiled to a special java language. Then the java runtime interprets that language. Just like a .NET, only difference is that .net's get a .exe extension and call the runtime withen themselves, where as with java you have to tell the OS which program to run your java files (geez it's been so long I don't even remember java extensions... jar?)


(And yes I fully believe C# is a direct rip from java)
We compile the .java files into .class files which run on a mini OS called the JVM. When we have many class files we bundle them into one .jar file, but we digress ...
Nov 7 '07 #22

Sign in to post your reply or Sign up for a free account.

Similar topics

47
by: Will Stuyvesant | last post by:
Hello all, So Zope still lives, yay. Well, I like that they use Python. <rant> What amazed me is they write that they "added types to the variables and hope that it will be added to the...
5
by: Steven T. Hatton | last post by:
I've seen people here write that C++ doesn't support modules. What does that mean? 'Module' is a very nebulous term in my book. It probably means something quite different to me than what it does...
9
by: MLH | last post by:
I need a fundamental explanation of Class Modules - something suitable for newbies. Access 2.0 didn't seem to focus on them very much. Now that I'm using Access 97, it seems they're everywhere. thx...
5
by: BH | last post by:
Hi what would be the C# equivalent of a VB.NET file that looks like this: Module Utilities Public Sub UtilitySubOne ( ByVal arg As String) // blah blah End Sub
16
by: Andrew Baker | last post by:
I am trying to write a function which provides my users with a file filter. The filter used to work just using the VB "Like" comparision, but I can't find the equivilant in C#. I looked at...
1
by: Nice | last post by:
Are they the same thing?
1
by: pcnerd | last post by:
I have VB.NET 2005 Express Edition. Is there a VB.NET equivalent to the "classic" VB's DoEvents? I searched the VB.NET Help & had no luck. In "classic" VB, DoEvents was used in code that might...
0
by: Rod | last post by:
I have made a copy of my (ASP.NET) project and renamed it everywhere I could find. I am stuck with one bit I can't figure out. The line at the top of the HTML which looks like this %@ Page...
8
by: cj | last post by:
I've seen examples of web services written with <%@ WebService Language ="Vb" Class=".... at the top. Is it not used in VB 2008?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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,...
0
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...

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.