主题:请VFP编程高手阅读下列程序,帮忙解决3个疑问?
很久以前学过一点VFP,现在由于工作,需要用VFP改编一个程序,以下程序是用Foxtools V2.2反编译过来的
(顺便说一下,这是一款售电管理系统,单位设置卡被我弄丢了,重新办张卡要2000元,不想承担责任,所以
想把插入设置卡验证这一过程去掉)。以下程序有几项看不懂,请高手指点(不甚感激):
1.*!* 是什么意思?
2.很多地方开始直接用“=”(如,= power_off()),这符合语法吗?是什么意思?
3.类似“power_off()、opencom()”的函数应该是自定义的吧,但是找不到这个函数的定义程序,请问这个自定义程序在哪?
4.“do while”语法后面可以直接用“.T.”吗?表示什么意思,是不是不管什么情况都执行下面的语句?
以下是readcard1.scx中读卡命令按钮中的程序:
LOCAL CardNo
LOCAL lnTotalPower, lnUsedPower, lnRemainPower, lnNegativePower, lnLimitPower
LOCAL lcCardType
LOCAL lnCount
LOCAL lcBuff
LOCAL lnRetVal, lnAnswer, lcErrorMessage
THISFORM.txtCardNo.Value = ""
THISFORM.txtPower.Value = 0
THISFORM.txtLimitPower.Value = 0
THISFORM.txtTotalPower.Value = 0
THISFORM.txtUsedPower.Value = 0
THISFORM.txtRemainPower.Value = 0
THISFORM.txtNegativePower.Value = 0
llRetVal = .F.
DO WHILE .T.
*!* = close_com()
*!* lnRetVal = OpenCom(gnComPort)
*!* IF (lnRetVal > 0)
*!* lcErrorMessage = GetErrorMessage(lnRetVal)
*!* lnAnswer = MESSAGEBOX(lcErrorMessage, MB_RETRYCANCEL + MB_ICONQUESTION, SD_LOC)
*!* IF lnAnswer = IDRETRY
*!* LOOP
*!* ENDIF
*!* EXIT
*!* ENDIF
lnRetVal = sele_card(AT88SC102)
lnRetVal = power_on()
IF (lnRetVal > 0)
lcErrorMessage = GetErrorMessage(lnRetVal)
lnAnswer = MESSAGEBOX(lcErrorMessage, MB_RETRYCANCEL + MB_ICONQUESTION, SD_LOC)
IF lnAnswer = IDRETRY
LOOP
ENDIF
EXIT
ENDIF
lcCardType = " "
lnRetVal = rd_str(0, 2, 2, @lcCardType) && 读卡类型
IF (lnRetVal > 0)
lcErrorMessage = GetErrorMessage(lnRetVal)
lnAnswer = MESSAGEBOX(lcErrorMessage, MB_RETRYCANCEL + MB_ICONQUESTION, SD_LOC)
IF lnAnswer = IDRETRY
LOOP
ENDIF
EXIT
ENDIF
IF lcCardType<> "SZ" AND lcCardType<> "GL" AND lcCardType<> "CS" AND lcCardType<> "GD" ;
AND lcCardType<> "HB" AND lcCardType<> "CB"
MESSAGEBOX(INVALIDCARD, MB_OK + MB_ICONQUESTION, SD_LOC)
llRetVal = .F.
EXIT
ENDIF
DO CASE
CASE lcCardType = "SZ" && 设置卡
PASSWD = PASSWD_SZ
CASE lcCardType = "GL" && 管理卡
PASSWD = PASSWD_GL
CASE lcCardType = "GD" && 购电卡
PASSWD = PASSWD_GD
CASE lcCardType = "CS" && 清除卡
PASSWD = PASSWD_CS
CASE lcCardType = "HB" && 换表卡
PASSWD = PASSWD_HB
CASE lcCardType = "CB" && 抄表卡
PASSWD = PASSWD_CB
OTHER
ENDCASE
lnRetVal = chk_sc(0, 2, PASSWD) &&核对密码
IF (lnRetVal>0)
lcErrorMessage = GetErrorMessage(lnRetVal)
IF (lnRetVal = PASSWDERROR)
lcErrorMessage = lcErrorMessage + CR + passwderrormsg()
ENDIF
lnAnswer = MESSAGEBOX(lcErrorMessage, MB_RETRYCANCEL + MB_ICONQUESTION, SD_LOC)
IF lnAnswer = IDRETRY
LOOP
ENDIF
EXIT
ENDIF
llRetVal = .T.
EXIT
ENDDO
IF llRetVal
DO CASE
CASE lcCardType = "GD"
THISFORM.OpCardType.Value = 1
THISFORM.txtFuncCard.Value = ''
CardNo = SPACE(6)
lnRetVal = rd_asc(0, 4, 3, @CardNo) && 读卡号
SELECT customer
IF !SEEK(CardNo)
MESSAGEBOX(CARDNONOTEXIST, MB_OK+MB_ICONEXCLAMATION, SD_LOC)
ELSE
lcBuff = SPACE(3*2)
lnRetVal = rd_asc(1, 2, 3, @lcBuff) && 读本次购电量,限电负荷
lnPower = VAL(h_dec(SUBSTR(lcBuff, 1, 4)))
lnLimitPower = VAL(h_dec(SUBSTR(lcBuff, 5, 2)))/10
lcBuff = SPACE(16*2)
lnRetVal = rd_asc(1, 16, 16, @lcBuff) && 读本次购电量,限电负荷
*susp
IF SUBSTR(lcBuff, 1, 2) = "FF" &&未插卡
*!* WAIT WINDOW "此卡为有效卡!" NOWAIT
lnUsedPower = customer.zydl
lnRemainPower = customer.sydl
lnTotalPower = customer.gdzl
lnNegativePower = customer.bnfdl
ELSE &&已插卡
*!* WAIT WINDOW "此卡为无效卡!" NOWAIT
lnUsedPower = VAL(h_dec(SUBSTR(lcBuff, 13, 6)))/10
lnRemainPower = VAL(h_dec(SUBSTR(lcBuff, 1, 6)))/10
lnTotalPower = VAL(h_dec(SUBSTR(lcBuff, 7, 6)))/10
lnNegativePower = VAL(h_dec(SUBSTR(lcBuff, 19, 4)))/10*lnLimitPower
IF customer.bl > 0
lnUsedPower = lnUsedPower * customer.bl
lnRemainPower = lnRemainPower * customer.bl
lnNegativePower = lnNegativePower * customer.bl
lnTotalPower = lnTotalPower * customer.bl
ENDIF
ENDIF
THISFORM.txtCardNo.Value = CardNo
THISFORM.txtPower.Value = lnPower
THISFORM.txtLimitPower.Value = lnLimitPower
THISFORM.txtTotalPower.Value = lnTotalPower
THISFORM.txtUsedPower.Value = lnUsedPower
THISFORM.txtRemainPower.Value = lnRemainPower
THISFORM.txtNegativePower.Value = lnNegativePower
ENDIF
CASE lcCardType = "GL"
THISFORM.OpCardType.Value = 2
THISFORM.txtFuncCard.Value = '管理卡'
CASE lcCardType = "CS"
THISFORM.OpCardType.Value = 2
THISFORM.txtFuncCard.Value = '清除卡'
CASE lcCardType = "HB"
THISFORM.OpCardType.Value = 2
THISFORM.txtFuncCard.Value = '换表卡'
*!* susp
lcBuff = SPAC(34)
lnRetVal = rd_asc(1, 2, 17, @lcBuff)
lnUsedPower = VAL(h_dec(SUBSTR(lcBuff, 15, 6)))/10
lnRemainPower = VAL(h_dec(SUBSTR(lcBuff, 3, 6)))/10
lnTotalPower = VAL(h_dec(SUBSTR(lcBuff, 9, 6)))/10
*!* lnNegativePower = VAL(h_dec(SUBSTR(lcBuff, 21, 6)))/10*lnLimitPower
lnLimitPower = VAL(h_dec(SUBSTR(lcBuff, 27, 2)))/10
CardNo = SUBSTR(lcBuff, 29, 6)
THISFORM.txtCardNo.Value = CardNo
THISFORM.txtPower.Value = 0
THISFORM.txtLimitPower.Value = lnLimitPower
THISFORM.txtTotalPower.Value = lnTotalPower
THISFORM.txtUsedPower.Value = lnUsedPower
THISFORM.txtRemainPower.Value = lnRemainPower
THISFORM.txtNegativePower.Value = 0
CASE lcCardType = "CB"
THISFORM.OpCardType.Value = 2
THISFORM.txtFuncCard.Value = '抄表卡'
CASE lcCardType = "SZ"
THISFORM.OpCardType.Value = 2
THISFORM.txtFuncCard.Value = '设置卡'
OTHER
ENDCASE
THISFORM.Refresh
ENDIF
= power_off()
*!* = close_com()
IF llRetVal
WAIT WINDOW "读卡成功!" NOWAIT
ELSE
WAIT WINDOW "读卡失败!" NOWAIT
ENDIF
RETURN
(顺便说一下,这是一款售电管理系统,单位设置卡被我弄丢了,重新办张卡要2000元,不想承担责任,所以
想把插入设置卡验证这一过程去掉)。以下程序有几项看不懂,请高手指点(不甚感激):
1.*!* 是什么意思?
2.很多地方开始直接用“=”(如,= power_off()),这符合语法吗?是什么意思?
3.类似“power_off()、opencom()”的函数应该是自定义的吧,但是找不到这个函数的定义程序,请问这个自定义程序在哪?
4.“do while”语法后面可以直接用“.T.”吗?表示什么意思,是不是不管什么情况都执行下面的语句?
以下是readcard1.scx中读卡命令按钮中的程序:
LOCAL CardNo
LOCAL lnTotalPower, lnUsedPower, lnRemainPower, lnNegativePower, lnLimitPower
LOCAL lcCardType
LOCAL lnCount
LOCAL lcBuff
LOCAL lnRetVal, lnAnswer, lcErrorMessage
THISFORM.txtCardNo.Value = ""
THISFORM.txtPower.Value = 0
THISFORM.txtLimitPower.Value = 0
THISFORM.txtTotalPower.Value = 0
THISFORM.txtUsedPower.Value = 0
THISFORM.txtRemainPower.Value = 0
THISFORM.txtNegativePower.Value = 0
llRetVal = .F.
DO WHILE .T.
*!* = close_com()
*!* lnRetVal = OpenCom(gnComPort)
*!* IF (lnRetVal > 0)
*!* lcErrorMessage = GetErrorMessage(lnRetVal)
*!* lnAnswer = MESSAGEBOX(lcErrorMessage, MB_RETRYCANCEL + MB_ICONQUESTION, SD_LOC)
*!* IF lnAnswer = IDRETRY
*!* LOOP
*!* ENDIF
*!* EXIT
*!* ENDIF
lnRetVal = sele_card(AT88SC102)
lnRetVal = power_on()
IF (lnRetVal > 0)
lcErrorMessage = GetErrorMessage(lnRetVal)
lnAnswer = MESSAGEBOX(lcErrorMessage, MB_RETRYCANCEL + MB_ICONQUESTION, SD_LOC)
IF lnAnswer = IDRETRY
LOOP
ENDIF
EXIT
ENDIF
lcCardType = " "
lnRetVal = rd_str(0, 2, 2, @lcCardType) && 读卡类型
IF (lnRetVal > 0)
lcErrorMessage = GetErrorMessage(lnRetVal)
lnAnswer = MESSAGEBOX(lcErrorMessage, MB_RETRYCANCEL + MB_ICONQUESTION, SD_LOC)
IF lnAnswer = IDRETRY
LOOP
ENDIF
EXIT
ENDIF
IF lcCardType<> "SZ" AND lcCardType<> "GL" AND lcCardType<> "CS" AND lcCardType<> "GD" ;
AND lcCardType<> "HB" AND lcCardType<> "CB"
MESSAGEBOX(INVALIDCARD, MB_OK + MB_ICONQUESTION, SD_LOC)
llRetVal = .F.
EXIT
ENDIF
DO CASE
CASE lcCardType = "SZ" && 设置卡
PASSWD = PASSWD_SZ
CASE lcCardType = "GL" && 管理卡
PASSWD = PASSWD_GL
CASE lcCardType = "GD" && 购电卡
PASSWD = PASSWD_GD
CASE lcCardType = "CS" && 清除卡
PASSWD = PASSWD_CS
CASE lcCardType = "HB" && 换表卡
PASSWD = PASSWD_HB
CASE lcCardType = "CB" && 抄表卡
PASSWD = PASSWD_CB
OTHER
ENDCASE
lnRetVal = chk_sc(0, 2, PASSWD) &&核对密码
IF (lnRetVal>0)
lcErrorMessage = GetErrorMessage(lnRetVal)
IF (lnRetVal = PASSWDERROR)
lcErrorMessage = lcErrorMessage + CR + passwderrormsg()
ENDIF
lnAnswer = MESSAGEBOX(lcErrorMessage, MB_RETRYCANCEL + MB_ICONQUESTION, SD_LOC)
IF lnAnswer = IDRETRY
LOOP
ENDIF
EXIT
ENDIF
llRetVal = .T.
EXIT
ENDDO
IF llRetVal
DO CASE
CASE lcCardType = "GD"
THISFORM.OpCardType.Value = 1
THISFORM.txtFuncCard.Value = ''
CardNo = SPACE(6)
lnRetVal = rd_asc(0, 4, 3, @CardNo) && 读卡号
SELECT customer
IF !SEEK(CardNo)
MESSAGEBOX(CARDNONOTEXIST, MB_OK+MB_ICONEXCLAMATION, SD_LOC)
ELSE
lcBuff = SPACE(3*2)
lnRetVal = rd_asc(1, 2, 3, @lcBuff) && 读本次购电量,限电负荷
lnPower = VAL(h_dec(SUBSTR(lcBuff, 1, 4)))
lnLimitPower = VAL(h_dec(SUBSTR(lcBuff, 5, 2)))/10
lcBuff = SPACE(16*2)
lnRetVal = rd_asc(1, 16, 16, @lcBuff) && 读本次购电量,限电负荷
*susp
IF SUBSTR(lcBuff, 1, 2) = "FF" &&未插卡
*!* WAIT WINDOW "此卡为有效卡!" NOWAIT
lnUsedPower = customer.zydl
lnRemainPower = customer.sydl
lnTotalPower = customer.gdzl
lnNegativePower = customer.bnfdl
ELSE &&已插卡
*!* WAIT WINDOW "此卡为无效卡!" NOWAIT
lnUsedPower = VAL(h_dec(SUBSTR(lcBuff, 13, 6)))/10
lnRemainPower = VAL(h_dec(SUBSTR(lcBuff, 1, 6)))/10
lnTotalPower = VAL(h_dec(SUBSTR(lcBuff, 7, 6)))/10
lnNegativePower = VAL(h_dec(SUBSTR(lcBuff, 19, 4)))/10*lnLimitPower
IF customer.bl > 0
lnUsedPower = lnUsedPower * customer.bl
lnRemainPower = lnRemainPower * customer.bl
lnNegativePower = lnNegativePower * customer.bl
lnTotalPower = lnTotalPower * customer.bl
ENDIF
ENDIF
THISFORM.txtCardNo.Value = CardNo
THISFORM.txtPower.Value = lnPower
THISFORM.txtLimitPower.Value = lnLimitPower
THISFORM.txtTotalPower.Value = lnTotalPower
THISFORM.txtUsedPower.Value = lnUsedPower
THISFORM.txtRemainPower.Value = lnRemainPower
THISFORM.txtNegativePower.Value = lnNegativePower
ENDIF
CASE lcCardType = "GL"
THISFORM.OpCardType.Value = 2
THISFORM.txtFuncCard.Value = '管理卡'
CASE lcCardType = "CS"
THISFORM.OpCardType.Value = 2
THISFORM.txtFuncCard.Value = '清除卡'
CASE lcCardType = "HB"
THISFORM.OpCardType.Value = 2
THISFORM.txtFuncCard.Value = '换表卡'
*!* susp
lcBuff = SPAC(34)
lnRetVal = rd_asc(1, 2, 17, @lcBuff)
lnUsedPower = VAL(h_dec(SUBSTR(lcBuff, 15, 6)))/10
lnRemainPower = VAL(h_dec(SUBSTR(lcBuff, 3, 6)))/10
lnTotalPower = VAL(h_dec(SUBSTR(lcBuff, 9, 6)))/10
*!* lnNegativePower = VAL(h_dec(SUBSTR(lcBuff, 21, 6)))/10*lnLimitPower
lnLimitPower = VAL(h_dec(SUBSTR(lcBuff, 27, 2)))/10
CardNo = SUBSTR(lcBuff, 29, 6)
THISFORM.txtCardNo.Value = CardNo
THISFORM.txtPower.Value = 0
THISFORM.txtLimitPower.Value = lnLimitPower
THISFORM.txtTotalPower.Value = lnTotalPower
THISFORM.txtUsedPower.Value = lnUsedPower
THISFORM.txtRemainPower.Value = lnRemainPower
THISFORM.txtNegativePower.Value = 0
CASE lcCardType = "CB"
THISFORM.OpCardType.Value = 2
THISFORM.txtFuncCard.Value = '抄表卡'
CASE lcCardType = "SZ"
THISFORM.OpCardType.Value = 2
THISFORM.txtFuncCard.Value = '设置卡'
OTHER
ENDCASE
THISFORM.Refresh
ENDIF
= power_off()
*!* = close_com()
IF llRetVal
WAIT WINDOW "读卡成功!" NOWAIT
ELSE
WAIT WINDOW "读卡失败!" NOWAIT
ENDIF
RETURN