I'm in agony

Post Reply
User avatar
Cakedaddy
Posts: 9422
Joined: Thu May 20, 2004 6:52 pm

Post 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."
TheCatt
Site Admin
Posts: 58419
Joined: Thu May 20, 2004 11:15 pm
Location: Cary, NC

Post 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"
It's not me, it's someone else.
GORDON
Site Admin
Posts: 56735
Joined: Sun Jun 06, 2004 10:43 pm
Location: DTManistan
Contact:

Post by GORDON »

I'd just turn in The Plan V1.1 with the completed project.
"Be bold, and mighty forces will come to your aid."
User avatar
Cakedaddy
Posts: 9422
Joined: Thu May 20, 2004 6:52 pm

Post 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.
TheCatt
Site Admin
Posts: 58419
Joined: Thu May 20, 2004 11:15 pm
Location: Cary, NC

Post 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.
It's not me, it's someone else.
User avatar
Cakedaddy
Posts: 9422
Joined: Thu May 20, 2004 6:52 pm

Post 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
GORDON
Site Admin
Posts: 56735
Joined: Sun Jun 06, 2004 10:43 pm
Location: DTManistan
Contact:

Post by GORDON »

What's a subroutine?

Good grief, you've missed the basics.
"Be bold, and mighty forces will come to your aid."
Leisher
Site Admin
Posts: 71385
Joined: Thu May 20, 2004 9:17 pm
Contact:

Post 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.
“Activism is a way for useless people to feel important, even if the consequences of their activism are counterproductive for those they claim to be helping and damaging to the fabric of society as a whole.” - Dr Thomas Sowell
User avatar
Cakedaddy
Posts: 9422
Joined: Thu May 20, 2004 6:52 pm

Post 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.
TheCatt
Site Admin
Posts: 58419
Joined: Thu May 20, 2004 11:15 pm
Location: Cary, NC

Post 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.
It's not me, it's someone else.
thibodeaux
Posts: 8121
Joined: Thu May 20, 2004 7:32 pm

Post 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]
User avatar
Cakedaddy
Posts: 9422
Joined: Thu May 20, 2004 6:52 pm

Post 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.
thibodeaux
Posts: 8121
Joined: Thu May 20, 2004 7:32 pm

Post 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
TheCatt
Site Admin
Posts: 58419
Joined: Thu May 20, 2004 11:15 pm
Location: Cary, NC

Post 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.
It's not me, it's someone else.
User avatar
Cakedaddy
Posts: 9422
Joined: Thu May 20, 2004 6:52 pm

Post 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.
thibodeaux
Posts: 8121
Joined: Thu May 20, 2004 7:32 pm

Post by thibodeaux »

Let us know if we get an A+.
Post Reply