简体   繁体   English

编写一个程序,使用事件仅打印 6 到 16 之间的偶数

[英]Write a program to print only even numbers between 6 and 16 using events

I am new to programming as you can see.如您所见,我是编程新手。 I need to add an event.我需要添加一个事件。 We are learning about events and there is really no help and I have tried using the internet for hours.我们正在了解事件,实际上没有任何帮助,我已经尝试使用互联网几个小时。 I just want to learn.我只是想学习。 Thanks ahead of time.提前致谢。

Module Modulel

Public Event PrintThis(ByVal val as Integer)

SubMain()

Dim number as Integer = 6
While number <= 16
// PRINT Goes here .. ??? Not sure if right or code
number = number + 2
End While

Below link will give you clear understanding of Events.下面的链接将使您清楚地了解事件。 http://www.simple-talk.com/dotnet/.net-framework/custom-events-in-vb.net-2005/ . http://www.simple-talk.com/dotnet/.net-framework/custom-events-in-vb.net-2005/

Please let me know if it helps.如果有帮助,请告诉我。

Something like this should work.像这样的事情应该有效。 You need to use AddHandler to add the Method that will respond to your event when you call RaiseEvent .您需要使用AddHandler添加将在您调用RaiseEvent时响应您的事件的方法。

Module Module1
    Public Event PrintThis(ByVal val As Integer)
    Sub Main()

        AddHandler PrintThis, AddressOf PrintThisMethod
        Dim number As Integer = 6
        While number <= 16
            RaiseEvent PrintThis(number)
            number = number + 2
        End While
        Console.ReadLine()
    End Sub

    Private Sub PrintThisMethod(val As Integer)
        Console.WriteLine(val)
    End Sub

End Module

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 编写程序以打印与ASCII码等效的字符表(从1到122)。每行仅10个字符 - Write a program to print the table of characters that are equivalent to the ASCII codes from 1 to 122. Only 10 chars per line 显示两个整数之间偶数的和 - Display the sum of the even numbers between two integers 使用 Visual Basic,我需要在 for next 循环中添加什么才能使我的应用程序只显示偶数? - Using visual basic, what do I need to add to my for next loop to make my application display only even numbers? 困惑? 如何找到两个数字之间的偶数? VB.NET - Confused? How to find even numbers between two numbers? VB.NET 有没有办法让我编写一个程序来显示用户输入的任何四个数字的所有可能组合 - Is there a way for me to write a program that displays all the possible combinations for any four numbers entered by the user 允许用户在文本框 VB.NET 2010 中只写一个点和数字 - Allow user to write only one dot And only numbers in a textbox VB.NET 2010 在VB中使用数组而不是数据表编写程序 - Write program using array instead of data table in vb 使用逗号和点指定十进制数字有什么区别? - What is the difference between using comma and dot specifying decimal numbers? 列出所有较小的偶数 - List All Lesser Even Numbers 编写一个程序来创建一个文件,该文件仅包含另一个文本文件中的2个字段(含6个字段)? (VB2012) - Write a program to create a file that consists of only 2 fields from another text file with 6? (VB2012)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM