本文介绍了帮助正确的代码......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我正在尝试在VB中构建一个15号码的shuffle游戏。 稍后我将不得不提交15件到一个完整的图像。 在最小的时候我试图用数字来构建它。一切正常,直到我得到这个消息: 从字符串转换到'双'的类型无效。 i得到它:if butt2 .Content =然后 这里是我的代码: Class MainWindow 私人 Sub btn1_Click(发件人作为 对象,e 作为 RoutedEventArgs)句柄 btn1。点击 ' 2,4 checkBtn(btn1,btn4) checkBtn(btn1,btn2) chechSolved() 结束 Sub 私有 Sub btn2_Click(sender 为 对象,e As RoutedEventArgs)句柄 btn2.Click ' 1,3,5 checkBtn(btn2,btn1 ) checkBtn(btn2,btn3) checkBtn(btn2,btn5) chechSolved() 结束 Sub 私有 Sub btn3_Click(发件人作为 对象,e 作为 RoutedEventArgs)句柄 btn3.Click ' 2 ,6 checkBtn(btn3,btn2) checkBtn(btn3,btn6) chechSolved() 结束 子 私人 Sub btn4_Click( sender 作为 对象,e As RoutedEventArgs) 句柄 btn4。点击 ' 1,5 ,7 checkBtn(btn4,btn1) checkBtn(btn4,btn5) checkBtn(btn4,btn7) chechSolved() 结束 Sub 私人 Sub btn5_Click(发件人作为 对象,e As RoutedEventArgs)句柄 btn5。点击 ' 2,4,6,8 checkBtn(btn5,btn2) checkBtn(btn5,btn4) checkBtn(btn5,btn6) checkBtn(btn5, btn8) chechSolved() 结束 Sub 私有 Sub btn6_Click(发件人作为 Object ,e As RoutedEventArgs) Handles btn6。点击 ' 3,5,9 checkBtn(btn6,btn3) checkBtn(btn6,btn5) checkBtn(btn6,btn9) chechSolved() 结束 Sub 私有 Sub btn7_Click(发件人作为 对象,e As RoutedEventArgs)句柄 btn7.Click ' 4,8 checkBtn(btn7,btn4) checkBtn(btn7,btn8) chechSolved() 结束 Sub 私有 Sub btn8_Click(sender 作为 对象,e As RoutedEventArgs)句柄 btn8。点击 ' 5,7,9 checkBtn(btn8,btn5) checkBtn(btn8,btn7) checkBtn(btn8,btn9) chechSolved() 结束 Sub 私人 Sub btn9_Click(发件人作为 对象,e 正如 RoutedEventArgs)句柄 btn9.Click ' 6,8 checkBtn(btn9,btn6) checkBtn(btn9,btn8) chechSolved() 结束 Sub Sub checkBtn ( ByVal butt1 作为按钮, ByVal butt2 作为按钮) 如果 butt2.Content = 然后 butt2.Content = butt1.Content butt1.Content = 结束 如果 结束 Sub Sub chechSolved() 如果 btn1.Content = 1 和 btn2.Content = 2 和 btn3.Content = 3 和 btn4.Content = 4 和 btn5.Content = 5 和 btn6.Content = 6 和 btn7.Content = 7 和 btn8.Content = 8 和 btn9.Content = 然后 MsgBox( הצלחת) 结束 如果 结束 Sub Sub shuffle() 昏暗 a( 8 ),i,j,RN As Integer Dim flag As Boolean flag = False i = 1 a(j)= 1 while i< = 8 Randomize() RN = CInt (Int(( 8 * Rnd())+ 1 )) 对于 j = 1 至 i 如果(a(j)= RN)那么 flag = True 退出 对于 结束 如果 下一步 如果 flag = True 然后 flag = 错误 其他 a(i)= RN i = i + 1 结束 如果 循环 btn1.Content = a ( 1 ) btn2.Content = a( 2 ) btn3.Content = a( 3 ) btn4.Content = a( 4 ) btn5.Content = a ( 5 ) btn6.Content = a( 6 ) btn7.Content = a( 7 ) btn8.Content = a( 8 ) btn9 .Content = 结束 Sub 私有 Sub btnSH_Click(发件人作为 对象,e 正如 RoutedEventArgs)句柄 btnSH.Click shuffle() 结束 Sub 结束 Class 如果你看一下它会有很大的帮助。解决方案 使用 double.Parse 。这不是你真正的问题。你真正的问题是......缺乏编程。感觉不是程序员的代码,而是缺乏经验的用户(非开发人员)创建的东西。代码片段只是重复。这不是编程的工作原理。您需要了解抽象的工作原理。我不确定你已经准备好了,但是在开始编程的时候开始学习某些东西。 -SA I am trying to build a 15 number shuffle game in VB. later on i will have to submit the 15 pieces to a full image.at the mintime i tries to build it with numbers. it was all working fine until i got this messege: "Conversion from string "" to type 'Double' is not valid".i got it line: "If butt2.Content = "" Then"here is my code:Class MainWindow Private Sub btn1_Click(sender As Object, e As RoutedEventArgs) Handles btn1.Click '2,4 checkBtn(btn1, btn4) checkBtn(btn1, btn2) chechSolved() End Sub Private Sub btn2_Click(sender As Object, e As RoutedEventArgs) Handles btn2.Click '1,3,5 checkBtn(btn2, btn1) checkBtn(btn2, btn3) checkBtn(btn2, btn5) chechSolved() End Sub Private Sub btn3_Click(sender As Object, e As RoutedEventArgs) Handles btn3.Click '2,6 checkBtn(btn3, btn2) checkBtn(btn3, btn6) chechSolved() End Sub Private Sub btn4_Click(sender As Object, e As RoutedEventArgs) Handles btn4.Click '1,5,7 checkBtn(btn4, btn1) checkBtn(btn4, btn5) checkBtn(btn4, btn7) chechSolved() End Sub Private Sub btn5_Click(sender As Object, e As RoutedEventArgs) Handles btn5.Click '2,4,6,8 checkBtn(btn5, btn2) checkBtn(btn5, btn4) checkBtn(btn5, btn6) checkBtn(btn5, btn8) chechSolved() End Sub Private Sub btn6_Click(sender As Object, e As RoutedEventArgs) Handles btn6.Click '3,5,9 checkBtn(btn6, btn3) checkBtn(btn6, btn5) checkBtn(btn6, btn9) chechSolved() End Sub Private Sub btn7_Click(sender As Object, e As RoutedEventArgs) Handles btn7.Click '4,8 checkBtn(btn7, btn4) checkBtn(btn7, btn8) chechSolved() End Sub Private Sub btn8_Click(sender As Object, e As RoutedEventArgs) Handles btn8.Click '5,7,9 checkBtn(btn8, btn5) checkBtn(btn8, btn7) checkBtn(btn8, btn9) chechSolved() End Sub Private Sub btn9_Click(sender As Object, e As RoutedEventArgs) Handles btn9.Click '6,8 checkBtn(btn9, btn6) checkBtn(btn9, btn8) chechSolved() End Sub Sub checkBtn(ByVal butt1 As Button, ByVal butt2 As Button) If butt2.Content = "" Then butt2.Content = butt1.Content butt1.Content = "" End If End Sub Sub chechSolved() If btn1.Content = "1" And btn2.Content = "2" And btn3.Content = "3" And btn4.Content = "4" And btn5.Content = "5" And btn6.Content = "6" And btn7.Content = "7" And btn8.Content = "8" And btn9.Content = "" Then MsgBox("הצלחת") End If End Sub Sub shuffle() Dim a(8), i, j, RN As Integer Dim flag As Boolean flag = False i = 1 a(j) = 1 Do While i <= 8 Randomize() RN = CInt(Int((8 * Rnd()) + 1)) For j = 1 To i If (a(j) = RN) Then flag = True Exit For End If Next If flag = True Then flag = False Else a(i) = RN i = i + 1 End If Loop btn1.Content = a(1) btn2.Content = a(2) btn3.Content = a(3) btn4.Content = a(4) btn5.Content = a(5) btn6.Content = a(6) btn7.Content = a(7) btn8.Content = a(8) btn9.Content = "" End Sub Private Sub btnSH_Click(sender As Object, e As RoutedEventArgs) Handles btnSH.Click shuffle() End SubEnd Classit would help a lot if you look at it. 解决方案 Use double.Parse. This is not your real problem. Your real problem is… the lack of programming. It feels like not a programmer's code, but something created by an inexperience user (non-developer). Fragments of code are just repeated. This is not how programming works. You need to learn how abstraction works. I'm not sure you are ready, but start learning from something, somewhere about the very beginning of programming.—SA 这篇关于帮助正确的代码......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-28 07:48