Help With CSI 101 Homework #7: Writing Click Event Procedure Using Classes

  • Thread starter Calculus!
  • Start date
  • Tags
    Homework
In summary, the code in the Click event will use the class to calculate the average and maximum value from four integers that are inputted into the text boxes.
  • #1
Calculus!
20
0
Hi! I do not know how to do any of this. Can someone please help me! Thank you.

Write the command button Click event procedure from Homework #7 using classes. You should define the class, then write the code contained in the Click event that would use the class.

As a reminder, Homework #7 read four integers from text boxes, calculated the average and maximum value, and placed them into text boxes. Your code will do that again, but use a class. Your class will contain four integers as member data. The data must obtain the values in the text boxes, so you will need a constructor or SET function. You’ll also need two method functions, one that returns the average and one that returns the maximum value. Clearly, neither of those will require arguments.

You can create this code in Visual Studio or .NET Framework if you wish, but it isn’t necessary. I only need the code, you do not need to recreate the form.


Homework #7:

'This is the code to be placed within the _Click() event of the button labeled START

'Declarations. These are needed, as you DO NOT receive any data from the arguments.
' The arguments to the Click event are set by Visual Studio options. Adding any to
' the function declaration simply means that you receive 0 values for the other arguments
Dim A As Integer, B As Integer, C As Integer, D As Integer 'The 4 integers
Dim Average As Decimal 'Must be decimal, as we want decimal places
Dim Max As Integer

'Obtain the 4 integers. Remember to convert them, as Text boxes hold Strings
A = CInt(txtNum1.Text) 'The Text property of a text box holds its value
B = CInt(txtNum2.Text)
C = CInt(txtNum3.Text)
D = CInt(txtNum4.Text)

Average = (A+B+C+D)/4
txtAverage.Text = Format(Average,”##0.00”) 'Format function isn't necessary.
'Could have used CStr function instead
'Didn't have to convert here, as Visual Studio does it for you, but it's best not
' to get comfortable with that. Not all compilers will automatically do that.

'Find maximum. Here I use a running max. I set the first number to max. I then compare
' each successive number. If the number is greater is max, I set max equal to the larger
' number. At the end, Max holds the highest value
Max = A
If B > Max Then Max = B
If C > Max Then Max = C
If D > Max Then Max = D

txtMax.Text = Cstr(Max)

Me.Refresh 'Necessary to immediate see changes to output boxes


Thanks Again.
 
Physics news on Phys.org
  • #2
Calculus!,

What is the IDE that your teacher told you to use? I notice it mentions .Net, but what are you using to write the code for any other homework assignments?
 
  • #3
I just use Microsoft Word and that's fine.
 
  • #4
Well, first I would make a form with 4 text boxes and a command button.

Name the 4 text boxes as the teacher told you to.

Then take the code you need and paste it into the command buttons OnClick or Click event.
 

FAQ: Help With CSI 101 Homework #7: Writing Click Event Procedure Using Classes

How do I write a click event procedure using classes for CSI 101 homework #7?

To write a click event procedure using classes, you will need to first create a class that contains the elements you want to interact with. Then, you can use the addEventListener method to add a click event listener to those elements. Finally, you can define a function within the class that will be executed when the click event is triggered.

What is the purpose of using classes in a click event procedure?

Classes allow you to group together related elements and functions, making your code more organized and easier to maintain. In the context of click event procedures, classes can be used to add multiple event listeners to different elements, without having to write separate functions for each one.

How do I access elements inside a class for my click event procedure?

You can use the this keyword to access elements within the class. For example, if you have an element with an id of "button" inside your class, you can access it using this.button within your click event function.

Do I need to use a specific programming language to write a click event procedure using classes?

No, you can use any programming language that has the ability to create classes and add event listeners. Some common languages used for web development include JavaScript, Python, and Java.

Can you provide an example of a click event procedure using classes?

Sure! Here is a basic example using JavaScript:

class Button { constructor() { this.button = document.getElementById("button"); this.button.addEventListener("click", this.handleClick); } handleClick() { // code to be executed when button is clicked }}let button = new Button();

Similar threads

Replies
3
Views
2K
Replies
1
Views
6K
Replies
1
Views
3K
Replies
2
Views
2K
2
Replies
61
Views
7K
Back
Top