中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-09-25 09:08
47,813 topics / 349,918 posts / today 0 new / 48,274 members
DOS批处理 & 脚本技术(批处理室) » Question for the experts: where is the error in this piece of VBS code???
Printable Version  962 / 11
Floor1 stornager Posted 2007-04-21 05:16
中级用户 Posts 131 Credits 328
Floor2 baomaboy Posted 2007-04-21 05:32
银牌会员 Posts 554 Credits 1,513
Floor3 slore Posted 2007-04-21 05:36
铂金会员 Posts 2,478 Credits 5,212
It's obviously a Sub
Floor4 baomaboy Posted 2007-04-21 05:38
银牌会员 Posts 554 Credits 1,513
Shadow
Floor5 stornager Posted 2007-04-21 06:41
中级用户 Posts 131 Credits 328
I tested brother baomaboy's code, but it still can't calculate the area of area2. Why is that???
Floor6 stornager Posted 2007-04-21 06:55
中级用户 Posts 131 Credits 328
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.
Floor7 stornager Posted 2007-04-21 07:10
中级用户 Posts 131 Credits 328
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!!
Floor8 slore Posted 2007-04-21 07:35
铂金会员 Posts 2,478 Credits 5,212
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
Floor9 baomaboy Posted 2007-04-21 11:09
银牌会员 Posts 554 Credits 1,513
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.
Floor10 stornager Posted 2007-04-22 04:30
中级用户 Posts 131 Credits 328
Thanks for the guidance, solar. Your code is completely correct.
Floor11 wayzbaby Posted 2007-05-30 09:22
初级用户 Posts 14 Credits 30
area1=PI*r^2
Change it to area1=PI*(r^2) and try it! There seems to be a problem with operator precedence.
Floor12 zhoushijay Posted 2007-05-30 11:17
高级用户 Posts 375 Credits 845
The format for defining the function is wrong
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023