`
eimhee
  • 浏览: 2152880 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论
文章列表
     如何计算给定的字符串计算表达式,如“ 1+2*3-4/5+ 6^7” 的值?笔者在使用EXCEL2002 时发现在单元格中可以输入此类表达式,输出的则是计算结果,所以写了一个函数,与大家共享。   '引用microsoft excel 10.0 object library( OR OTHER VERSION)' add a textbox and a commandbutton to form1Function result(ByVal x As String)Dim myobj As ObjectSet myobj = CreateObject("excel.sheet& ...
笔者曾写过一个递归与组合的算法(http://www.csdn.net/Develop/read_article.asp?id=23809),下面给出一个排列的递归算法,请大家指教。 Private Sub Command1_Click() ' 列出数组a 的全排列Dim a(8) As String, temp As StringFor i = 0 To 8a(i) = iNexttemp = permutation(a, UBound(a))Debug.Print tempDebug.Print "共有 " & UBound(Split(temp, vbCrLf) ...
下面实现字符串表达式计算代码由笔者收藏的本论坛代码改编,记不清是哪位网友提供的了,非常感谢。 Option ExplicitPrivate Declare Function EbExecuteLine Lib "vba6.dll" (ByVal pStringToExec As Long, ByVal Unknownn1 As Long, ByVal Unknownn2 As Long, ByVal fCheckOnly As Long) As Long Private Function ExecuteLine(sCode As String, Optional fCheck ...
       动态数组在VB语言中常能起到出奇制胜的作用。但数组有没有被重新定义或释放,用“is empty”,“is null”,“=" "”等方法都不起作用。所以判断时一般采用侦别错误消息(ON ERROR )的方法。下面给出一个非错误侦别的代码,判断动态字符串数组的分配情况:   Private Sub Command1_Click()Dim a() As String, i As Long MsgBox hasredim(a), 64, "Has a() been redimed?"   '未初始化 ReDim a(20) For i = 1 To ...
一个运用API 更改系统菜单,复制系统菜单的例子。(需要注意的是:如果要响应菜单项的单击事件,可能要用到钩子函数和更多的代码) Option Explicit Private Declare Function TrackPopupMenu Lib "user32" (ByVal hMenu As Long, ByVal wFlags As Long, ByVal x As Long, ByVal y As Long, ByVal nReserved As Long, ByVal hwnd As Long, ByVal lprc As Any) As LongPrivate D ...
       福利彩票和体育彩票近两年比较火暴,相应在VB论坛上大家讨论也较多。其实选择彩票与集合选择子集相同道理。下面给出一种VB的递归算法(虽然明知存入数组会加快运算速度,但最终也没能满意地实现,请大家多多指教。另外,效率确实不高)Option Explicit Private Sub Command1_Click() Dim temp, i As Long, starttime As Long, endtime As Longstarttime = Timertemp = cmn(22, 6)endtime = TimerOpen "d:\mofn.txt" For B ...
     一个简单的API语句可以实现更改菜单字体颜色:Private Declare Function SetSysColors Lib "user32" (ByVal nChanges As Long, lpSysColor As Long, lpColorvalues As Long) As LongPrivate Sub Form_Load()  SetSysColors 1, 7, vbRed '设置菜单字体红色(可选择 &H0 -----> &HFFFFFF 共16777216种颜色!)End Sub Private Sub Form_Unl ...
       多元一次方程往往采用循环求解。笔者在与网友们讨论一个问题(http://expert.csdn.net/Expert/topic/2607/2607772.xml?temp=.7494928)过程中,琢磨出一种算法,采用递归进行多元一次方程的求解。并将解分为整数解和 非负整数解两种情况,请大家指教。     Private Sub Command1_Click() '演示求X1+X2+X3+X4+X5=10整数解Text1.Text = ""Dim answer As Stringanswer = GETRESULT(5, 10, True) '赋值Dim te ...
       笔者在学习VB中发现利用集合可以进行排序,优化后比冒泡法快得多。下面是完整的函数代码,演示了如何进行数组的升序或降序排列。   Option ExplicitDim X(100) As DoubleDim y(100) As StringPrivate Sub Command1_Click() '演示数字排序Dim a(100) As Double, z(100) As String, i As LongFor i = 0 To 100a(i) = X(i) '复制数组z(i) = CStr(X(i)) '转化为字符串数组NextMsgBox Join(z, ",&quo ...
Global site tag (gtag.js) - Google Analytics