PDA

View Full Version : Visual Basic


basicxman
11-12-2007, 10:31 PM
I'm not exacly sure where to put this thread but....

Does anyone here program Visual Basic and have any tips. Microsoft Visual Basic 2005 Express is free and it's awesome. I've been developing for about half a year now. Also Coding4Fun (an msdn blog) is a great place to start.

jee7s
11-12-2007, 11:37 PM
Though I might not agree with all of what Microsoft does, they do bring new meaning to RTFM. One of the better benefits of the Visual Studio system is the help. Basically, if you want to do something, search the help, and more than likely there's already something in the .NET framework ready for you to use.

If you can learn to read the documentation that Microsoft provides and learn to implement what they give you, you should have a pleasant VB experience.

However, VB has limitations...the professional CS types tend to use Java, C++ or C#, which give greater control over the processes.

Java is platform independent, meaning it will run on a Mac, Linux, or Windows computer, provided it has the Java software (VM) from Sun.

C++ allows you to program at low levels, even in assembly (think: controlling the processor step by step).

C# is something of a blend. The syntax is c-style (as opposed to VB-style), but it is like VB with regard to the ease of use.

That should give you a brief picture of what is going on.

Chief Pride
11-13-2007, 04:58 AM
i agree with the above, learning visual basic before any other languages should be avoided, it will teach you bad habbits that are hard to break when you move to a new language, such as c++

Robostang 548
11-13-2007, 06:16 AM
I suggest that you familiarize yourself with the .net framework namespaces. It took me a while to get used to using the .net namespaces instead of the vb6 ones. Also, try playing around with the serial port class and your RC. I made a vb.net program that takes sensor data printf'd to the serial port graph on my laptop.

-Don

basicxman
11-13-2007, 07:48 AM
well, i agree with u guys somewhat but ive been programming visual basic for a year and love it! i have to admit running programs is a bit slow but, meh!
i also have a BasicX microcontroller which programs on visual basic and the BasicATOM programs with basic as well

as for C and C++ i know the basics of (how can i be on a robotics team without at least knowing easyC) and im not screwed up by anything, i also know HTML, Javascript, CSS and im still not screwed up

oh and by the way im sure a lot of you will agree but in c++ or sometimes C i hate those semicolons ;;;;;; :mad: :mad: :mad: :mad:

whitetiger0990
11-13-2007, 11:20 AM
"It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration."

I'm not one to argue with Edsger Dijkstra. =)

jee7s
11-13-2007, 01:54 PM
Actually, those semi-colons are really useful in C/C++/C#. In all three cases, you can write several lines of neatly formatted code (a long string or calculation for instance) without needing to do an actual concatenation.

Also C/C++/C# allows for "fall through" switch/case statements. which are valuable. Conditional statements are also more concise, since C/C++/C# all interpret the value 0 for byte, int, long , etc as a false bool. This, along with the ?: operator in C# allows for this:

int i = 0;
string str = (!i) ? "Is Zero" : "Is Not Zero";

which would look like this in VB:

Dim i as Integer
Dim str as String
i = 0
If(i == 0)
str = "Is Zero"
Else
str = "Is Not Zero"
End

As you can see, the C# code is much more concise than the VB code.

Also, you may love doing VB for now, when it's all for play, glitz, and glam. However, if you pursue CS or EE as a profession later on, you will quickly learn that VB is "programming for business majors." (i.e. there is no rigor to it) Real (professional) programmers and engineers pay a great deal of attention to data structure, argument passing, type casting, etc...all of which VB is very loose with.

DonRotolo
11-13-2007, 04:39 PM
i have to admit running programs is a bit slow but, meh! Heh, it's just a problem of insufficient hardware :D

"It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration."
BASIC is not Visual Basic; VB has more in common with C++ than with BASIC.

That being said, if you can teach yourself (or get taught) regular old C, you'll have a foundation that will pay you well for the rest of your life.

Not a bad return for a High School student...

Don

EHaskins
11-13-2007, 09:45 PM
I suggest that you familiarize yourself with the .net framework namespaces. It took me a while to get used to using the .net namespaces instead of the vb6 ones. Also, try playing around with the serial port class and your RC. I made a vb.net program that takes sensor data printf'd to the serial port graph on my laptop.

-Don

I totally agree. The .net framework is huge, and the best way to learn it is to write code.

Also C/C++/C# allows for "fall through" switch/case statements. which are valuable.

...

As you can see, the C# code is much more concise than the VB code.

Also, you may love doing VB for now, when it's all for play, glitz, and glam. However, if you pursue CS or EE as a profession later on, you will quickly learn that VB is "programming for business majors." (i.e. there is no rigor to it) Real (professional) programmers and engineers pay a great deal of attention to data structure, argument passing, type casting, etc...all of which VB is very loose with.

