查看: 1600|回复: 4

[已经过期] 求助一段vb.net的代码

  [复制链接]

傻♂逼

梦石
0
星屑
374
在线时间
1606 小时
注册时间
2007-3-13
回帖
6005

烫烫烫开拓者

发表于 2010-10-20 22:28:50 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
一旦使用任何System.Math运算就直接杯具,求各种解释和安慰
  1. Imports System.CodeDom.Compiler
  2. Imports System.Math
  3. 'Public Class clsF'
  4. 'Public Function funCal() As Object'
  5. 'Dim x As Integer = 1
  6. '    Return Math.Sin(x)
  7. 'End Function
  8. 'End Class
  9. Public Class frmArrayEdit
  10.     Dim labs() As Label
  11.     Dim inps() As TextBox
  12.     Dim num As Integer
  13.     Private Sub frmArrayEdit_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

  14.     End Sub
  15.     Public Function Calculate(ByVal x As Integer, ByVal expression As String) As Object
  16.         On Error Resume Next
  17.         Dim className As String = "clsF"
  18.         Dim methodName As String = "funCal"

  19.         Dim classSource As New System.Text.StringBuilder
  20.         '  classSource.Append("Imports System.Math")
  21.         classSource.Append("public   class   " + className + vbCrLf)
  22.         classSource.Append("         public  function " + methodName + "() as object" + vbCrLf)
  23.         classSource.Append("                 Dim x As Integer = " & x & vbCrLf)
  24.         classSource.Append("                 return   " + expression + vbCrLf)
  25.         classSource.Append("         end function" + vbCrLf)
  26.         classSource.Append("end class")

  27.         Dim codeProvider As New VBCodeProvider
  28.         Dim cParams As New CompilerParameters
  29.         cParams.GenerateExecutable = False
  30.         cParams.GenerateInMemory = False
  31.         Dim cResults As CompilerResults = codeProvider.CompileAssemblyFromSource(cParams, classSource.ToString)
  32.         Dim asm As System.Reflection.Assembly = cResults.CompiledAssembly
  33.         Dim eval As Object = asm.CreateInstance(className)
  34.         Dim method As System.Reflection.MethodInfo = eval.GetType().GetMethod(methodName)
  35.         Dim args() As String = Nothing
  36.         Dim reObj As Object = method.Invoke(eval, args)

  37.         GC.Collect()
  38.         Return reObj
  39.     End Function
  40.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  41.         Dim onum As Integer = num

  42.         num = TextBox1.Text
  43.         If num < onum Then
  44.             For i = num + 1 To onum
  45.                 labs(i).Dispose()
  46.                 inps(i).Dispose()
  47.             Next
  48.             ReDim Preserve labs(TextBox1.Text)
  49.             ReDim Preserve inps(TextBox1.Text)
  50.         Else
  51.             If num > onum Then
  52.                 ReDim Preserve labs(TextBox1.Text)
  53.                 ReDim Preserve inps(TextBox1.Text)
  54.                 For i = onum + 1 To num
  55.                     labs(i) = New Label
  56.                     inps(i) = New TextBox
  57.                     ' labs(i).Width =
  58.                     labs(i).AutoSize = True
  59.                     labs(i).Text = i
  60.                     'labs(i).AutoSize = False
  61.                     If labs(i).Font.SizeInPoints < 32 Then
  62.                         labs(i).AutoSize = False
  63.                         labs(i).Width = 32
  64.                     End If
  65.                     labs(i).TextAlign = ContentAlignment.MiddleCenter

  66.                     labs(i).Parent = Panel1
  67.                     labs(i).Left = labs(i - 1).Left + labs(i - 1).Width
  68.                     labs(i).Show()
  69.                     ''''
  70.                     inps(i).Width = labs(i).Width
  71.                     inps(i).Top = labs(i).Height
  72.                     ' labs(i).Text = i
  73.                     inps(i).Parent = Panel1
  74.                     inps(i).Left = inps(i - 1).Right
  75.                     inps(i).Show()
  76.                 Next
  77.             End If
  78.         End If

  79.     End Sub
  80.     Public Sub buit()
  81.         num = 1
  82.         TextBox1.Text = 1
  83.         ReDim Preserve labs(TextBox1.Text)
  84.         ReDim Preserve inps(TextBox1.Text)
  85.         For i = 1 To num
  86.             labs(i) = New Label
  87.             inps(i) = New TextBox
  88.             ' labs(i).Width =
  89.             labs(i).AutoSize = True
  90.             'labs(i).AutoSize = False
  91.             labs(i).Text = i
  92.             If labs(i).Font.SizeInPoints Then
  93.                 labs(i).AutoSize = False
  94.                 labs(i).Width = 32
  95.             End If
  96.             labs(i).TextAlign = ContentAlignment.MiddleCenter

  97.             labs(i).Parent = Panel1
  98.             labs(i).Left = 0 'labs(i - 1).Left + labs(i - 1).Width
  99.             labs(i).Show()
  100.             ''''
  101.             inps(i).Width = labs(i).Width
  102.             inps(i).Top = labs(i).Height
  103.             ' labs(i).Text = i
  104.             inps(i).Parent = Panel1
  105.             inps(i).Left = 0 'inps(i - 1).Right
  106.             inps(i).Show()
  107.         Next
  108.     End Sub

  109.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  110.         Dim ss As String
  111.         ss = InputBox("F(x)=?", "AutoFinnish")
  112.         For i = 1 To num
  113.             inps(i).Text = Calculate(i, ss)
  114.         Next
  115.     End Sub
  116. End Class

复制代码

评分

参与人数 1星屑 +2 收起 理由
graykid + 2

查看全部评分

梦石
0
星屑
50
在线时间
462 小时
注册时间
2007-7-30
回帖
605
发表于 2010-10-20 22:33:08 | 显示全部楼层
表示不懂VB...路过 沙发~
RGE这万年大坑 啥时填起来@@

回复

使用道具 举报

头像被屏蔽
梦石
0
星屑
50
在线时间
89 小时
注册时间
2009-10-26
回帖
700
发表于 2010-10-20 22:46:03 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
回复

使用道具 举报

梦石
0
星屑
140
在线时间
0 小时
注册时间
2010-10-21
回帖
4
发表于 2010-10-21 10:45:01 | 显示全部楼层
不错哦,顶你!睡觉了.明天要上班.
回复

使用道具 举报

梦石
0
星屑
67676
在线时间
269 小时
注册时间
2010-6-16
回帖
878
发表于 2010-10-21 12:33:07 | 显示全部楼层
LS马嘴了
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部