ZKX's LAB

vba等待并响应键盘输入 vba 键盘输入

2021-04-25知识8

excel中使用vba分别从键盘输入3个数,按其从小到大依次输出到单元格B1、B2、B3中 可以利用range的sort方法.Sub test()a=InputBox(\"请输入3个数字,各数字以空格分隔:\",\"3 2 1\")a=Split(a)With Range(\"b1:b3\")Value=Application.WorksheetFunction.Transpose(a)Sort.Cells(1),xlAscendingEnd WithEnd Sub

vba等待并响应键盘输入 Declare Function GetAsyncKeyState Lib\"user32\"(ByVal vKey As Long)As Long‘上面这句请放到程序开头处,对API函数的引用Do For Cnt=48 To 105 If GetAsyncKeyState(Cnt)。

VBA编程:从键盘输入三个整数,然后调用过程sort(),由过程sort()将这三个数从大到小进行排序, Private Sub Form6_Load(sender As Object,e As EventArgs)Handles MyBase.LoadDim a,b,c As IntegerMe.Visible=Falsea=InputBox(\"请输入第一个整数\")b=InputBox(\"请输入第二个整数\")c=InputBox(\"请输入第三个整数\")Sort(a,b,c)Me.Close()End SubPublic Sub Sort(a As Integer,b As Integer,c As Integer)Dim m As Integer=0Dim list As New List(Of Integer)list.Add(a)list.Add(b)list.Add(c)For i=0 To list.Count-1For j=i To list.Count-1If list.Item(i)(j)Thenm=list.Item(i)list.Item(i)=list.Item(j)list.Item(j)=mEnd IfNextNextMsgBox(\"从大到小排列为:\"&vbCrLf&list.Item(0)&\",\"&list.Item(1)&\",\"&list.Item(2))End Sub写的比较粗糙.

#vba 循环函数#vba 代码口诀#vba 文件操作#vba 键盘输入#vba 更新数据

随机阅读

qrcode
访问手机版