View Full Version : Microsoft Visual Basic - Questions


ToryCynic
23-09-2004, 19:18
Hiya,


As I *know* that a few people are Programmers on here - Martin_S, JoeP to name two they may well know about this software - well anyone might...
... anyways, to the point:
In College, one of the units is "Introduction to Software Development" and next week we will start using MS VB, what's it like, what does it do?

Originally posted by Sidla from the "Mouse over Topic" thread


This is the key code which makes it tick:
<tr>
<td class="alt1"><img src="images/statusicon/thread_new.gif" alt="" border="" /></td>

<td >


<div>
<span style="float:right">



</span>
<a href="showthread.php?goto=newpost&amp;t=59706"><img class="inlineimg" src="images/buttons/firstnew.gif" alt="Go to first new post" border="0" /></a>


<a href="showthread.php?t=59706"><strong>Request.</strong></a>

</div>

<div class="smallfont">


<span style="cursor:pointer" onclick="window.open('member.php?u=22072')">Knobby</span>


</div>



</td>


Is it using tags and stuff like that, that looks *technincal* like above.

Also, how much is it to buy? It doesen't come as part of MS Office does it? As I have MS Office 2k, (which didn't have VB with it).

Cheers
Alex

Internetowl
23-09-2004, 20:13
It comes as part of visual studio - well it did.

Costs....probably a packet knowing Uncle Bill and his cronies

sanman
23-09-2004, 20:15
Alex

You do get VB for applications as part of office. Don't know how much it costs. As for what it's like, I found it verry powerful but also very long winded.

Cheers

Mark

ToryCynic
23-09-2004, 20:29
Originally posted by Internetowl
It comes as part of visual studio - well it did.

Costs....probably a packet knowing Uncle Bill and his cronies

Probally, lol! :D

Originally posted by sanman
Alex

You do get VB for applications as part of office. Don't know how much it costs. As for what it's like, I found it verry powerful but also very long winded.

Cheers

Mark

Ah, my version of MS Office 2000.
Long-winded, oh yay! :mad:

Cheers
Alex

Edd
23-09-2004, 20:51
Microsoft Office includes VBA ("Visual Basic for Applications") which is what you use to write Macros and stuff in word or excel.

Visual Basic itself is part of Visual Studio. Its a great programming language for beginners, and its a great language to use for rapid prototyping of fairly simple software. I use it all the time, and i still enjoy it, and still find new ways to do stuff.

good luck! and let us know how you get on with it!


edd

alchresearch
23-09-2004, 21:52
The trouble with VB (I did it last year at uni) is that you have to be a graphic designer rather than a programmer.

ToryCynic
23-09-2004, 22:12
OK, Cheers :)

Alex

John
23-09-2004, 22:13
The code you posted is HTML and is nothing like Visual Basic.

I am a little confuse to how alchreserch came to the conclusion that you need to be a graphic designer to use VB. If you are thinking that you need to draw components on the form then that alone is useless without the programming behind it.

Open up word and try pressing F11

Failing that, In word, select Tools > Macro > Visual basic editor

By now you should have the Visual Basic window is open, select Insert > User Form

and then have a play - don't be fooled that you need to be a graphic designer as soon as you see those drawing tools.

F5 compiles and runs your work - F1 brings up the help from here.

This is a limited version of Visual Basic known as VBA but it should give you an idea of what it is like.

ToryCynic
23-09-2004, 22:14
It's only one of the many (18 ) units on the course. The ND is more geared towards h/w.

Alex

alchresearch
24-09-2004, 19:38
Originally posted by John
I am a little confuse to how alchreserch came to the conclusion that you need to be a graphic designer to use VB. If you are thinking that you need to draw components on the form then that alone is useless without the programming behind it.


In my degree module quite a lot of people struggled with the design of all the buttons, labels and captions. It seemed to be more about getting these set up and then double clicking on said function and typing in a bit of code.

Proper programming really existed in the 80's with BASIC on the eight bit machines, or Pascal. You just used a PRINT or WriteLn statement to output to the screen, you didn't have to waste time designing text boxes and the like.

ToryCynic
24-09-2004, 20:04
Originally posted by John
The code you posted is HTML and is nothing like Visual Basic.

I am a little confuse to how alchreserch came to the conclusion that you need to be a graphic designer to use VB. If you are thinking that you need to draw components on the form then that alone is useless without the programming behind it.

Open up word and try pressing F11

Failing that, In word, select Tools > Macro > Visual basic editor

By now you should have the Visual Basic window is open, select Insert > User Form

and then have a play - don't be fooled that you need to be a graphic designer as soon as you see those drawing tools.

F5 compiles and runs your work - F1 brings up the help from here.

This is a limited version of Visual Basic known as VBA but it should give you an idea of what it is like.


Thanks for the info on how to get to VBA via Word, I'll have a look later.

Alex

ToryCynic
28-09-2004, 23:01
Hiya,

Well, we started using the software in the morning session - and we were taught some of the simple code.
However on Thursday's afternoon session we will start creating a Welcome Message, where students have to type in their name and click Login. Then click Exit to Logout.

Seems interesting.
I think I'll still prefer the h/w and network units. Especially as we are also enrolled to do the Cisco CCNA certificate too. Which is hard , but will be worthwhile.

Alex

JoeP
29-09-2004, 06:39
Hiya,

Proper programming was what we did in the 1970s with machine code...PRINT? WRITELN? For wimps who couldn't handle stuff like 09 BA 10 BB.....;)

Developing with VB is fairly straight forward to get started with - I write a lot of middleware and never actually see a form, but provided you follow the Windows interface guidelines you can produce a functional program with a half decent user interface very easily.

VBA is the language designed by Microsoft for automating applications. As well as being in the MS Office suite, it's supported by a number of other products. It supports most of the VB syntax and stuff but doesn't support the production of stand alone code like DLLs or EXEs. A piece of Visual Basic for Applications code has to reside within another container document - a word file, Excel spreadsheet, etc.

VB allows you to produce stand alone applications and components called ActiveX DLLs, which can be used by other languages. It used to come with Visual Studio but your best hope to get it now is from eBay as Microsoft no longer ship it new - been replaced in the development languages they produce by VB.NET / C#. The main thing to get your head around is the almost object orientation that VB uses. It supports classes, and to make full use of all the facilities of VB6 you need to be aware of them and how they work. However, it's not got the full 'book definition' implrmrntations of polymorphism and inheritance.

It's widely used in the real world as a means of getting user facing applications developed quickly and cheaply. It's not as fast as C++, but it's excellent at what it does.

Joe

adlinds
29-09-2004, 10:27
If your course is at Hallam you can borrow the visual basic software for free to load on your computer, ask your programming tutor about it.

If your still struggling PM me and i'll see what I can do.

I also got all the projects they give you finished with code, not to copy but its useful to see it because it helps you to work it out in your head better.

www.planet-source-code.com (http://www.planet-source-code.com) is also useful and worth a look.

Good luck,
Adam

alchresearch
29-09-2004, 12:18
Originally posted by JoePritchard
Proper programming was what we did in the 1970s with machine code...PRINT? WRITELN? For wimps who couldn't handle stuff like 09 BA 10 BB.....;)

Too right Joe! I had to program an engineering machine with nothing more than a vacumn display and a hex keypad! I did so much Z80 programming years ago that I can still look at ASCII characters and tell you the hex codes!

ToryCynic
29-09-2004, 22:58
Originally posted by adlinds
If your course is at Hallam you can borrow the visual basic software for free to load on your computer, ask your programming tutor about it.

If your still struggling PM me and i'll see what I can do.

I also got all the projects they give you finished with code, not to copy but its useful to see it because it helps you to work it out in your head better.

www.planet-source-code.com (http://www.planet-source-code.com) is also useful and worth a look.

Good luck,
Adam

Thanks very much for your assistance there Adam, I'll certainly bear your "I can PM you in mind".

No, I'm doing it at Lewisham College - jsouth London. Where they don't give you anything for nothing - they're very much - ooh you need a lisence etc.

Cheers
Alex

ToryCynic
07-11-2004, 12:07
Hiya,

Just having a bit of trouble with "variables"
The guy running the lectures went through it - I wote it down, however I din't write down enough info for me to understang it..

He gave an example of a block of flats - e.g "Psalter Flats" within the block of flats you have memory and within one flat you (i.e Craig lives at number 4) he moves - then the contents of house VARIES - so that is why it is a variable, yet #4 Psalter Flat continues to be the same flat but the contents vary...

The lecturer went on to say that Variables are named memory locations...

"That means you will have to tell the program you wish to use that memory location"



DIM (Keyword)
Variable (Name chosen by programmer)
Name
As (Keyword)
Type (This is the data type)
Name

Can anyone reiterate the above, please?

DIM intotal as Integer -

Option Explicit
DIM as integer
DIM curTotalCost - we are currently doing a program for a restaraunt owner who wishes to click on the options and it work out the cost - hence curTotalCost.

Thanks
Alex :)

xafier
07-11-2004, 13:03
Originally posted by amhudson119

DIM (Keyword)
Variable (Name chosen by programmer)
Name
As (Keyword)
Type (This is the data type)
Name

DIM - used to tell the compiler to allocate space for the following variable.

the rest you said is correct, anyways no offence but VB sucks monkey balls ;) I had to do it last year for my Uni course... its very much like programming for kids, or at least in my oppinion...

I had to make a noughts and crosses game in VB for my assignment, it was rather amusing... lol... personally I think a bit of C++ or Pascal/Delphi is much more interesting :)

just be thankful that you probably wont have to do anything like pointers and references and how arrays work with doing a VB module ;)

JoeP
07-11-2004, 13:09
For all other VB programmers out there, this is a VERY simplified 'get you started' view! :)

Just think of a variable as a box with a label on it.

So :

Dim i as integer

will create a box called 'i' which has the ability to store numbers of type 'Integer'. Similarly,

Dim s as string

will create a box called 's' that can hold strings.

If the language is typed, like VB, trying to shove a string in to an integer shaped box will not work, and you get an error called a 'Type Mismatch'. So :

Let i="Hello World"

after dimming I as an integer will generate a Type Mismatch.

VB also supports more complex types of variables - like Date which hold data that ust represent a Date, or 'Object', which allows you to handle data that can represent all sorts of things from a database record to a Word Document.

VB also supports something called 'Variant', which is a type of variable that can hold any type of information.

So, Dim i as Variant, followed by i="Hello World" would be fine.

The 'Option Explicit' referred to is basically a compiler directive for VB telling VB to insist on all variables being declared with Dim or another declaration statement before use. Very good practice - makes you think about what you're doing.

Hope this helps!

Joe

JoeP
07-11-2004, 13:15
Originally posted by xafier
DIM - used to tell the compiler to allocate space for the following variable.

the rest you said is correct, anyways no offence but VB sucks monkey balls ;) I had to do it last year for my Uni course... its very much like programming for kids, or at least in my oppinion...

I had to make a noughts and crosses game in VB for my assignment, it was rather amusing... lol... personally I think a bit of C++ or Pascal/Delphi is much more interesting :)

just be thankful that you probably wont have to do anything like pointers and references and how arrays work with doing a VB module ;)

Funny how VB is still used by many businesses for developing their corporate systems, while Delphi is used by very few....;)

VB does wrap things up so you don't have to worry about how the data structures work internally - which is a good thing if you're interested in producing business solutions rather than academic computer science work.

ByRef is required in VB, btw, for passing object variables and such.

Different languages have differnt uses - whilst I might use C++ to write a DLL that does a lot of string processing, I might prefer to use VB to put together an application that's needed quickly and is likely to require frequent modification.

For most business applications, developing in VB is also faster than doing stuff in C++, as you do have a lot of the internal compexities deat with - it's horses for courses, really.

Joe

bigrods
07-11-2004, 13:39
Originally posted by amhudson119

Option Explicit
DIM as integer
DIM curTotalCost - we are currently doing a program for a restaraunt owner who wishes to click on the options and it work out the cost - hence curTotalCost.

Thanks
Alex :) [/B]

I don't know if you need help with this, but hopefully this might be able to point you in the right direction:

Let's say for example you have 2 text boxes that you can input a price into, a button to calculate a price, and a text box to show that total price.

Option Explicit - (to signify all variables must be declared)

dim curprice1 as currency - (variable to hold the value of the first price. It is declared as a currency variable as it is currency it shall be storing)

dim curprice2 as currency - (same as above, just holds the second price)

dim curTotalCost as currency - (the total cost of the prices added together)

Sub Button1_Click() - (the action that happens when the button is clicked)

curprice1 = txtprice1.text - (the value of whatever is in the first text box is stored in the first price variable)

curprice2 = txtprice2.text - (ditto, but with the second price)

curTotalCost = curprice1 + curprice2 - (the curTotalCost is updated to the value of the curprice1 and curprice2 variables added together)

txttotalcost.text = curTotalCost -(the value of the txttotalcost text box is updated with whatever is stored in the curtotalcost variable)
End Sub

Hope that helps in any way!

bigrods
07-11-2004, 13:45
Originally posted by alchresearch
The trouble with VB (I did it last year at uni) is that you have to be a graphic designer rather than a programmer.

In software development, the graphical user interface (GUI) is very important, as your users need to be able to use the system.
The strong point of VB is that it allows programmers to create Windows-like applications (with menu bars, buttons etc).

I don't think that you need to be a graphic designer to create effective programs - jsut have a basic awareness of creating user-friendly screens (ie easy to navigate, not too much clutter).

xafier
07-11-2004, 15:06
Originally posted by JoePritchard
Funny how VB is still used by many businesses for developing their corporate systems, while Delphi is used by very few....;)

maybe because they dont teach pascal/delphi in Universities they just cram VB down peoples necks? ;) anyways, I dont deny VB has it uses, its very handy for whipping up prototype programs that look pretty and do half the stuff you want the final thing to do...

but when you want a program thats going to deal with lots of databases and other systems and you want it to work effectively and fast you do it in a more suitable language...

plus, VB isn't very portable, you cant take a VB program from windows and quickly make it work on a FreeBSD system :P anyways, I prefer C++ and Java and Delphi... its what I have most experiance in and I enjoy it more than lots of clicking and dropping in VB

JoeP
07-11-2004, 16:02
Originally posted by xafier
maybe because they dont teach pascal/delphi in Universities they just cram VB down peoples necks? ;) anyways, I dont deny VB has it uses, its very handy for whipping up prototype programs that look pretty and do half the stuff you want the final thing to do...

but when you want a program thats going to deal with lots of databases and other systems and you want it to work effectively and fast you do it in a more suitable language...

plus, VB isn't very portable, you cant take a VB program from windows and quickly make it work on a FreeBSD system :P anyways, I prefer C++ and Java and Delphi... its what I have most experiance in and I enjoy it more than lots of clicking and dropping in VB

As an aside, until quite recently most people doing academic courses in IT were taught using Pascal / Delphi / C++ - then it was Java, and only recently has VB started making a showing in teaching.

In the 'real' commercial world - and I'm talking people like HSBC, HBOS, GE Capital, etc. VB is widely used to provide business systems in teh Windows environment. VB is perfectly adequate for developing multi-tier client server database systems, and is frequently used to provide database and mainframe middleware solutions.

Yes, if you need speed then you might write the parts of the system in a language that provides it. However, rapid development and ease of maintenance of packages are usually more important and you tend to get that more from VB.

It doesn't matter that VB isn't portable if your whole organisation is based on Win32 machines.

And as for drag and drop - in several recent contracts I've been writing ActiveX DLLs and middleware where not a single bit of clicking and dropping has taken place. Just because VB supports ease of interface development doesn't mean that all VB programs require you to use it.

Joe

ToryCynic
07-11-2004, 21:02
Thanks for the help there, guys :)

Alex

ToryCynic
20-09-2005, 21:21
Bringing this back from the dead - currently in year two of the course, and after completing last year's "Restaturant Project" - where you had to create a menu with option buttons and in the finish it calculated the total price of the total items purchased, I passed it.

This year, I've learnt that the whole programming side of it will be split between Visual Basic and HTML - after only doing a few days of HTML (we didn't do any last year), I've found I prefer it to VB.

This week's mini project - creating a calculator.

I successfully managed to create a calculator that had a text box - txtVal1 and txtVal2 - simply txtVal1 & txtVal2 added together and the answer appeared in lblAnswer.

This week, we need to expand upon it, and include minus, multiply and divide - last week we did not need to use the mouse - we only used Tab to move across the text boxes. Same with this - Tab from txtVal1 to cmdAdd / cmdSubtract / cmdMultiply and cmdDivde then to txtVal2, which after hitting enter, will display the answer in lblAnswer - the problem is that replicating the addition code is not working - I think it's because the if / End statement isn't working properly... ...I would display what I've done, but left the VB work on the college's drive!

Cheers,
:)

adlinds
20-09-2005, 21:31
The code for a simple calculator can be found here http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=51201&lngWId=1

Its good to look at it to help you gain understanding. I have not done VB for over a year so am a bit rusty I'm afraid.

ToryCynic
20-09-2005, 22:12
Originally posted by adlinds
The code for a simple calculator can be found here http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=51201&lngWId=1

Its good to look at it to help you gain understanding. I have not done VB for over a year so am a bit rusty I'm afraid.

Cheers - will investigate!

:)

ToryCynic
15-10-2005, 00:37
It's that time again - VB trouble time.

I've created the basic program as requested, but am having trouble with those niggly points.

The idea of this is for a user to type in a food item and its code - i.e. apple 101 see this (http://i19.photobucket.com/albums/b157/kentboy/vbproblem1.jpg). Once they've done this, they need to be able to search their list - i.e type in 'a' for apple. (Which is 'playing up' - ;) ).

After, they need to be able to search 'ap' for apple, however, if they type in 'ao' it should go to the word above, and if they type in 'aq', for example, it should go to a word after 'ap' (i.e bread)...

Lastly, the search button doesn't seem to be clearing txtFood, nor txtNumber...

Thanks,

Alex - :)

fnkysknky
15-10-2005, 15:09
Can't you just use a combo box for the list of food items - you don't need to worry about writing the code to search then.

As for the text boxes not clearing just put some code in the search button click event handler to clear them or set their text properties to ""

ToryCynic
15-10-2005, 15:18
Originally posted by fnkysknky
Can't you just use a combo box for the list of food items - you don't need to worry about writing the code to search then.

As for the text boxes not clearing just put some code in the search button click event handler to clear them or set their text properties to ""

Hey,

I could use a combo box, but unfortunately we have to follow the syllabus, which states that for this 'project', we have to use a lstBox....

I never thought of "" - so simple.

Cheers!

:)