Page 1 of 1

Posted: Thu Jan 04, 2007 5:35 pm
by Cakedaddy
My son took a programming class in high school (freshman). They are learning VB.

What's killing me is, his current project is kind of a mix between a text adventure and . . . I don't know. Basically, the bottom of the window is a picture to show you what you see instead of words describing it. You will have different options depending on which screen you are on. Leave building. Go north. Enter shop. Etc. Nice easy beginning thing, I thought. The agony is watching him use fucking radio buttons to initiate an action. Game starts, you are at home. Options, go into town, stay in bed. Those are radio buttons. Click on go into town, and the window instantly updates to you being outside. He hides and unhides radio buttons as more or less options are available to the player. Eventually plans on putting in some animation, etc. Cool project, I thought. His mistakes with the radio buttons, to me, is forgivable, because he's a beginner. I told him he should make object in the picture clickable. Door takes you outside. Bed rests you. etc. He liked that idea. But he can't stop using the RBs cause that's what's in his 'plan'. The Plan was the concept written on paper that he and his teacher went over. They both thought it was a good idea to use radio buttons. She also didn't know how to make an action happen when the mouse hovered over something. I kept going on and on about how they were horrible programming habbits that are best abandoned now. He can't cause of the plan. The teacher is expecting to see the program based on the plan. When I found out the teach agreed he was on the right track, my heart sank. Seeing the look of disapointment in my eyes, he comforted me with. "What do you expect. She's a biology teacher."

Posted: Thu Jan 04, 2007 5:41 pm
by TheCatt
That story brings to mind every issue I have with public education.

On the other hand, it sure explains the mentality of some bad PMs I've worked with. "But the spec says radio buttons"

Posted: Thu Jan 04, 2007 6:34 pm
by GORDON
I'd just turn in The Plan V1.1 with the completed project.

Posted: Thu Jan 04, 2007 8:54 pm
by Cakedaddy
I won him over. . . he's ditching the radio buttons and going with regular push buttons for navigation. We decided he could put radio buttons in there for quest type stuff when the time comes to fulfill the radio button requirement if need be.

What broke him was when he'd ask me for help, I'd tell him that I couldn't help him cause I simply could not support the current course of action. I couldn't help him become a bad programmer.

One thing I didn't know how to do though, was a seperate chunk of code. Been too long since I've played with programming that I've actually forgot where to put a resuable chunk of code. For example, he now has navigation buttons. N, S, E, W. Click one, and it changes the 'location' variable. Now, every time the location variable changes, this affects what buttons are visible (north not visible when at the top of the map) and which picture you see (in house, courtyard, in blacksmith, etc). I wanted each button to be similar to:

location = location + 1
execute chunk of code that determines where you are and what to display

Currently, we have to have the same code associated with each button cause I don't know where to put code that's not actually associated with an object, or how to execute it.

If it can be explained quickly, let me know.

Posted: Thu Jan 04, 2007 9:07 pm
by TheCatt
Which type of VB? Original VB or VB.Net?

In VB.Net just add "handles (Buttonname).click" to the end of a routine to handle the events.

In VB... I don't know. You can fake it by having the handlers call a common method.

Posted: Thu Jan 04, 2007 9:48 pm
by Cakedaddy
It's the free version of VB that you can download. Express? I think.

Unfortunately, both of those explinations were over my head. :-) What's a routine? What's a common method? I'd need you to explain it to me like I'm a 6 year old. . .

Actually, he's going to ask his teacher how to handle this tomorrow. . . let's see how your answers compare. heheh

Posted: Thu Jan 04, 2007 9:57 pm
by GORDON
What's a subroutine?

Good grief, you've missed the basics.

Posted: Thu Jan 04, 2007 9:59 pm
by Leisher
It's the free version of VB that you can download. Express? I think.


Yes, it's called Express.

I downloaded it recently in preparation for my own little Help Desk project.

Posted: Fri Jan 05, 2007 1:59 am
by Cakedaddy
GORDON wrote:What's a subroutine?

Good grief, you've missed the basics.
I didn't ask what a subroutine was. . . I asked what a routine was. Since you are implying they are the same thing, fine. Didn't know the code associated with an object was a 'routine'. I know the basics. . . just don't know how to apply all of them to VB or all the terms used.

In C++, I would have created a function, and been done with it. I don't know how to create a function in VB.

Posted: Fri Jan 05, 2007 7:30 am
by TheCatt
VB Express is VB.Net (1.1 .Net Framework)

It's the good version.

So if you have a button called cmdButton, and it has a click event (you can create this just by double-clicking on it), it'd be something like this:

private sub cmdButton_Click handles cmdButton.Click
....
end sub

just add the names of your other buttons "cmdNorth.click, cmdSouth.click, "etc and they'll all be handled by that same routine.

Posted: Fri Jan 05, 2007 9:13 am
by thibodeaux
Cakedaddy wrote:In C++, I would have created a function, and been done with it. I don't know how to create a function in VB.

Do you want to do something like this?

Code: Select all

Public Class Form1

    'data members to hold location on a grid
    Private _x As Integer
    Private _y As Integer

    'where am I and what do I see?  This does that
    Private Sub RenderMap()
        'Do some stuff to display map, etc
    End Sub

'''' these are the click handlers for the buttons
'''' they update the location data and then call RenderMap
    Private Sub ButtonN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonN.Click
        _y = _y + 1
        RenderMap()
    End Sub

    Private Sub ButtonS_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonS.Click
        _y = _y - 1
        RenderMap()
    End Sub

    Private Sub ButtonE_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonE.Click
        _x = _x + 1
        RenderMap()
    End Sub

    Private Sub ButtonW_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonW.Click
        _x = _x - 1
        RenderMap()
    End Sub

End Class
[/color]

Posted: Fri Jan 05, 2007 12:00 pm
by Cakedaddy
Both of those examples are excelent! Thank you. Thib, that's exectly what I had in mind. Catt, do I just put commas between each button?

Private Sub ButtonN_Click handles ButtonS_Click, ButtonW_Click, ButtonE_Click

or is it:

Private Sub ButtonN_Click handles ButtonS_Click handles Button W_Click handles ButtonE_Click


And of the two meathods, which is better? I see them both as equaly good/proper.

Posted: Fri Jan 05, 2007 1:05 pm
by thibodeaux
Well, MY method is better, of course :) Either will work, but I think if you have to do ANY different code for each button (e.g., north increments something while south decrements it), I think mine is better.

Also, you're right about the commas:

Code: Select all

Private Sub Button1_Click(   ByVal sender As System.Object,   ByVal e As System.EventArgs)    Handles Button1.Click, Button2.Click
  MsgBox("Hello World!")

End Sub
(from http://www.informit.com/article....=3&rl=1. I didn't actually test that code, though)[/color]



Edited By thibodeaux on 1168020361

Posted: Fri Jan 05, 2007 1:49 pm
by TheCatt
Well, it depends on what you want. Thib's method allows for each event to have its own code, and call a shared piece of code (RenderMap). The way I posted is if you want each to run the exact same code. If the buttons do different things (go north, south, etc) Thib's the right one.

Posted: Fri Jan 05, 2007 4:49 pm
by Cakedaddy
I came to that conclusion after posting as well. As stated, they each increment/decriment differently, so the called function is what we'll do.

Posted: Sat Jan 06, 2007 7:42 pm
by thibodeaux
Let us know if we get an A+.