VB程序的问题
你给的那个程序能运行但输出的全部是0,怎么解决?还有能否给上程序的注释,我看不太懂。能否实现调用其他的数组来进行排序?请告诉我下。非常谢谢!
追问:有问题了。运行后没反应了
你给的那个程序能运行但输出的全部是0,怎么解决?还有能否给上程序的注释,我看不太懂。能否实现调用其他的数组来进行排序?请告诉我下。非常谢谢!
追问:有问题了。运行后没反应了
答案:解决方案如下, 注释已经详细到可以通过国标了!:
窗体放一个 Command 按钮,名称为 Command1 删掉所有代码,写下:
' ////////////////
' 先修改为你的数据结构 行列数
private const COLUME_COUNT = 4 ' 4 列
private const ROW_COUNT = 5 ' 5 行
dim ArrayData(ROW_COUNT -1 , COLUME_COUNT ) as long
' 这样定义后最高的列坐标位可以放总和
private sub Command1_Click()
' 请在这里初始化 ArrayData 二维数组内的数据
' example 把数据第一行全填 1 ,第二行填 2
dim i as long , j as long
for i =0 to ROW_COUNT -1 ' 外循环 行号
for j = 0 to COLUME_COUNT-1
ArrayData (i , j) = i +1 ' 始始化值,因为第一行全填 1 ,比数组中行号 i 要大 1
next j
next i
' 以上初始化数据完毕
call Compositor ' 调用该函数进行排序
end sub
private sub Compositor()
dim i as long , j as long
dim sumL as long
for i =0 to Row_count -1
sumL = 0
for j = 0 to colume_count -1
sumL = sumL + ArrayData( i , j)
next j
' 这样就求出了和,放在最后面位置
ArrayData (i, colume_count) = sumL
next i
' 冒泡排序算法
for i = 0 to Row_count-2
for j = i+1 to Row_count-1
if ArrayData (i, colume_count) < ArrayData( j, colume_count) then
ExchangeData i ,j ' 换位
end if
next j
next i
end sub
private sub ExchangeData(byval i as long , byval j as long ) ' 函数交换数据
dim tData as long ' 中间数据
dim k as long
for k = 0 to COLUME_COUNT
tData = ArrayData( i, k)
ArrayData( i, k) = ArrayData( j, k)
ArrayData( j, k) = tData
next k
end sub
private sub Form_DBCLick()
dim myValue as long
dim Message as string
dim Title as string
dim Default as string
dim i as long ,j as long
Message = "Enter a value between 1 and " & cstr(ROW_COUNT) ' 设置提示信息。
Title = "你要打印几行" ' 设置标题。
Default = "1" ' 设置缺省值。
' 显示信息、标题及缺省值。
MyValue = InputBox(Message, Title, Default)
if myvalue >=1 and myvalue <=ROW_COUNT then
cls ' 清屏
for i = 0 to MyValue -1
Message =vbnullstring
for j = 0 to COLUME_COUNT
Message = Message & cstr(ArrayData(i,j)) & vbtab
next j
print Message ' 打印数据
next i
else
msgbox "输入有误"
end if
end sub
上一个:VB读取txt问题
下一个:vb程序设计 求救 SOS