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
21 1376
You mean classes?
Hehe chalk another one up for vb's strange naming conventions.
Add a new class file to your project
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 - Public Class MyClass1
-
Public Shared Function MyMethod(ByVal Param1 As String) As String
-
Return SomeStringValue
-
End Function
-
End Class
-
-
Dim MyString As String = MyClass1.MyMethod(MyParam)
C# - public class MyClass1{
-
public static string MyMethod(string Param1){
-
return SomeStringValue;
-
}
-
}
-
-
string MyString = MyClass.MyMethod1(MyParam);
Make sure your method doesn't rely on any class-wide variables etc.
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?
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#.
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")
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.
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
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.
The over-use of statics would be no different then the over-use of modules.
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.
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?
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.
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 ;)
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 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
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
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.
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 ...
You haven't seen them slow down for no apparent reason and develop memory leaks just to spite you?
3 year olds? ... lol
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)
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 ...
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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
|
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...
|
by: Nice |
last post by:
Are they the same thing?
|
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...
|
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...
|
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?
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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,...
|
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...
| |