![]() |
购物专题 | 基金专题 | 性专题 | 饮食专题 | 教育专题 | 生活大参考 | 园林资讯 | 园艺库 | 健康专题 | |
| 论文专题 | 家庭养花 | 园林景观 | 盆景奇石 | 激情图库 | 农业资料库 | 园林古建 | 英文站 | 花卉栽培 |
发现很多人有一个习惯,就是很不喜欢用空格和缩进、比如:
strsql="update class set classx=’"&classx&"’,orderx="&orderx&",default="&default&",openmode="&openmode
if classurl<>"" then
strsql=strsql&",classurl=’"&classurl&"’"
end if
strsql=strsql&" where id="&id
==================================
这样的代码别人根本无法看懂,而且,如果&后面出现H字符就会出错!
给大家一个建议:
1、使用变量之前先用Dim定义
2、尽量取一些有意义的变量名
3、不要用拼音首字母的缩写作为变量名
4、注意缩进
5、较长的代码可以加入适量的注释或者分段
6、在+-*/&=<>等运算符前后加上一个空格
7、...............顺便散分,技术分
---------------------------------------------------------------
严重同意,好的习惯让维护代码和移交非常方便
3、不要用拼音首字母的缩写作为变量名
最好用vbs约定的变量命名规范
String 用 str前缀,例如:strName
Integer 用 int或lng前缀,例如:intStatus
Double 用 dbl前缀,例如:dblPay
Object 用 obj前缀,例如:objPtr
Class 用 cls前缀,例如:clsPtr
不多列举了,vbs帮助手册里有特别说明
---------------------------------------------------------------
而且,应该多加些注释,时间久了,代码长了,或许到时候自己都看不懂自己的代码了
尽可能使用函数或封装成类,将功能分成各个模块,而不是将代码全部堆砌在一个文件里。
--------------------------------
对写sql语句的建议
dim strSql;
strSql = "select columnName "
& "from tableName "
& "where columnaName=’"&value&"’ "
& "order by columnName"
这点也应该提倡....
实际中不仅仅是这一点...
--------------------------------
补充一个:
区分大小写的代码比全部小写的代码容易看懂,容易维护,还是上面的例子:
strsql="update class set classx=’"&classx&"’,orderx="&orderx&",default="&default&",openmode="&openmode
if classurl<>"" then
strsql=strsql&",classurl=’"&classurl&"’"
end if
strsql=strsql&" where id="&id
==================
strSql="UPDATE [Class] SET ClassX=’" & ClassX & "’,OrderX=" & OrderX & _
",[Default]=" & Default & ",OpenMode=" & OpenMode"
If ClassURL<>"" Then
strSql= strSql & ",ClassURL=’" & ClassURL & "’"
End If
strSql=strSql & " WHERE [ID]=" & ID
========================================
建议加一条: 在文件开头加上 <%Option Explicit%>, 逼你减少很大部分的错误.
浙ICP备 :07003766号 Copyright © 2001-2007 JUBAO163,All rights reserved. |