我有一个学校作业,要求我使用循环和一些数学方程式。项目需要完成的是您在数字顶部输入一个范围。然后在下面的文本框中输入一个数字和每边的一个单词。当您点击“计算”时,程序需要将您输入的数字的所有 MULTIPLES 替换为您在其下方输入的 WORD。这应该发生在两组数字和单词上。然后,如果一个数字是两者的倍数,它应该显示两个单词。
这是我的 GUI 的屏幕截图,可帮助您了解我的意思。
这是到目前为止的代码,它产生的是一个列表或我想要的所有倍数......但它只是在数字下方添加单词。
如何让它用我想输入的单词替换数字?
谢谢。
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
Dim counter As Integer
Dim intCounterHigh As Integer
Dim intCounterLow As Integer
Dim intMultipleLeft As Integer
Dim intMultipleRight As Integer
Dim strWordLeft As String
Dim strWordRight As String
intCounterHigh = txtCounterHigh.Text
intCounterLow = txtCounterLow.Text
strWordLeft = txtWordLeft.Text
strWordRight = txtWordRight.Text
intMultipleLeft = txtMultipleLeft.Text
intMultipleRight = txtMultipleRight.Text
While counter <= intCounterHigh - 1
counter += 1
lstResult.Items.Add(CStr(counter))
If counter Mod intMultipleLeft < 1 Then
lstResult.Items.Add(strWordLeft)
End If
If counter Mod intMultipleRight < 1 Then
lstResult.Items.Add(strWordRight)
End If
If counter Mod intMultipleRight < 1 And counter Mod intMultipleLeft < 1 Then
lstResult.Items.Add(strWordLeft & strWordRight)
End If
End While
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
lstResult.Items.Clear()
End Sub
Private Sub txtCounter_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtCounterHigh.TextChanged
End Sub
End Class