以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  帮我看一下 哪里出错了 谢谢  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=148476)

--  作者:jswjyjf
--  发布时间:2020/4/8 19:37:00
--  帮我看一下 哪里出错了 谢谢
帮我看一下 哪里出错了 谢谢  出错说找不到cpbm  
 Dim dr As Row
    dr = Tables("货品").current
    DataTables("货品目录表").SQLDeleteFor("产品货号=\'" & dr("货号") & "\'")
    DataTables("货品目录表").RemoveFor("产品货号=\'" & dr("货号") & "\'")
    Dim nms() As String = dr("颜色").Split(",")
    Dim nms2() As String = dr("尺码").Split(",")
    For Each name As String In Nms
        For Each name2 As String In Nms2
 \'\'读取颜色和尺码的编码 用于定义产品编码
Dim dr1 As DataRow= DataTables("颜色").SQLFind("名称 =\'" & name & "\'") \'找出编号为03的产品
Dim dr2 As DataRow= DataTables("尺码").SQLFind("名称 =\'" & name2 & "\'") \'找出编号为03的产品
If dr1 IsNot Nothing And dr2 IsNot Nothing
Dim cpbm As String=dr("货号")&"-"&dr1("编码")&"-"&dr2("编码")
End If 
msgbox(cpbm)  


--  作者:有点蓝
--  发布时间:2020/4/9 9:05:00
--  
变量是有作用域的。在if里面定义的变量只能在if里面使用

Dim abc As String= xxx 在if外面定义的变量
if xxxx条件 then
   Dim cpbm As String= xxx ‘’在if里面定义的变量
msgbox(cpbm)  在if里面使用,是正确的
msgbox(abc )  在if里面使用,是正确的
end if
msgbox(cpbm)  在if外面使用,是错误的
msgbox(abc)  在if外面使用,是正确的