我收到错误代码而我的朋友不是。 [英] I'm getting an error code while my friend is not.

查看:43
本文介绍了我收到错误代码而我的朋友不是。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个编程类的项目。我们应该创建一对骰子1000次,并找到他们加起来的所有时间7.我的朋友和我有相同的确切代码和他的作品,我的不会。我们甚至有相同的错误代码但
我不会让我开始这个项目。它一直说我检查时没有调试文件夹中的project.exe,我做了。这是我们的代码。单击按钮时发生错误,我不明白为什么。

 Public Class Form1 

Public Sub Button1_Click(sender As Object,e As EventArgs,ByVal pair1 As Integer,ByVal pair2 As Integer)处理Button1 .Click
Label1.Text = pair1.ToString
Label2.Text = pair2.ToString
if pair1> pair2然后
MessageBox.Show(" Player 1 wins!")
ElseIf pair2> pair1然后
MessageBox.Show(" Player 2 wins!")
ElseIf pair1 = pair2然后
MessageBox.Show(" Player 1 and Player 2 tied!")
结束如果
结束次级


结束等级

公共类别HighRoller
Dim rnd As Random

Dim pair1 As Integer
Dim pair2 As Integer
Dim dice1 As New PairOfDice1(rnd)
Dim dice2 As New PairOfDice1(rnd)

Dim dice3 As New PairOfDice2 (rnd)
Dim dice4 As New PairOfDice2(rnd)

Dim roll1 As Integer = dice1.roll
Dim roll2 As Integer = dice2.roll
Dim roll3 As Integer = dice3.roll
Dim roll4 As Integer = dice4.roll
Public Sub New(ByVal roll1 As Integer,roll2 As Integer,roll3 As Integer,roll4 As Integer)
pair1 = roll1 + roll2
pair2 = roll3 + roll4

结束次级


结束等级

公共类PairOfDice1
Dim num1 As Integer
Private rnd1 As Random

Public Sub New(ByVal random As Random)
rnd1 = random

End Sub

公共函数roll()As Integer
Randomize()
num1 = Int(Rnd()* 6)+ 1
返回num1

结束函数
结束类

公共类PairOfDice2
Dim num2 As Integer
Private rnd1 As Random

Public Sub New(ByVal random As Random)
rnd1 = random

End Sub

公共函数roll()As Integer
Randomize()
num2 = Int(Rnd() * 6)+ 1
返回num2

结束函数
结束类



解决方案

您好


尝试将Option Strict On置于代码顶部并重新编译 - 然后修复所有错误。


I'm coding for a project in a programming class. We are supposed to create a pair of dice 1000 times and find all the times they add up to 7. My friend and I have the same exact code and his works and mine will not. We even have the same error code yet mine is not letting me even start the project. It keeps saying that I don't have the project.exe in the debug folder while I checked and I did. Here's the code that we have. The error is occurring on the button click and I don't understand why.

Public Class Form1

    Public Sub Button1_Click(sender As Object, e As EventArgs, ByVal pair1 As Integer, ByVal pair2 As Integer) Handles Button1.Click
        Label1.Text = pair1.ToString
        Label2.Text = pair2.ToString
        If pair1 > pair2 Then
            MessageBox.Show("Player 1 wins!")
        ElseIf pair2 > pair1 Then
            MessageBox.Show("Player 2 wins!")
        ElseIf pair1 = pair2 Then
            MessageBox.Show("Player 1 and Player 2 tied!")
        End If
    End Sub


End Class

Public Class HighRoller
    Dim rnd As Random

    Dim pair1 As Integer
    Dim pair2 As Integer
    Dim dice1 As New PairOfDice1(rnd)
    Dim dice2 As New PairOfDice1(rnd)

    Dim dice3 As New PairOfDice2(rnd)
    Dim dice4 As New PairOfDice2(rnd)

    Dim roll1 As Integer = dice1.roll
    Dim roll2 As Integer = dice2.roll
    Dim roll3 As Integer = dice3.roll
    Dim roll4 As Integer = dice4.roll
    Public Sub New(ByVal roll1 As Integer, roll2 As Integer, roll3 As Integer, roll4 As Integer)
        pair1 = roll1 + roll2
        pair2 = roll3 + roll4

    End Sub


End Class

Public Class PairOfDice1
    Dim num1 As Integer
    Private rnd1 As Random

    Public Sub New(ByVal random As Random)
        rnd1 = random

    End Sub

    Public Function roll() As Integer
        Randomize()
        num1 = Int(Rnd() * 6) + 1
        Return num1

    End Function
End Class

Public Class PairOfDice2
    Dim num2 As Integer
    Private rnd1 As Random

    Public Sub New(ByVal random As Random)
        rnd1 = random

    End Sub

    Public Function roll() As Integer
        Randomize()
        num2 = Int(Rnd() * 6) + 1
        Return num2

    End Function
End Class


解决方案

Hi

Try putting Option Strict On at the top of your code and recompile - then fix all the errors.


这篇关于我收到错误代码而我的朋友不是。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