请更正我的代码SOS! [英] Please Correct My Code SOS!

查看:94
本文介绍了请更正我的代码SOS!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Visual Basic中为MS Excel中的应用程序编写代码,但无法正常工作.这是我的功课.
请尽快写出更正的代码.

我不记得原来的任务,但这就是我记得的事情.
Excel中有两个4x5矩阵.用户在矩阵中随机写入一些数字,然后单击第一个按钮CommandButton1_Click(),代码必须在第一个矩阵中对数字进行升序排序.通过单击第二个按钮CommandButton2_Click(),代码必须对第二个矩阵中按列降序排列的数字进行排序.
这是矩阵的可视示例.

http://i50.tinypic.com/2j34ho7.jpg
那就是结果的样子.
http://i49.tinypic.com/i4plkn.jpg

I''m trying to write code in Visual Basic for Application in MS Excel, but it''s not working properly. It''s for my homework.
Please write the corrected code ASAP.

I don''t remember the original task, but that''s what I''ve remembered.
There are two 4x5 matrices in Excel. The user writes some numbers randomly in the matrices and by clicking first button CommandButton1_Click()the code must sort the numbers in the first matrix ascending. By clicking the second button CommandButton2_Click() the code must sort the numbers in the second matrix descending in columns.
Here is the visual example of matrix.

http://i50.tinypic.com/2j34ho7.jpg
That''s how the result should look.
http://i49.tinypic.com/i4plkn.jpg

Dim a(4, 5), b(4, 5), buff As Double
 Dim i, j, k  As Integer
Private Sub CommandButton1_Click()
For i = 1 To 4
   For j = 1 To 5
      b(i, j) = Cells(i + 9, j + 1).Value
   Next j
  Next i
For i = 1 To 5
  For j = 1 To 4
   For k = j + 1 To 4
      If b(j, i) < b(k, i) Then
             buff = b(k, i): b(k, i) = b(j, i): b(j, i) = buff
     End If
      Next k
   Next j
 Next i
  For i = 1 To 4
   For j = 1 To 5
       Cells(i + 9, j + 1).Value = b(i, j)
   Next j
  Next i
End Sub

Private Sub CommandButton2_Click()
For i = 1 To 4
   For j = 1 To 5
     a(i, j) = Cells(i + 2, j + 1).Value
      b(i, j) = Cells(i + 9, j + 1).Value
   Next j
  Next i
For k = 1 To 4
  For i = 1 To 4
   For j = i + 1 To 5
    If a(k, i) > a(k, j) Then
     buff = a(k, i):    a(k, i) = a(k, j): a(k, j) = buff
     End If
Next j
   Next i
 Next k
For i = 1 To 4
   For j = 1 To 5
       Cells(i + 2, j + 1).Value = a(i, j)
        Next j
  Next i
End Sub

推荐答案

我们不能.

当您报告的问题为 无法正常工作"时,您如何期望我们 在12小时内编写更正的代码" /b> ?

我们甚至都不知道应该做什么,更不用说它不应该做的事情,或者不应该做的事情.它没有注释,懒惰的名称,并且缩进了很多.

因此,您将不得不惊慌失措.
We can''t.

How do you expect us to "write the corrected code in 12 hours" when your reported problem is "it''s not working properly"?

We don''t don''t even know what it is supposed to do, much less what it is doing that it shouldn''t, or not doing that it should. It''s uncommented, lazy names, and porrly indented.

So you will have to freak out.


好了,不再需要该解决方案了
Okay the solution is no longer needed


这篇关于请更正我的代码SOS!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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