• Advertisement
Sign in to follow this  

Text in VB

This topic is 3894 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've just started using VB and I was wondering how to print text in. Back in old BASIC you just have to type something like this... Print "Hello World" How do you do that in VB?

Share this post


Link to post
Share on other sites
Advertisement
Well, Visual Basic is different from BASIC. A blank project has a form, you can add a label to your form. Name it 'Label1'. Then in your code, you type:

Private Sub Form_Load()
Label1.caption = "Hello World"
End Sub

Press run, and when it loads, the label should say Hello World.

Ben

(Haven't used VB in the last couple of years, going to install V Studio 05 tomorrow, got this info of a tutorial. I'll check the code once I've installed it, and if you need any more help, I can give it then.)

Share this post


Link to post
Share on other sites
Aye, it's not about console output any more. Basically if you have something you want to output, you can indeed output it to a label on a window (as above), or into a textbox, etc...

I had the same problem when I made that conversion from QBasic to VB. It's a very different world in Windows, but start with that code posted above and let us know if you have any questions.

If it helps, another thing to remember is that VB is event-driven. It's not so much about running a program from beginning to end as in QBasic, but rather it's about responding to what the user does to the components you drop into forms.

Text Boxes, Buttons, etc... (everything you can drag and drop onto one of those visual forms) has several "events" that when the user does the related action, you can have code run in immediate response.

For example, a button has a "Click" event. (Try double-clicking on a button that you drag into a VB form to create the Subroutine that will "respond" to the "Click" event) Whatever code you write within that click response subroutine will be run when that button is clicked.

Hopefully this helps. It's a big paradigm change from QBasic (and console-based programming in general), but with time you'll get used to it. Let us know if you run into any more questions!

Share this post


Link to post
Share on other sites
Wow, much better explained than me:P I'm surprised my code was correct, haven't touched VB in years lol. PM me if you need any help...now, off to install V Studio

Share this post


Link to post
Share on other sites
Alternatively, create a new console program and use Console.WriteLine("Hello, World") [smile]

(Either set a breakpoint on the program's final Exit Sub or run without debugging - Ctrl+F5 - to keep the window on-screen from Visual Studio).

Share this post


Link to post
Share on other sites
Aye latest versions of VB has kinda of come full circle in that you can actually write old style console/command line programs again if you want but the syntax is completely different so it's not really VB anymore?

Share this post


Link to post
Share on other sites
There is no real reason to use VB6. VB7 and above are a significant step forwards.

Share this post


Link to post
Share on other sites
Thanks for the help on this subject it's been quit a large jump from BASIC to VB. Your answers did help a lot.

Share this post


Link to post
Share on other sites
I suggest that you skip VB and VB.NET and learn C++, java, C#

Share this post


Link to post
Share on other sites
Quote:
Original post by V-man
I suggest that you skip VB and VB.NET and learn C++, java, C#


Would you suggest That i learn C++ or C#?

Share this post


Link to post
Share on other sites
I dunno about V-man, but I suggest c#. There is even a Workshop that will start in under a week for C#. Check out the forum, it is located here.

Share this post


Link to post
Share on other sites
I don't know if I agree with the poster above.

If you're planning on learning VB.NET, I could see the argument for just switching over to C#... BUT...

The nice thing about VB is that it teaches core language skills in a way that's less overwhelming than C-based languages. Its syntax is more english-like, and certainly more readable for a non-programmer or a newbie programmer. It also teaches some of the most core concepts without having to dive in to *all* of the major programming concepts.

I think it'd be worth it to switch over to one of the C-based languages above if you feel that you learned everything there was to learn when you were working with QBasic, and if you feel that you want to do more than just code as a hobby.

If you don't feel that both of the above statements are true, however, I say VB 6 or .NET is a good intermediary step.

Hell, it can be a final step if you want. I'm making damn good money right now programming in VB 6 (maintaining a legacy system while trying to develop a similar app in VB.NET), and for desktop applications it works just fine. I was trained in C but haven't worked with it professionally in years as a result. And the nice part about working in a VB language is that the interns we bring in pick it up quick (even non-programmers) so you don't have to spend as much time/effort training them.

But I digress. Anyways, investigate what you feel would be the best next step for you and go for it full force! The worst that can happen is that you decide halfway through that you'd rather learn the other language... and then you can just pick up and do that one too. =)

Share this post


Link to post
Share on other sites
Quote:
Original post by EdgarVerona

If you don't feel that both of the above statements are true, however, I say VB 6 or .NET is a good intermediary step.


I strongly disagree with starting with VB 6. It's horribly outdated. If you do decide to go with VB, you should go with the newest version.

If on the otherhand you decide to go with a C based language, I would go with C++ (unless your interested in doing the workshop, which would help you learn it greatly). I only recommend C++ over C# because they're very similar in syntax, and C++ is the game development industry standard.

Some people say that learning VB as your first language, and getting experienced at it, opens doors for bad coding techniques in the future when/if you would learn a non-VB language.

This is just my 2 cents.
Hope it helps.

Share this post


Link to post
Share on other sites
I think that VB6 has been given a bad name unfairly. It neither encourages or discourages bad programming - I can program badly in lots of languages! :)

It is a relatively easy language to learn, so making the step from QBasic is easier than, say, going to C++.

However, if you want to program games (I guess that's why you're here) then you might want to consider something like DarkBasic or XNA, which are designed for writing games. The tools for XNA are free, I'm not sure about DarkBasic, I've not used it.

VB6 is easy (ish) to get started with, but quite difficult to use for games. You will probably end up using lots of Windows APIs to do things that VB6 doesn't support directly. VB6 was really designed for applications with data entry forms and databases (yawn!) not for high speed animation or even decent sound. If you want to program DirectX, you are restricted to version 8 as that was the last version supported by VB6. You still have to do a *lot* of coding to get it to work, compared to XNA for example.

By the way, you can also do something like this in VB6 to print text (from memory, may contain errors!):

with Form1
.CurrentX = 50
.CurrentY = 50
.FontName = "Arial"
.FontSize = 14

Form1.Print "Hello World!"
end with

This way you don't need a label. The way I would normally do it, for speed and versatility, is to use the DrawText API. This is a fairly complex way to do something amazingly simple, and one indication why VB6 may not the right way to make games.

Share this post


Link to post
Share on other sites
Indeed, VB 6 is outdated, but from a conceptual learning standpoint it's not terribly outdated. If you need to figure out how to use subroutines, how event-driven programming works, etc... VB 6 can work. But I do agree with you that VB.NET would be the more preferable of the two.

I also think that C++ would be more useful than C# from a global perspective because in doing so you'll get to learn about things like pointers... actually, that's a good question. I haven't worked in C# yet, since it's managed do they still allow you to create pointers? I honestly don't know... but I do know that you get extensive experience with them working in C++, so of the two I'd go for the former until more info comes over to me. =)

Lastly, I'd say that learning VB (well, at least VB.NET) as your first language has no bearing on your coding techniques in my opinion. I can understand your concern with VB 6 (as I myself have been frustrated by its lack of support for true object-oriented programming, or anything even approaching it) But now with VB.NET, you can utilize any object-oriented design patterns you'd like. All of the features you could ask for in an OO language exist in VB.NET, so you can go nuts... which of course presents the real problem with learning "good coding techniques" in any language. The extent to which your coding techniques thrive or fail is almost entirely dependent on you (and the effort you put forth in implementing good techniques), and are - almost - not language dependant.

That isn't to say that it's just as easy to practice good coding techniques with x86 Assembly, Java, and VB.NET. But the latter two are both near-fully implemented object-oriented languages, and thus'll serve you as well as at least C# will for the purpose.

With some effort, good coding practices can be used even VB 6. It does require a person to be a bit more creative as VB 6 lacks support for implementation inheritence, polymorphism, etc... but it *does* allow interface inheritence, and you can do some unexpectedly organized things with VB 6 with thoughtful use of interfaces.

But I'm digressing quite a bit, sorry about that. =) Indeed, VB.NET would be preferable to VB 6, to clarify my opinion on the two. That's why I'm trying to move my company's code to VB.NET as we speak. (I guess it could be worse, it could've been a mainframe application written in FORTRAN ;) )

But anyways, this is all probably beyond what Froley needs to know right now as someone just starting up and who's probably more interested in learning how functions and windowed programming works than how to implement object oriented design patterns. Sometimes you have to walk before you run.

The quick summation for you is: C#, C++, C, VB and VB.NET can all be good "next steps" for you, depending on what you want and how much of a learning (or re-learning) curve you think you can handle. If you don't want to tread in unfamiliar water too quickly, go for a bit of VB.NET. If you're willing to have a higher learning curve in exchange for learning a more standardly used language in the game field, go with C++. All the other options are (varyingly difficult and varyingly useful) intermediary options.

Share this post


Link to post
Share on other sites
Quote:
Original post by cemedias
I only recommend C++ over C# because they're very similar in syntax, and C++ is the game development industry standard.
Just because they use it (and they have their own reasons to do so) is no reason to use it yourself (unless you're desperately trying to get a job). C++ and C# both look similar, but C# is significantly cleaner and easier to work with than C++ (not just as far as the language goes, but also as far as things like C++'s archaic compilation model goes, for example).

Knowing how to use pointers is not exactly relevant to the majority of C# programs, but you can drop to unsafe code if you so wish to use them.

Share this post


Link to post
Share on other sites
Quote:
Original post by benryves
Quote:
Original post by cemedias
I only recommend C++ over C# because they're very similar in syntax, and C++ is the game development industry standard.
Just because they use it (and they have their own reasons to do so) is no reason to use it yourself (unless you're desperately trying to get a job). C++ and C# both look similar, but C# is significantly cleaner and easier to work with than C++ (not just as far as the language goes, but also as far as things like C++'s archaic compilation model goes, for example).

Knowing how to use pointers is not exactly relevant to the majority of C# programs, but you can drop to unsafe code if you so wish to use them.

And another thing you might want to take into consideration is that if choose to code to VB.NET instead of C# you can easily port 99% of your code over to C# in a jiffy since the 2 languages are so similar! The same cannot be said if you choose to code in C++.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement