Nooby Visual Basic question.

Soldato
Joined
23 Dec 2010
Posts
3,483
Hello guys,
This year in college we are programming in Visual Basic, I didn't expect it to be as weird as Pascal but I was quickly proven wrong. However in a attempt to out-do my classmates (I had to, my final bit of Pascal programming last year was awful) I have decided to download Visual Basic 2010 from the Microsoft Developers Website.

So anyways, I have an idea for a program. It's basically going to use the radio-button feature and the user is going to click on a radio button and next to it a picture is going to appear. In this case its going to be a selection of Premier Leauge football clubs and when you select Arsenal a picture of Robin van Persie is going to come up. And so on and so forth with all the other Premier League Clubs (Aston Villa - Dunne, Blackburn Rovers - Pedersen ect..)

So I want to know how I can achieve this.

Thanks.
 
How far have you got?

Often the members of this forum frown upon those who ask others to do their course/home/other work for them, so please have a go at it yourself, then ask for help with problems you find along the way. :)
 
It's a long time since I wrote any VB, but you can respond to the radio button's CheckedChanged event to populate a picturebox's image property.

iirc, you would populate an imagelist either dynamically at start-up, or through the project's resources. you can also set the picturebox's Top property to the Top property of whatever radiobutton was clicked to make sure they line up.

something like this in CheckedChanged:

Code:
PictureBox1.Top = RadioButton1.Top
PictureBox1.Image = ImageList1.Images(0)

although I'm sure people who actually use VB will have better suggestions (I'm assuming its a windows forms app, rather than wpf)

edit: there used to be a thing called a control array, you could just pass in the index to the imagelist rather than writing the same event handler for each radiobutton - but I'm not sure if it still exists in VB.
 
How far have you got?

Often the members of this forum frown upon those who ask others to do their course/home/other work for them, so please have a go at it yourself, then ask for help with problems you find along the way. :)

I am very new to this form of programming, I clicked on one of the radio buttons and then on properites it gave me an option to add a image, but it just stayed on screen, even when I select another radio button.

I must add that this isn't a piece of coursework, purely just me having a bit of a fiddle with it.
 
Post your code. :)

I would if I knew how to!

This is what I've got so far, as I said it's a bit basic to say the least. But it's basically going to be my scrapbook of VB throughout the year, and then hopefully I have a program at the end of it that i'll release.

4Hs4L.png


So as you can see, its not exactly brilliant. I've got the radio buttons to work and the about button to show a disclamer and the exit button shuts it down completley. (However I would like to implement a 'Are you sure' option onto it, but that'll come when I learn more). I'm not kidding when I say i'm an absolute noob, I didn't bother with it untill last Monday so this is a very new thing to me.

Heres some of my code.

YhdCI.png


But if anyone here could help me get pictures so that whenever a radio button is selected a picture will appear on the side then that'll be fantastic. To the person who tried to help earlier on, I didn't understand any of what you just said!
 
hi mate - if you were referring to me above, hopefully the following will help out:

you can add a control called an ImageList to your form, from the toolbox. It won't appear on screen, but is used to contain a set of images.

you can also add a picturebox to the form (again from the toolbox), and assign an image from the imagelist to the picturebox's image property in code. I assume you've mastered this part, as you have the Barclays logo on your form.

if the picturebox doesn't have an image, it is not visible on screen. you can get it to line up with the radiobutton (if that's what you want) by moving it, again in the radiobutton's checkedchanged event.
 
Some folks from my python programming thread do Visual Basic at college, would you like to meet them on skype?
 
ok i dont have VB installed but wouldnt something as simple as this work

create 2 images van persie and dunne

call them "arsenal" and "aston" on your form respectively

form_load()
arsenal.show = false
aston.show = false
end sub()

private Sub RadioButton1_Click()
arsenal.show = true
end sub

private Sub RadioButton2_Click()
aston.show = true
end sub


bit crude i know

as long as you create one picture ontop of the other on your form this should work

you could also make it so if van persie is showing on the form and you click liverpool van persie's visibiliy is false and Suarez is true

BTW if arsenal.show = false doesn't work it could be arsenal.visible = false



hope that helps
 
Thank you for the help guys, I have decided to drop this project and work on something a bit more valid.

If you would like to view my project then please feel free to message me on trust.
 

I did some VB at college last year, but i dont currently have VB installed atm.
denby has pretty much the same idea i had. Although it may be more efficient to have one picturebox and change the image on the radio button click event. Also it is possible to set the arsenal picturebox etc to invisible in the property section.

Most of my ideas above are guess work as i havent had chance to test any ideas.


P.S Remember to annotate your code and use proper naming conventions (e.g. btnAbout instead of Button1) I know it's only a small test project but it's good to get into the habbit of doing it for future and bigger projects.


EDIT: Just saw your last post (probably should have read the whole thread before posting) If you need any help with your new project post on here again, as it will give me a chance to practise VB again :)
 
Back
Top Bottom