Foxtable(狐表)用户栏目专家坐堂 → 自定义函数


  共有2717人关注过本帖树形打印复制链接

主题:自定义函数

帅哥哟,离线,有人找我吗?
lxhmax
  1楼 | QQ | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:三尾狐 帖子:632 积分:5651 威望:0 精华:0 注册:2012/8/2 19:04:00
自定义函数  发帖心情 Post By:2020/3/29 18:03:00 [只看该作者]

For Each r2 As DataRow In dt.DataRows
    Dim r3 As DataRow = DataTables("新房信息").SQLFind("房产编号 = '" & r2("房产编号") & "'")
    If r3 IsNot Nothing Then  '''新房
        a = a + 1
        wb.AppendLine("<div class='house-wrap k'>")
        wb.AppendLine("<div class='house-pic'>")
        wb.AppendLine("<img src='/New house/" & r3("项目名称") & "/" &  r3("项目名称") & "x" & ".jpg' alt='" & r3("项目名称") & "'>")
        wb.AppendLine("</div>")
        wb.AppendLine("</div>")
    Else '''二手房
        Dim r As DataRow = DataTables("房产信息").SQLFind("房产编号 = '" & r2("第八列") & "'")
        If r IsNot Nothing Then
            a = a + 1
            wb.AppendLine("<div class='house-wrap k'>")
            wb.AppendLine("<a class='house pr hor-view box' href='fyxx.htm?khbh=" & khbh & "&id=" & r("房产编号") & "' sap-expo='true'>")
            wb.AppendLine("<div class='house-info'>")
            wb.AppendLine("<p class='house-name line-clamp-1'>" & r("小区名称") & " " & r("楼层") & "</p>")
            wb.AppendLine("</a>")
            wb.AppendLine("</div>")
        End If
    End If
Next

请问老师们,这里面的红色跟蓝色内容因为在很多地方引用,有时候修改起来每个地方都要修改,我想把他放到自定义函数里,然后换成下面的格式来执行代码,请问这个自定义函数要怎么编写?

For Each r2 As DataRow In dt.DataRows
    Dim r3 As DataRow = DataTables("新房信息").SQLFind("房产编号 = '" & r2("房产编号") & "'")
    If r3 IsNot Nothing Then  '''新房
Functions.Execute("房源","新房")
    Else '''二手房
        Dim r As DataRow = DataTables("房产信息").SQLFind("房产编号 = '" & r2("房产编号") & "'")
        If r IsNot Nothing Then
Functions.Execute("房源","二手房")
        End If
    End If
Next

[此贴子已经被作者于2020/3/29 18:08:43编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
李孝春
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:九尾狐 帖子:2472 积分:17346 威望:0 精华:0 注册:2013/1/31 0:03:00
回复:(lxhmax)自定义函数  发帖心情 Post By:2020/3/29 18:27:00 [只看该作者]

你那颜色部分是页面代码吧   

在自定义函数里面去写一个完整的页面代码    


 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:107813 积分:548416 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2020/3/29 21:51:00 [只看该作者]

键2个函数

函数名称1:新房
dim 项目名称 as string =args(0)
dim wb as stringbuilder
        wb.AppendLine("<div class='house-wrap k'>")
        wb.AppendLine("<div class='house-pic'>")
        wb.AppendLine("<img src='/New house/" & 项目名称 & "/" &  项目名称 & "x" & ".jpg' alt='" & 项目名称 & "'>")
        wb.AppendLine("</div>")
        wb.AppendLine("</div>")
return wb.tostring

函数名称2:二手房
dim 房产编号 as string =args(0)
dim 小区名称 as string =args(1)
dim 楼层 as string =args(2)
dim wb as stringbuilder
            wb.AppendLine("<div class='house-wrap k'>")
            wb.AppendLine("<a class='house pr hor-view box' href='fyxx.htm?khbh=" & khbh & "&id=" & 房产编号& "' sap-expo='true'>")
            wb.AppendLine("<div class='house-info'>")
            wb.AppendLine("<p class='house-name line-clamp-1'>" & 小区名称  & " " & 楼层 & "</p>")
            wb.AppendLine("</a>")
            wb.AppendLine("</div>")
return wb.tostring

调用
For Each r2 As DataRow In dt.DataRows
    Dim r3 As DataRow = DataTables("新房信息").SQLFind("房产编号 = '" & r2("房产编号") & "'")
    If r3 IsNot Nothing Then  '''新房
wb.Append(Functions.Execute("新房",r3("项目名称")))
    Else '''二手房
        Dim r As DataRow = DataTables("房产信息").SQLFind("房产编号 = '" & r2("房产编号") & "'")
        If r IsNot Nothing Then
 wb.Append(Functions.Execute("二手房",r("房产编号"),r("小区名称"),r("楼层")))
        End If
    End If
Next

 回到顶部
帅哥哟,离线,有人找我吗?
lxhmax
  4楼 | QQ | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:三尾狐 帖子:632 积分:5651 威望:0 精华:0 注册:2012/8/2 19:04:00
自定义函数报错  发帖心情 Post By:2020/4/15 19:15:00 [只看该作者]

老师,调用下面这个函数的时候,会报错,请问下是什么情况?
wb.Append(Functions.Execute("新房",r3("项目名称")))

函数名称1:新房
dim 项目名称 as string =args(0)
dim wb as stringbuilder
msgbox(1)---------这个能正常弹出提示
        wb.AppendLine("<div class='house-wrap k'>")  ----报错
msgbox(2)---------这个提示无法弹出
        wb.AppendLine("<div class='house-pic'>")
        wb.AppendLine("<img src='/New house/" & 项目名称 & "/" &  项目名称 & "x" & ".jpg' alt='" & 项目名称 & "'>")
        wb.AppendLine("</div>")
        wb.AppendLine("</div>")
return wb.tostring

 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:107813 积分:548416 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2020/4/16 8:59:00 [只看该作者]

dim wb as new stringbuilder

 回到顶部