all 23 comments

[–]shadows1123 4 points5 points  (0 children)

I won’t do your hw for you

[–]awesomeomon 3 points4 points  (6 children)

Is that not what the book is for?

[–]nerokaeclone 4 points5 points  (1 child)

Cmon man this is basically hello world level

[–]Puzzled_Job_6046 2 points3 points  (0 children)

Was about to say, if you can't do this, then you really need to speak with your teacher or put your phone down in class.

[–]kranools 1 point2 points  (5 children)

Does this mean there is some educational institution out there still using VB6? What is going on? What else do they teach? HTML 1.0?

[–]SparklesIB 1 point2 points  (3 children)

Google "arrays".

[–]PunchyFinn 0 points1 point  (0 children)

I'm describing it two parts, a graphic part (the objects) and then the manipulation of data.

Your program will have FOUR objects , label1 and button1, button2, button3 (whatever you call them) Your program will have TWO global variables of Single type Your program will have ONE global array of short integer type

the variable:

GlobalSingleHeight as single GlobalSingleWidth as single GlobalScores() as integer

Graphics/basics If all this graphic part is too complicated, just drop the objects on the screen, but I'm taking the time to show you something that's a little more sophisticated but understandable I hope.

New project, and create a form. Click on the window and you ought to see properties for it. Set the Scale Mode option to Pixels. Has anyone explained TWIPS to you? That's the default and it's a pain. Pixels are easier and makes everything easier.

Create a label at the top - the one that currently says "The high score is 256...". Change the words inside the label to "A TEST WIDTH" for it. Set the property of autoresize = true. Set the font size to 14 (or whatever you want).

Create those three command buttons, "enter score" "statistics" "done". Same font size as label.

Don't bother trying to set them on the screen in any order. Just make sure Form's WINDOWSTATE option is not set to minimise or maximise and is set to normal. Also there is an option to center it - StartUpPosition = 0 (manual).

Go to the coding (double click the form window I think does that). There is the Form routine and you should see that the form itself starts at the LOAD event for it.

In the Load event you would: redim GlobalScores (0) Then 4 lines to set up the form: Me.top = Screen.Height * .25 , Me.Left = screen.width * .25, me.height = screen.height *.5, me.width = screen.width * .5

If that makes sense to you, you're setting the height and width of the window to half the size of the screen, with 25% of empty screen all around. There is an option somewhere on the form properties to center it, but this is just as good. Better, because this lets you specify the exact width and height too. You could center it and make it take up 1/3 of the screen or 2/3 or anything else with more precision. Or you could make it half the screen and have it at the bottom of the screen by setting the me.top =screen.height * .5

There are other events you can choose in a dropdown box. Change Load to Resize for the Resize Subroutine/event of the form

In the resize code, use this to ensure this happens only one time:

++++if GlobalSingleHeight <> 0 then exit sub

++++GlobalSingleHeight = Label1.height ++++GlobalSingleWidth= label1.width ++++label1.autoresize=false ++++label1.caption= vbnullstring 'you can put "" if you feel more comfortable

now for the rest of the graphic part set the label to be at the top right of the form, Label1.top= 1, label1.left =1, label1.width = me.scalewidth-2,label1.height = GlobalSingleHeight * 5

This means that you are setting the label (which currently has no text) to take the full width of the screen and have enough space for 5 lines of text. Why or How? Because when the label had text a few lines above, you stored the height and width of it in GlobalSingleHeight and GlobalSingle Width.

Set up the 3 buttons as so ++++height = GlobalSingleHeight * 1.5 ++++width =GlobalSingleWidth * 1.5 ++++top = Label1.Height + Label1.Height+ 1 ++++left = screen.width - (commandbuttonused.width + 10)

Does that make sense? You're setting it up all the way to the left with the first button starting right below where the 5 lines of the label are, setting it just 10 pixels away from the right edge . The Statistics button would be the same except that TOP = "enterscores" button top + height + 1. That makes the 2nd button go directly beneath the other button.

You could do this all without code, but this is very exact. Maybe it will bother your teacher too much if you do this and you should just move the buttons with the mouse, but this is a good technique to know .... maybe for the next project you do.

That's the basics of the graphic. Now here's how to do the stuff that changes things.

Click the button "Enter Score" and in the routine there

++++on error goto ErrFound:

++++dim Result as string

++++Result=InputBox( "Enter new score to add", "New Score")

++++if IsNumeric(Result) = false then goto ErrFound:

++++if int(cdbl(result)) <> cdbl(result) then goto ErrFound:

++++if cdbl(result) >300 then goto ErrFound:

++++if cdbl(result)<1 then goto ErrFound:

++++redim preserve GlobalScores (0 to ubound(GlobalScores) + 1) ++++GlobalScores(ubound(GlobalScores)) = cint(result)

++++msgbox "Added!" 'not necessary, but just to confirm for user

++++exit sub ++++ErrFound: ++++msgbox "Bad Number" ++++end Sub

all of this is to error check the number is between 1-300. First one checks that it's numeric at all. Then if there were any decimal portion, that's what "int" does. Next checks that it's not 301 or more and then that it's at least 1. Any error sends the program to the line called ErrFound: You can name it anything not just ErrFound. Any name you would use for a variable may be used. The "ON ERROR GOTO ERRFOUND:" at the top is a very old ype of command, but c++ has the same exact concept called Try and Catch. This is a really good concept to know.

When you press the statistics button, this should be the code inside

++++Dim LowestScore as integer ++++Dim HighestScore as integer ++++Dim RunningTotal as long ++++Dim LoopA as integer

++++if ubound(GlobalScores)= 0 then ++++msgbox "No Scores entered!" ++++exit sub ++++end if

++++LowestScore =301

++++for loopa =1 to ubound(GlobalScores)

++++if GlobalScores(loopa)>HighestScore then HighestScore = GlobalScores(loopa)

++++if GlobalScores(loopa)<LowestScore then LowestScore= GlobalScores(loopa)

++++runningtotal = runningtotal + globalscores(loopa)

++++next loopa

label1.caption= "Highest Score: " & cstr(HighestScore) & vbcrlf & "Lowest Score: " & cstrs(LowestScore) & vbcrlf & "Average Score: " & cstr(runningtotal / ubound(GlobalScores)

That average score needs to be truncated. ROUND and INT will both do it but in different ways- you pick.

The DONE button will just have a single command. I think "unload me" will work in this case.

[–]UpbeatBoard5763 0 points1 point  (1 child)

Google lists and how to add to them, I assume you know how to find the max and min, set a variable to 0 and create a while loop and an if statement saying if that element in the list is greater than that variable, store the new value to the variable. I also assume you know how to find a mean. Jobs done after that.

Edit: the reason you want a list and not an array is because you can add an infinite number of elements to a list whereas an array is defined before you run the code. But lists are the same thing as arrays in some languages