China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-07-23 21:03
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Question for the experts: where is the error in this piece of VBS code??? View 854 Replies 11
Original Poster Posted 2007-04-21 05:16 ·  中国 湖北 武汉 电信
中级用户
★★
scriptlover
Credits 328
Posts 131
Joined 2007-03-25 22:17
19-year member
UID 82910
Gender Male
Status Offline
Floor 2 Posted 2007-04-21 05:32 ·  中国 河北 保定 联通
银牌会员
★★★
Credits 1,513
Posts 554
Joined 2005-12-30 00:50
20-year member
UID 48180
Gender Male
Status Offline
Floor 3 Posted 2007-04-21 05:36 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
It's obviously a Sub
Floor 4 Posted 2007-04-21 05:38 ·  中国 河北 保定 联通
银牌会员
★★★
Credits 1,513
Posts 554
Joined 2005-12-30 00:50
20-year member
UID 48180
Gender Male
Status Offline
Floor 5 Posted 2007-04-21 06:41 ·  中国 湖北 武汉 电信
中级用户
★★
scriptlover
Credits 328
Posts 131
Joined 2007-03-25 22:17
19-year member
UID 82910
Gender Male
Status Offline
I tested brother baomaboy's code, but it still can't calculate the area of area2. Why is that???
Floor 6 Posted 2007-04-21 06:55 ·  中国 湖北 武汉 电信
中级用户
★★
scriptlover
Credits 328
Posts 131
Joined 2007-03-25 22:17
19-year member
UID 82910
Gender Male
Status Offline
I'm really learning VBS, and I've just started, so it's inevitable that I make mistakes. Please give me lots of guidance, slore.
Floor 7 Posted 2007-04-21 07:10 ·  中国 湖北 武汉 电信
中级用户
★★
scriptlover
Credits 328
Posts 131
Joined 2007-03-25 22:17
19-year member
UID 82910
Gender Male
Status Offline
Option Explicit
Dim r
Const PI=3.14
r=Inputbox("Please enter a num.")
Function area1()
area1=PI*r^2
Msgbox(area1)
Exit Function
PI=3.1415
Call area1()
area1=PI*r^2
Msgbox(area2)
Exit Function
End function
I modified it like this. There are no errors at all when running it, but I still can't get the values of area1 and area2. Please have a VBS expert explain!!
Floor 8 Posted 2007-04-21 07:35 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
Your code is a complete mess. Could you first look at the proper format for defining custom functions?

Option Explicit
Dim r
r=Inputbox("Please enter a num.")

area1
area2

Function area1()
area1=3.14*r*r
Msgbox area1
End Function

Function area2()
area2=3.1415*r*r
Msgbox area2
End Function
Floor 9 Posted 2007-04-21 11:09 ·  中国 河北 保定 联通
银牌会员
★★★
Credits 1,513
Posts 554
Joined 2005-12-30 00:50
20-year member
UID 48180
Gender Male
Status Offline
Originally posted by stornager at 2007-4-21 06:41:
I tested brother baomaboy's code, but it still can't calculate the area of area2. Why is that???


Hehe, it works fine here. Not sure whether it's your problem or your computer's problem.
Floor 10 Posted 2007-04-22 04:30 ·  中国 湖北 武汉 电信
中级用户
★★
scriptlover
Credits 328
Posts 131
Joined 2007-03-25 22:17
19-year member
UID 82910
Gender Male
Status Offline
Thanks for the guidance, solar. Your code is completely correct.
Floor 11 Posted 2007-05-30 09:22 ·  中国 江苏 泰州 电信
初级用户
Credits 30
Posts 14
Joined 2006-01-10 16:39
20-year member
UID 48757
Status Offline
area1=PI*r^2
Change it to area1=PI*(r^2) and try it! There seems to be a problem with operator precedence.
Floor 12 Posted 2007-05-30 11:17 ·  中国 新疆 乌鲁木齐 电信
高级用户
★★★
Autowalk
Credits 845
Posts 375
Joined 2007-03-03 01:58
19-year member
UID 80606
Gender Male
Status Offline
The format for defining the function is wrong
你好,脚本专家!
<a target=blank href=tencent://message/?uin=29654761&Site=www.111.com&Menu=yes><img border="0" SRC=http://wpa.qq.com/pa?p=1:29654761:5 alt="点击这里给我发消息"></a>
Forum Jump: