以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助] 执行长代码  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=129131)

--  作者:zcgmxf
--  发布时间:2018/12/22 9:57:00
--  [求助] 执行长代码
老师,是否可以将一段代码定义为字符串,然后去执行。如果可以改如何处理?谢谢!

        rt1.Cells(t1+tt1+45,0).SpanCols = 10
        rt1.Cells(t1+tt1+45,0).Text = "神经系统常规检查"
        rt1.Rows(t1+tt1+45).Height = 9
        rt1.Rows(t1+tt1+45).Style.BackColor = Color.OliveDrab
        rt1.Cells(t1+tt1+45,0).Style.TextAlignHorz = prt.AlignHorzEnum.Center
        rt1.Cells(t1+tt1+45,0).Style.TextAlignVert = prt.AlignVertEnum.Center
        rt1.Cells(t1+tt1+45,0).Style.Font = New Font("宋体", 12, FontStyle.Bold)
        rt1.Rows(t1+tt1+45).Style.GridLines.top = New Prt.LineDef(0.1, Color.Gray)

    Dim s9 As String 
    s9 = " rt1.Cells(t1+tt1+45,0).SpanCols" & " = " & "10" & _
        "rt1.Cells(t1+tt1+45,0).Text" & " = " & "神经系统常规检查" & _
        "rt1.Rows(t1+tt1+45).Height" & " = " & "9" & _
        "rt1.Rows(t1+tt1+45).Style.BackColor = Color.OliveDrab " & _
        "rt1.Cells(t1+tt1+45,0).Style.TextAlignHorz = prt.AlignHorzEnum.Center " & _
        "rt1.Cells(t1+tt1+45,0).Style.TextAlignVert = prt.AlignVertEnum.Center" & _
        "rt1.Cells(t1+tt1+45,0).Style.Font" & " = " & "New Font( " & "宋体" & "," & " 12, FontStyle.Bold) " & _
        "rt1.Rows(t1+tt1+45).Style.GridLines.top" & " = " & "New Prt.LineDef(" & "_0.1" & "," & " Color.Gray" & ")" 
    If s.Contains("神经系统常规") Then
       s9  ‘ 执行上面的那段代码,这里改如何写代码
    end if

--  作者:有点蓝
--  发布时间:2018/12/22 10:13:00
--  
参考:http://www.foxtable.com/webhelp/scr/1487.htm
--  作者:zcgmxf
--  发布时间:2018/12/23 8:42:00
--  
老师,我有如下一段代码,通过调用  sjxt2 将其还原 。水平有限,请指教。谢谢!

在命令窗口执行   output.Show(Functions.Execute("sjxt2"))  显示已经还原,还原后的代码没有在该处执行。
函数 sjxt2
函数代码:
Dim Code As String 
Code = "rt1.Cells(t1+tt1+46,0).SpanCols = 10" & vbcrlf
Code = Code & " Dim ra14 As prt.RenderArea" & vbcrlf
Code = Code & "ra14 = rt1.Cells(t1+tt1+46,0).Area" & vbcrlf
Code = Code & "Dim rx19 As New prt.RenderText" & vbcrlf
Code = Code & "rx19.Text = ""意识和精神状态:""" & vbcrlf
Code = Code & "rx19.Style.Font" & " =" & " New Font(" & """宋体""" & "," & " 12," & " FontStyle.Bold" & ")" & vbcrlf
Code = Code & "rx19.x = ""0""" & vbcrlf
Code = Code & "rx19.y = ""2""" & vbcrlf
Code = Code & "ra14.Children.Add(rx19)" & vbcrlf
Code = Code & "Dim rx20 As New prt.RenderText" & vbcrlf
Code = Code & "rx20.Text" & " = " & "r(" & """神经系统_意识和精神状态""" & ")" & vbcrlf
Code = Code & "rx20.x = ""35""" & vbcrlf
Code = Code & "rx20.y = ""2""" & vbcrlf
Code = Code & "ra14.Children.Add(rx20)"
Return Code


还原成下面的代码,并且在该位置继续执行代码:
rt1.Cells(t1+tt1+46,0).SpanCols = 10
 Dim ra14 As prt.RenderArea
ra14 = rt1.Cells(t1+tt1+46,0).Area
Dim rx19 As New prt.RenderText
rx19.Text = "意识和精神状态:"
rx19.Style.Font = New Font("宋体", 12, FontStyle.Bold)
rx19.x = "0"
rx19.y = "2"
ra14.Children.Add(rx19)
Dim rx20 As New prt.RenderText
rx20.Text = r("神经系统_浅感觉")
rx20.x = "35"
rx20.y = "2"
ra14.Children.Add(rx20)

[此贴子已经被作者于2018/12/23 9:13:59编辑过]

--  作者:有点甜
--  发布时间:2018/12/23 9:44:00
--  

看看

 

Dim Code As String
Code = "dim a as string = args(0)" &  vbcrlf
Code = Code & "Dim ifo As new FileInfo(a) " & vbcrlf
Code = Code & "dim qsnd = ifo.Name.replace(ifo.Extension,nothing)" & vbcrlf
code = code & "return qsnd"


Output.Show(Code)
Functions.remove("qsnd10")
Functions.Add("qsnd10",Code)
Functions.Complie()

Dim s = Functions.Execute("qsnd10", "d:\\test.jpg")
msgbox(s)


--  作者:zcgmxf
--  发布时间:2018/12/25 12:49:00
--  
老师,感觉看不懂。能否解释一下。谢谢!
--  作者:有点甜
--  发布时间:2018/12/25 12:53:00
--  

 

加上4楼的红色代码即可。