By switch/case statments do you mean something like this?

'VB.net code'

Dim i As Integer = 10
Select Case i
Case 1
DoSomething()
Case 10
DoSomethingElse()
End Select

Also, add this to the top of your .vb file, to get the "strictness" of C#.

Option Explicit On
Option Strict On


well, i agree with u guys somewhat but ive been programming visual basic for a year and love it! i have to admit running programs is a bit slow but, meh!

If you're running VB.net code the performance will be identical to C#, since they're both copiled to the same IL(Intermediate Language), using the same .net framework, running on the same CLR(Common language runtime).

---------

I know some people will say I'm insane, or stupid, but I'll say this anyways.

I am equally capible of proramming in C# and VB.net. I also have some experiance with C++ on windows, and C on the RC, but .net is what I really have experiance with.

Now, this is what some people won't believe. I am more effecient in VB! The background compilation, LINQ to XML(in vs2008 Beta 2), case-insensitivity (http://www.codinghorror.com/blog/archives/000458.html), ect., make me much more productive than C#.

EDIT: As languages I have no preference between VB and C#, but the IDE features of VB.net are far superior of C#. Just my opinion.

Tips for people interested in .net.
Read these blogs:
Coding Horror (http://www.codinghorror.com)
Coding4Fun (http://blogs.msdn.com/coding4fun)

Listen to these podcasts:
.Net Rocks! (http://www.dotnetrocks.com)
HanselMinutes (http://www.hanselminutes.com)

Use these sites:
CodeProject (http://www.codeproject.com)

jee7s
11-13-2007, 09:58 PM
Yes, that's a switch-case statement. However, a fall-through switch case statement is a little different:

int i,x,y,z;

switch(i)
{
case(1): x = 4;
case(2): y = 4;
case(3): z = 4;
break;
default: x = y = z = 0;
break;
}

This code sets:
x,y,z to 4 if i = 1
y, z to 4 if i = 2
z to 4 if i = 3
x, y, z to 0 else

It's called "fall through" because there are no break statements in the early set of cases. This means that the case i == 1 falls through to i == 2 which in turn falls through to i == 3. There are many situations where this is useful, especially if the cases for i are not mutually exclusive.

From my understanding of VB, the above block would have to be coded this way:

Select(i)
case(1):
x = 4
y = 4
z = 4
case(2):
y = 4
z = 4
case(3):
z = 4
default:
x = 0
y = 0
z = 0
End Select

I might be wrong about that VB switch statement, but I'm pretty sure it doesn't support the fall-through idea.

de KG2OV

EHaskins
11-13-2007, 10:07 PM
Yes, that's a switch-case statement. However, a fall-through switch case statement is a little different:

I might be wrong about that VB switch statement, but I'm pretty sure it doesn't support the fall-through idea.

de KG2OV

Thanks for the clarification. I should have know that, but I don't remember ever seeing that in practice.

However, after reading your post i decided to try that in C#, and as far as I can tell C# dosn't support that either.

This code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int i = 10;
switch (i) {
case (1):
Debug.Print("1");
case (2):
Debug.Print("2");
}
}
}
}


generates these errors:
Error 1 Control cannot fall through from one case label ('case 1:') to another C:\Users\Eric Haskins\Documents\Visual Studio 2008\Projects\ConsoleApplication1\ConsoleApplicati on1\Program.cs 15 17 ConsoleApplication1
Error 2 Control cannot fall through from one case label ('case 2:') to another C:\Users\Eric Haskins\Documents\Visual Studio 2008\Projects\ConsoleApplication1\ConsoleApplicati on1\Program.cs 17 17 ConsoleApplication1

Am I being stupid again, or is this a limitation of all .net languages?

EDIT: I found my own answer. http://msdn2.microsoft.com/en-us/library/843c4c28(VS.90).aspx That seems slightly old VBish.
EDIT: More info http://blogs.msdn.com/abhinaba/archive/2005/11/15/492866.aspx
-Eric

jee7s
11-13-2007, 10:43 PM
I really meant my fall through explanation to be focused on C/C++. Frankly, I have never used it in a C# application, but I assumed the C-style syntax would support it...I was apparently wrong.

So, let's apply my previous post to C/C++ only.

Also, the link you posted is a good work around for a fall through. However, as a practice, GOTO statements violate OOP principals, and I try to avoid them at all costs.

P.S....I've been itching for a correlary to __asm (from C++) in C#. Perrhaps __cpp, or __C++, or __cplusplus to allow for inline C++ code in C#. I suppose I'll never see it.