vb写函数的问题
Public Function between(a As Integer) As Integer
Dim b As Integer, c As Integer
If between(f, b And c) Then
f> =b and f <=c
写到 f> =b and f <=c
的时候程序提示缺少表达式
应该怎么写啊 我 是新手 大家不要笑我啊~
[解决办法]
Public Function between(f As Integer,b As Integer,c As Integer) As Integer
If f> =b and f <=c Then between=1
End Function
[解决办法]
between=1返回一个真值说明f在b和c之间,else between=0
[解决办法]
你就把between=1换成你要写的代码
他们只是举一个例子
[解决办法]
题目应该变成:
Public Function between(f As Integer,b As Integer,c As Integer) As Integer
if f 属于[b,c] then
between=1
else
between=0
end if
End Function
'下面是调用
dim x as long
f=10
b=8
c=15
if between(10,8,15)=1 then
for x= b to c
print x
next
else
print "f 不属于[B,C]范围 "
end if
[解决办法]
Public Function between(f As Integer,b As Integer,c As Integer) As Integer
if b <=f and f <=c then 'b <c
between=1
else
between=0
end if
End Function
————————————————————————————————————
写作,虽然每个人都会查阅辞海,可,不是人人都能写出不朽的篇章的。编程,如是也。
[解决办法]
实在没看明白楼主到底要什么功能的函数, 只能瞎猜一个了:
Option Explicit
Public Function Betwwen(ByVal b As Integer, ByVal c As Integer) As Integer
'功能描述: 产生一个[b,c]之间的随机整数
Dim S As Integer, L As Integer
If b < c Then
S = b
L = c
Else
S = c
L = b
End If
Betwwen = Rnd * (L - S) + S
End Function
Private Sub Form_Load()
Randomize Timer
Debug.Print Betwwen(10, 20)
Debug.Print Betwwen(10, 20)
Debug.Print Betwwen(10, 20)
End
End Sub