English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I'm very new VB.net and I don't know how to do ANYTHING. All my previous experience is with QBasic. So, could somebody give me an example of how to say, on clicking a button, "Hello World" pops up. And also explain each piece. Google isn't helping me, as I do a copy-paste and I get some handling error or another. I think I'm missing something small but critical. (And what does ByVal mean!?)

2007-08-28 13:46:52 · 3 answers · asked by Mitchell 5 in Computers & Internet Programming & Design

I'm using Visual Studio 2005

2007-08-28 14:12:24 · update #1

3 answers

I'm assuming that you are using Microsoft Visual Studeo of some version.


What I would do is to add a Button from the toolbox over at the left-hand side of the screen. It may be auto-hidden, if so just hover over the tab that says "Toolbox". Just drag and drop the button to your form. Click on the button you just added.

Now look over to the right of the screen for the "Properties" box. Look for the property labeled "(name)". Double click it and replace the default name with something more meaningful (ie hiButton).

Now look for "Text" in the properties box. The Text property is the text on the button. Replace the default value (which is usually "Button1") with something like "Click me" or anything really.

Next, double-click on the button on your form. This opens up the code editor for the project and also adds an event handler for the click event of the button. You should see something like:

Private Sub hiButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles hiButton.Click

End Sub


Make sure your cursor is in between the two parts. Here's where you add the code to make the button do something. The simplest way in this case would be to pop up a message box like windows uses for errors and whatnot. Type this in:

messagebox.show("Hello World")


You should now have something like:

Private Sub hiButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles hiButton.Click

messagebox.show("Hello World")

End Sub


Now it's time to test. Click on the little right facing triangle in the toolbar at the top, or go to the Debug menu and click "Start Debugging". Your project should load and you can test out your button.


ByVal is something that tells the editor that it's an incoming variable for a sub or function. It's really not important in this case. It only really is used when creating your own subs or functions, and even then you don't have to actually type it if you don't want to. The editor adds it for you if you leave it off.


I might suggest buying a VB book to help you in learning it. The internet is great, but nothing beats a good reference book when you are teaching yourself. You could also take classes at your local college or whatever. It's always nice to have a teacher who can help you figure out what you're doing wrong.

2007-08-28 14:16:55 · answer #1 · answered by babyzcostumeshop 3 · 0 0

The biggest fundamental difference you will notice from QBASIC is that VB is an event driven windows based language vs a DOS based procedurial language.


In a proceedurial language you used line number to sequence through your code. This sequence would repeat over and over as long as the program is running event if your code had nothing to do. In a proceedurial language the code would have to frequently poll a button to see if a user pressed it. If the user doesn't press it the code is still checking the button.

VB is event driven, simple put your code is broken down in to small sections (Subroutines and/or Functions) which only run when an event (Like a button press) triggers (fires) the event.

Using an event driven language frees up the computer to do other things without having to frequently watch for a button press. Only when the event happens (user presses a button) does the code in that event handler.

The Visual Part of VB is the ease of creating a window and all of its functionality. In QBASIC you would have to write all of the code to create a window including its functions (Minimize, Maximize, Open Close, resize etc...)

Microsoft has encapsulated all of that code in its Visual Programming languages into a drag and drop interface. You can make a simple "Hello World" program by writting as little as a single line of code!


Upon opening a new windows program in VB2005 you already have code written for you behind the scenes to create a windows form. But before you run this program you would want to add a BUTTON control to the form so the user will have somethine to click on.

From the ToolBox double click the button icon. You will see a button appear on the form . Double click this new button and you will be taken to the code page where the code will be written. The event handler is written for you and all you need to do is add the following

me.text = "Hello World"



that is it you can now run this program and you will see a fully functional window with a single button appear. Clicl on the button and Hello World will appear in the title bar

2007-08-28 23:06:15 · answer #2 · answered by MarkG 7 · 0 0

hi
u can add a command button on a form
then
u double click on it to write the code in the coressponding event (click by default)
then u write this
msgbox "Hallo word"
then u run the program (debug->start)
bye fr now

2007-08-28 20:58:39 · answer #3 · answered by has_infoooo 3 · 0 0

fedest.com, questions and answers