View Full Version : Visual Basic
turey22
12-20-08, 12:28 PM
Anyone her familiar with Vb? I have a simple question that i should of asked my teacher but i cant get of hold of her...but in Vb can you use DIM in the Event? like ex....
Private Sub btnNew_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNew.Click
Dim intNumTries As Integer = 0
End Sub
or does this have to go in the public area?
thank you if you can answer this...i know theres a lot of forums out there but i like you guys better.
turey22
12-20-08, 12:32 PM
what i need to do is set intNumTries to 0...but i already have it already declared...but i wasnt sure if you can use Dim in the event or only when you declare variable
dennisj00
12-20-08, 03:28 PM
You can declare in the event, however if declared there it is only available to that event. Once you exit the event intNumTries goes out of scope. If you need it available to your entire module then declare it in the public section and just reference it in your event.
(Actually answered by my wife, VB / VS guru)
turey22
12-20-08, 04:38 PM
Thanks wife...and of cousre dennisj00. much appreciated...This VB is hard sometimes.
turey22
12-20-08, 06:02 PM
Btw VB sucks so its really cool that your wife is a guru at it.
wilbur_the_goose
12-20-08, 06:55 PM
My opinion - if it's declared externally, use a different variable.
And, coding style - I prefer:
Dim iTries as integer
iTries = 0
I strongly suggest you use the first letter of your variable (any language) to indicate the type of variable. The person debugging your code in 4 years will thank you.
I'm with Wilbur for the most part. Some data types you can't DIM and assign values to at the same time.
And as to VB sucking - I've been making a living at it for quite some time now. Shall we have fun and start a VB/C# war now? :) But, then, I go back to Dartmouth BASIC, old DEC RSTS versions of Basic, COBOL and even a little Fortran "back in the day".
... Shall we have fun and start a VB/C# war now? :) ...
Let's expand the war .. VB/C#/Delphi
Delphi still retains at least one fan here in the US but is much more popular abroad. I've turned out some nice desktop apps and a few VCL components coded in Delphi. I think the component programming concept began with Borland's Delphi. I consider that concept to be pure genius.
--- CHAS
wilbur_the_goose
12-21-08, 06:36 PM
Kids.. I've been in IT since 1980. We still had a card reader back then (ughh!).
Remember - the most used language in the world is clunky old COBOL.
As far as VB goes, it's very good for what it's good for. It's compiled, so it's fast (if you write it well). And it's kinda/sorta OO.
Well, VB is no more compiled than C# (compiled down to MISL or what we used to call "p-code"). Heck, I've even heard of F#.Net, Ruby.Net and COBOL.Net (if you can believe it).
From my personal experience (and it's by no means completely comprehensive), C# would get some of the OO concepts first and VB would get usability concepts first. I saw a lot of VB upgrades that included thing that were in the previous version of C# along with the reverse being true (things in the VB IDE or other areas of the language coming out in the following C# release)
dbconsultant
12-22-08, 11:54 AM
My husband is an old Cobol guy (all the way back to the punchcard days). I started with VB4 and kept going through VS2005 and ASP.net with VB. A good argument was given in one of my ASP books, "Those that programmed with VB will probably do ASP.net with VB just because that is what they are comfortable with and the same goes for c++/C# programmers."
So I did this whole book, cover-to-cover to learn ASP.net using VB only to find out that most companies these days want C# so this last year I forced myself to switch to C#. I've actually found that some things are easier in VB and some things are easier in C# so there's good in both languages.
Oh, well, at least I don't mind learning new stuff AND I found a company willing to pay me while I learn! Doesn't get much better than that in this economy!
:computer:
jadebox
12-23-08, 12:52 PM
Anyone her familiar with Vb? I have a simple question that i should of asked my teacher but i cant get of hold of her...but in Vb can you use DIM in the Event? like ex....
Private Sub btnNew_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNew.Click
Dim intNumTries As Integer = 0
End Sub
or does this have to go in the public area?
thank you if you can answer this...i know theres a lot of forums out there but i like you guys better.
Depending on how you want to use the value, you would declare intNumTries in a public area (if you need to access it outside your event handler). Or you can declare it inside btnNew_Click if the value is only needed in the handler.
If you want the value to start at zero each time btnNew_Click is called, then declare it as you have above. If you want it to be set to zero when your program starts, but the value to be remembered between calls to btnNew_Click, then delcare it as Static:
Static intNumTries as Integer = 0
BTW ... VB code is compiled. It can be compiled into either p-code or native code, but it is always compiled.
And, personally, I wouldn't recommend using "Hungarian Notation" (adding the type as part of the variable name). It makes some sense for weakly-typed languages like C, but in the case of most modern languages it's not needed and can add confusion if a variable's type is changed or the wrong notation is used.
-- Roger
BillyT2008
12-23-08, 01:12 PM
I worked with a guy named Charlie Calvert at Borland who was on the PASCAL technical support team at the time (I was on the C++ technical support team back then) and Charlie is one of the smartest guys I have ever known. Charlie is now the Community Program Manager of C# and works for Microsoft. His C# blog can be read at http://blogs.msdn.com/charlie/.
For me the transition from C# was derived from using Visual C++ with MFC which derived from using Borland C++ over the course of various jobs I've held over the years. For Charlie, the transition went from Turbo Pascal to Delphi to Java to Borland C++ Builder and then to C# over the course of jobs he has held.
Most of the development I do now is using C# with SQL Server. Visual BASIC is a good programming language, but all of the end sub, end function, end this and that commands are not for me. Give me curly braces to define the scope of data any day of the week over that. Most of the people I have ever worked with are now using C# (and C++ for anything needed to be unmanaged) and if I were to recommend any programming languages to anyone looking to learn about programming from this point into the forseeable future, I would recommend learning C# (and maybe C++ if you wanted to learn about memory management, etc).
C# 4.0 should be interesting as Microsoft is adding the ability to define dynamic objects using a new 'dynamic' keyword (which will essentially allow you to create objects without all of the compiler type-checking and allow the type for the object to be included "late bound" as a reference. Also they will be adding the ability to create methods with optional parameters (with default values) and also allow you to call the method and provide the parameters in any order using a <parametername>: syntax.
wilbur_the_goose
12-23-08, 06:50 PM
Having done this for 20+ years, one truth stands above all.
Develop an algorithm well, and you can write it in any language. Going from FORTRAN to PASCAL to COBOL to VB to C to whatever is next is just rethinking HOW your implement your algorithm.
Do the algorithm first, and you will be very successful, very flexible, and hopefully gainfully employed.
Having done this for 20+ years, one truth stands above all.
Develop an algorithm well, and you can write it in any language. Going from FORTRAN to PASCAL to COBOL to VB to C to whatever is next is just rethinking HOW your implement your algorithm.
Do the algorithm first, and you will be very successful, very flexible, and hopefully gainfully employed.
And if the code is getting ugly, then revisit the algorithm.
--- CHAS
wilbur_the_goose
12-23-08, 08:29 PM
HIPAR - Amen to that!
Algorithm uber alles! :)
Seriously, though, the "end this" and "end that" are for readability. It's really a matter of personal preference but I find the braces and semicolons everywhere to be unpleasant to look at. Part of that is probably due to the amount of legacy code I've had to come in and fix up.
vBulletin® v3.7.6, Copyright ©2000-2010, Jelsoft Enterprises Ltd.