locked
Substitute for VB's 'Module', in C#? RRS feed

  • Question

  • Is there something thats similar to a module in VB, in C#

    Because I want my variables to be used widely, so I can use isclicked=true ,

    instead of frmwhatever.isclicked=true

     

    I'm using C# 2005 Express

    Monday, August 28, 2006 1:18 AM

Answers

  • there are many topics on the forums about this, turning out to be a religous war! :-) but yes, majority of companies using .NET would like C# developers as standard since C# is an industry standard language
    Monday, August 28, 2006 11:48 AM

All replies

  • not sure about modules, if you need your variables to be used widely, either create the variable private globally, and or have a get/set property for other classes to access it, or create a class file, which is shared amoungst other classes to get and set properties.

    From what it sounds like, module files maybe pretty much the same as a Class file in C#, equivilent to it perhaps

    Monday, August 28, 2006 1:34 AM
  • k, I'll try that

    === Edited by Predator14567 @ 28 Aug 2006 2:13 AM UTC===
    Ok, I created a class, but how do I declare the variables inside it, I can declare public static int something, but in order for it to work through another file, you have to do class1.bob= 2, and it only works when declared public static

    Monday, August 28, 2006 2:04 AM
  • Modules is just one of the many things that VB has the C# does not , or at least not easily.

    You actually have to create a class and give that class all static (shared in vb) members or methods. You then must reference those method through the classname. So your class would look like:

    public class myCommon
    {
         public static String csSQL = "myconnection string";
         public static double TaxRate = 0.07;

    and your consuming code would look somthing like:

    private void frmDemo_Load(object sender, EventArgs e)
    {
         this.Text = myCommon.csSQL;
    }

    Now, obviously you’re not going to put a connection string as the label of a form, but you should get the idea...

     

    Long Live VB !

    Monday, August 28, 2006 2:36 AM
  • k, thanks, I see your a vb fanatic hehe
    Monday, August 28, 2006 2:50 AM
  • What advantages do you see in using c# express, compared to visual basic express? Is something being sort of forced on you by an employer, maybe?
    Monday, August 28, 2006 11:34 AM
  • there are many topics on the forums about this, turning out to be a religous war! :-) but yes, majority of companies using .NET would like C# developers as standard since C# is an industry standard language
    Monday, August 28, 2006 11:48 AM
  • C# is only a 'standard' because some people (probably those who know no better...) have said "Make it so" as neither C# nor its evil twin, JAVA, are anywhere near as mature of a language as BASIC or even Visual BASIC.

    For instance, even this method of mimicking a VB "module" is incomplete. One thing that I find valuable in VB is to declare a public string that's value is assigned from the app.config (or web.config). Can NOT be done in C# because reading the config file is not a "static method", which in C# requires an instance variable, but not in a module in VB

    JIHAD!!! Long Live VB.

    cheers.

    Monday, August 28, 2006 1:37 PM
  • Cmon guys !

     

    Everyone has their favourite poison. I personally like C#. Not because I am forced to like it by some evil empire. The empire I work for does not even use .NET

     

    Some people like C# and others like VB. The end product is the same MSIL.

     

    Regards

    Sunday, September 21, 2008 10:38 AM
  • Ahmed is right, see http://telerikwatch.com/2008/04/survey-says-c-more-popular-than-vb.html

     

    The reason for this is plain. Since C# is more strict, it tends to produce programmers who think more in terms of object orientation, design patterns. VB.NET has many things for backward compatibility and allows programmers to be more sloppy and get away with it. Then it becomes a habit and before long, experienced users are recommended their poor practices to others as the way to do things.

     

    When they see C# folks programming to interfaces and not to implementations, leveraging design patterns and using advanced features, (which is the norm for even the most basic C# guy) they (VB folks) simply don't understand it. In the VB.NET world these things seem to be esoteric to only the few that actually are ambitious enough to want to know more. These folks inevitably turn to C#. And when they do, they never turn back.

     

    Remember basic stood for (Beginners All Purpose Symbolic Instruction Code). It was taken for granted when a programmer wanted to know the deep things, they would switch languages. Personally, I would never hire a VB person.

     

    Let's not pretend Microsoft didn't have reasons for different languages in .NET. They did. C# (read the documentation and specification) was designed for enterprise level projects, while VB is for smaller scale projects. The end product is the same MSIL? Even that is debatable because even in some areas C# is better then VB. Additionally, C# can do things like work with pointers, while still VB.NET can't. Reason? Only an advanced developer would need to. That is why VB doesn't allow this. This alone speaks for itself.

     

    So my VB biased friend, do not expect us in the C# room to not have some say in the matter.

     

    Cos, Why don't you go assist in the VB room if you have such an evangelistic attitude towards VB? You should offer your personal opinions of languages when asked rather then dissing a language in that language forum. It is very unprofessional. Especially when it comes down to promoting mediocrity in programming practices, like Modules.

     

    For instance you say

    "For instance, even this method of mimicking a VB "module" is incomplete. One thing that I find valuable in VB is to declare a public string that's value is assigned from the app.config (or web.config). Can NOT be done in C# because reading the config file is not a "static method", which in C# requires an instance variable, but not in a module in VB"

     

    This shows how inexperienced you are as a programmer and clearly demonstrates your inability to think in object oriented ways. Additionally, the app.config can be done via the ConfigurationManager class in C#, so why do you say things that are blatantly wrong and untrue?

     

    Modules don't exist in the C# paradigm for obvious reasons. We do everthing in OO terms (Encapsulation, Inheritence, Polymorphism). VB folks still have trouble with OOA/OOD/OOP, so they need "Modules". C# developers don't need the training wheels for their bikes.

    • Proposed as answer by BellaMatte Thursday, August 16, 2012 4:53 PM
    • Unproposed as answer by BellaMatte Thursday, August 16, 2012 4:53 PM
    Sunday, September 21, 2008 2:55 PM
  • JohnGrove:
    Cos, Why don't you go assist in the VB room if you have such an evangelistic attitude towards VB? You should offer your personal opinions of languages when asked rather then dissing a language in that language forum. It is very unprofessional. Especially when it comes down to promoting mediocrity in programming practices, like Modules.

    And after saying that, you go and "diss" VB right back. You shouldn't tell someone not to do something then do it yourself. Instead of arguing, why don't we just say that VB is better in some ways, and C# is better in some ways. Arguing over an opinion is useless.
    Sunday, September 21, 2008 9:30 PM
  • When someone offers bogus reasons why another language is better then another without clearly knowing what they are talking about, I felt it is only fair to offer my 2 cents. Most of what I said is fact, so if you have issue with that all I can say is I'm sorry you feel that way.

     

    You say "why don't we just say that VB is better in some ways, and C# is better in some ways". Because I don't think it is true, why should I state something I believe to be untrue? Don't take it so personal. He offered his opinions, I offered mine.

     

    Sunday, September 21, 2008 11:20 PM
  • Modules are most akin to declaring a class as static in C#.

     

    EDIT:  As noted above, there is no actual C# equivalent.  Modules are a throwback to Visual Basic's roots.  The old, procedure-driven BASIC language had subroutines.  Remember GOSUB?

    Monday, September 22, 2008 5:23 PM
  • Agreed.

    C# is supposed to be OOP and event-driven.

    OOP means no "wide" variables.  It's against it's base principle.

    And tbh, the company I work for uses template-driven procedural languages, and it sucks... You constantly have to "assume" your collegues didn't mess with the "global properties", that the users have only one instance of a form open at any given time, etc etc etc...

    Not saying you shouldn't use them.  Just saying, try to avoid them whenever you can!

     

    PS: C#er for life.

     

    Tuesday, September 23, 2008 3:57 PM
  • (I am the rayms of a few posts back, and a few years ago - can't now get in on original account)

    As it was explained to me, about 12 years ago - OOD/OOP, you sort of got to unplug your brain, and plug it in sideways. Of course, that was when perhaps the more pure oop language was smalltalk, which now hardly seems to exist - I think C# tends to try to be something for everyone.

    I think I should refrain from being critical too much - I wouldn't know where to begin But, I think there could be more emphasis on how the fundamental's are different - there seems almost to be a deliberate policy of osfuscation within the help files, worse in 2008, then back in 2005, or maybe I shouldn't have left it for a few years.

    Best wishes,

    Ray
    Tuesday, September 23, 2008 6:03 PM
  •  raymser wrote:
    (I am the rayms of a few posts back, and a few years ago - can't now get in on original account)

    As it was explained to me, about 12 years ago - OOD/OOP, you sort of got to unplug your brain, and plug it in sideways. Of course, that was when perhaps the more pure oop language was smalltalk, which now hardly seems to exist - I think C# tends to try to be something for everyone.

    I think I should refrain from being critical too much - I wouldn't know where to begin But, I think there could be more emphasis on how the fundamental's are different - there seems almost to be a deliberate policy of osfuscation within the help files, worse in 2008, then back in 2005, or maybe I shouldn't have left it for a few years.

    Best wishes,

    Ray

     

     

    I started programming BASIC way back in 1971 using a PDP-8 and the ASR-33.  BASIC has evolved over the years reaching its peak in th 1980s during the proliferation of so many brands of home computers, each running a slightly different BASIC interpreter.  The result.  More times than not, a program written for one platform could not be ported to another.

     

    Microsoft attempted to standardize BASIC when it introduced Visual Basic.  Today, there are two ways or approaches to VB programming.  There's VisualBasic which attempts to recreate the original feel and syntax of BASIC, minus the line numbers.  That means, aside from numerical value types and strings, most everything that you are doing is found within the VisualBasic namespace of the FCL.

     

    Then there's VB.NET which is essentially using the types defined within the System namespace.  C# shares more in common with VB.NET than it does Visual Basic.  I assumed that the original question dealt with this second approach.  Someone was attempting to translate VB.NET to C#.NET. 

     

    Most folks that I have met who swear by Visual Basic don't constrain themselves to the VisualBasic namespace.  They feel that the expanded "keywords", types in C#, adds power to the language that C# does not provide.  Also, a person's opinion is shaped heavily by their experiences.  In the past, programmers tended to stick with the first language they learn really well.  I have notice that most who swear allegiance to VB tend to be these older programmers, or younger ones who cut their teeth at the feet of these mentors.  Nothing wrong with that.

     

    There is only one standard for judging whether or not code is properly written.  "Can you read, edit, and maintain the code in the future, near term and long term?"  If your code cannot meet that simple standard, why go through the trouble of even writing it?

     

    Rudedog  =8^D

    Tuesday, September 23, 2008 6:31 PM
  • Hi Rudedog,

    I guess we could chew the fat, I think I may even have been at it longer than you, but from IBM fortran roots. The 'best', most impressive basic I ever used was Microsoft visual basic for msdos - I still use it for quick and very dirty stuff. I have a program that runs on most machines, and I port it to other languages to test out the ease of use of the language - a bit more than 'hello world'.

    What takes the time now, is the gui - that is what seems to be the major 'selling point' today. I find the model/view/controller paradigm to be very powerful, and the big thing, for me with c#, is how easy that is to apply, but initially there is plenty of refactoring required. There is a slight problem, in that the view is tied in fairly tightly with the controller, in the simpler apps I deal with, and to overcome that I find I start poking into regions that I am warned not to poke into. I'm afraid I can't abide the fancy new click-once installation thing, but when I get too bothered by it, I'll sort it out. wrt the help I personally find more help outside of the microsoft in built helpfile  system, too many broken links, mix up with c++ and basic.

    Today's code, is sort of self documenting - use of almost meaningful names, etc. but it fails when the case changes as in much of the help example text. e.g. if the software insists on  'textBox', then no use if the help shows 'Textbox' (not saying that that in particular, but many instances of similar) It makes me wonder if it may be better that syntax was not so rigorous, since even the Microsoft folk get confused. Of course, once you are familiar with it all, then it appears so easy.

    I suppose, eventually it will be one language 'visual c#java++' or some such, running some p code on a 20GB .Web framework, and still the banks will make money out of floating point errors

    (and what do these emoticons signify - other forums - right click comes up with smile, blush, whatever - here we got to second guess.)

    Best wishes,

    Ray
    • Proposed as answer by jvelezc Wednesday, March 9, 2011 12:15 AM
    Tuesday, September 23, 2008 8:15 PM
  • Use a namespace in c#. Declare the class public and the functions public and the variables public. Instantiate the class then you will have a module.
    Wednesday, March 9, 2011 12:18 AM