刚学VB,这几道vb题不会做!

来源:百度知道 编辑:UC知道 时间:2024/05/17 06:22:38
1.编写程序,计算数学表达式(x+y)^2 的结果
我的程序编写是这样,可以输入,使用除了不经输入就按“结果”报错以外没有报错,就是看不见结果:
Dim n, m As Integer

Private Sub Command1_Click()
n = Text1.Text
Text1.Text = ""
p = 1
End Sub

Private Sub Command2_Click()
Dim m As Integer
m = Text1.Text
Select Case p
Case 1
Text1.Text = (n + m) ^ 2
End Select
End Sub

Private Sub Form_Load()
Command1.Caption = "连接"
Command2.Caption = "结果"
Form1.Caption = "(x+y)^2 计算器"
End Sub
2.编写程序,找出整型数据32167的最高位数字和最低位数字
还有求反运算符也看不懂
dim a1,a2,a3,a4
a1=26
a2=41
a3=true
a4=false
print not a1
print not a2
print not a3
print not a4
为什么结果却是
-21
-42
false
true
初学用的书不好,麻烦大家详细解答,谢谢!

第一 p变量没有在整个过程中定义 ,并且n没有定义类型Dim n as integer, m as integer ,p As Integer

第二 分离出每一个数,然后比较
代码如下
dim a!,b!,c!,min!,max!
a=32167
for i=1 to 5
c=mid(a,i,1)
if c>b then
min=c
else
max=c
end if
b=c
next i
第三 同第一个 三变量都没有定义 vb默认为变体类型
数字取反是二进制取反 true,false是逻辑型变量

Dim n, m As Integer

Private Sub Command1_Click()
n = Text1.Text
Text1.Text = ""
p = 1
End Sub

Private Sub Command2_Click()
Dim m As Integer
m = Text1.Text
Select Case p
Case 1
Text1.Text = (n + m) ^ 2
End Select
End Sub

n和m怎么都= Text1.Text ??

n = Text1.Text 改为
n=trim(Text1.Text )同理m = trim(Text1.Text )

把p定义为:public p as interger