开发者

VB.Net Events Practice Help

开发者 https://www.devze.com 2023-03-07 07:59 出处:网络
I was given an assignment to \"write a program to print only even numbers between 6 and 16 using events\", but I don\'t eve开发者_JAVA技巧n know where to begin. The main thing I am having difficulty w

I was given an assignment to "write a program to print only even numbers between 6 and 16 using events", but I don't eve开发者_JAVA技巧n know where to begin. The main thing I am having difficulty with understanding in this assignment is how I am supposed to specify that it only print even numbers in the given range of numbers.

Am I going to have to do a Mod2 code for each individual number and have it exclude any with the result of 1? Or is there another piece of code specifically designed for such an occassion? Perhaps there is some type of equation I can have the program read in terms of a variable, which holds the values of 6, 8, 10, 12, 14, and 16? I am just genuinely confused on how this is supposed to be programmed. Any assistance would be greatly appreciated.


No offense, but I'm not at all convinced that you are accurately relaying you assignment, but...

Firstly, using MOD is a good starting point, particularly as you are supposedly tying this in with events...

To use events as part of your solution, I would suggest creating a textbox withevents and a handler for textchanged, then in a loop set the txtbox.Text property to the string representation of the loop index (say going from 1 to 20), then inside the textchanded event turn the propery back into an integer, check to see if it's within the proper range and even(using, as you suggested, MOD).


The following will help you solving a part of the problem:

Dim number as Integer = 6
While number <= 16
    // PRINT Goes here ..
    number = number + 2
End While


These Microsoft links are good learning resources:

  • Learning Visual Basic from the Ground Up

  • Getting Started with Visual Basic

  • Video How to: Creating Your First Visual Basic Program

  • Events in Visual Basic

  • Closer Look: Understanding Properties, Methods, and Events

  • Events and Event Handlers

0

精彩评论

暂无评论...
验证码 换一张
取 消