[VB]输入一个合法的3位正整数,测试其数值合法性后,逆序输出并显示,例如,输入"734",输出是"437",如图1所示

供稿:hz-xin.com     日期:2025-01-16
VB编程:输入一合法的3位正整数,先后逆序输出并显示。如:输入“128”,输出“821”



注意只是用第一行第一列的单元格说明,代码如下:
Private Sub CommandButton1_Click()Dim i As IntegerDim s As String s = ActiveSheet.Cells(1, 1) If IsNumeric(s) = True Then s = StrReverse(s) MsgBox s '或者 ActiveSheet.Cells(1, 1)= s Else MsgBox "Is not Numeric" End IfEnd Sub

dim i as integer
dim g,s,b
i=text1.text
g=i mod 10
s=(i mod 100)\10
b=i \ 100
text2.text= g & s & b

假如:输入数字的 TextBox 控件名称为 txtNum1,输出用 TextBox 的名称为 txtNum2

1、判断 txtNum1 是否为数字的程序如下
If Trim(txtNum1) = "" Then Exit Sub
If Not IsNumeric(txtNum1) Then
MsgBox "请输入数字!"
txtNum1.SetFocus
End If

2、实现逆序的程序如下
Dim maxNum As Long
Dim i As Long

Dim strN1 As String
Dim strN2 As String

maxNum = Len(Trim(txtNum1))
strN1 = Str(Trim(txtNum1))
For i = maxNum + 1 To 2 Step -1
strN2 = strN2 + Mid$(strN1, i, 1)
Next
txtNum2 = strN2
在实现“逆序”程序中,我是把输入内容按字符串进行处理的,原因主要是
(1)、不知道输入数字长度的大小,
(2)、如果数字最后一位是0的话,也能明确看到结果。

3、如果你确定输入是三位数字的话,直接转换:
txtNum2 = (txtNum1 Mod 10) * 100 + ((txtNum1 Mod 100) \ 10) * 10 + (txtNum1 \ 100)

希望对你有参考价值...

(1)if keycode=13 then
if isnumeric(text1.text)=true then

if val(text1.text)<100 or val(text1.text)>999 then

msgbox "你输入的整数不合法 100-999"

exit sub

else

msgbox "输入合法"

end if

end if
(2)
Private Sub Command1_Click()
Dim a As Integer, b As Integer, c As Integer
Dim i As Integer, j As String
i = 100 + Int(Rnd * 900)
a = Int(i / 100)
b = i Mod 100
c = b Mod 10
b = Int(b / 10)
j = c & b & a
MsgBox i & "," & j

End Sub

[VB]输入一个合法的3位正整数,测试其数值合法性后,逆序输出并显示,例 ...
MsgBox "请输入数字!"txtNum1.SetFocus End If 2、实现逆序的程序如下 Dim maxNum As Long Dim i As Long Dim strN1 As String Dim strN2 As String maxNum = Len(Trim(txtNum1))strN1 = Str(Trim(txtNum1))For i = maxNum + 1 To 2 Step -1 strN2 = strN2 + Mid$(strN1, ...

VB编程:输入一合法的3位正整数,先后逆序输出并显示。如:输入“128...
1) If IsNumeric(s) = True Then s = StrReverse(s) MsgBox s '或者 ActiveSheet.Cells(1, 1)= s Else MsgBox "Is not Numeric" End IfEnd Sub

vb题目:输入一个三位正整数,输出其个,十,百位数字。。
labResult.Caption = "个位数据为:" + Left(txtNumbers.Text, 1) + "十位数据为:" + Mid(txtNumbers.Text, 2, 1) + "百位数据为:" + Right(txtNumbers.Text, 1)End Sub

输入一个三位的正整数,反向输出,如输入123,输出321。
include<stdio.h>void main(){ int a,b; scanf("%d",&a); b=a\/100+((a%100)\/10)*10+((a%100)%10)*100; printf("%d",b);}

从键盘上任意输入一个3位正整数,正确分离出的个、十、百位数,并分别在...
我个简单,用求余和取整运算就可以得了,程序是:input "输入一个3位正整数:"to n ?"个位数字是:“,n%10 ?"十位数字是:",int(n\/10)%10 ?"百位数字是:",int(n\/100)

vb编程实现:随机产生一个3位正整数,逆序输出。
Private Sub Form_Load()Dim i As Integer Dim temp As Integer Dim result As String Randomize For i = 1 To 3 temp = Rnd * 10 If temp = 10 Then temp = 1 result = result & Trim(Str(temp))Next Print "随机数:" & result Print "反转后:" & StrReverse(result)End Sub ...

VB :由键盘输入3个正整数,求出这3个数的最小公倍数。
)Dim a, b, c As Integer a = InputBox("输入第一个数")b = InputBox("输入第儿个数")c = InputBox("输入第三个数")For i = 1 To a * b * c If i Mod a = 0 And i Mod b = 0 And i Mod c = 0 Then Exit For Next i MsgBox "最小公倍数为" & i End Sub ...

vb如何随机生成一个三位正整数,单击窗体,分别输出其百位、十位和个位...
Private Sub Form_Click()Dim x As Integer Randomize x = Int(Rnd * 900) + 100 MsgBox "随机生成的三位正整数是" & x & vbCrLf & "百位数是" & x \\ 100 & vbCrLf & "十位数是" & x \\ 10 Mod 10 & vbCrLf & "个位数是" & x Mod 10 End Sub ...

VB 随机产生一个三位正整数,然后逆序输出,产生的数与逆序数同时显示_百 ...
num = Int((999 - 100 + 1) * Rnd + 100)For i = Len(num) To 1 Step -1 num1 = num1 & Mid(num, i, 1)Next Print "原始:" & num; "变换" & num1

从键盘上任意输入一个3位正整数,正确分离出的个、十、百位数,并分别在...
比如你输入的是321 321%100=21 用321-(321%100)再除以100即可得:(321-(321%100))100=3 同样,用21%10=1再除以10即可得:((321%100)-((321%100)%10))\/10=2 最后,1-(1%1)=1 VF程序应用介绍:本课程主要内容包括:数据库技术基础、VisualFoxPro的基本知识(包括安装、启动、...