![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
VBA
northwolves
MS-VB-MVP
MS-EXCEL-MVP
展开
-
VB获得迅雷资讯弹出网页的源代码
迅雷资讯弹出网页采用UTF-8编码,需要编制自定义函数对XMLHTTP对象获得的源代码进行转换:Private Declare Function MultiByteToWideChar Lib "kernel32" (ByVal CodePage As Long, ByVal dwFlags As Long, ByVal lpMultiByteStr As Long, ByVal cc原创 2009-01-04 23:11:00 · 2911 阅读 · 0 评论 -
猴子选大王的四种VB解法
题目:一堆猴子编号依次是1,2,3 ...n ,这群猴子(n个)按照1到n的顺序围坐一圈,从第1开始报数,报双数的猴子离开此圈,这样依次下来,直到圈中只剩下最后一只猴子,则该猴子为大王。 解法: 1.集合的方法(O(2N)): Function Monkeyking(ByVal n As Long) As LongDim all As New Collection,原创 2009-02-10 15:30:00 · 2336 阅读 · 5 评论 -
Nine-digit Fractions(II)
Problem: Suppose integer A,B(A>B) and single C were satisified A/B=C and all digits(1-9) each used just once in the both sides of the equality respectively. Try to get all solutions. Answer:原创 2009-02-11 01:16:00 · 1928 阅读 · 0 评论 -
Ten-digit Fractions
Similar with another article of mine: Nine-digit FractionsProblem: Suppose integer A,B(A>B) and single C were satisified A/B=C and all digits(0-9) each used just once in the both sides of the原创 2009-02-11 13:45:00 · 5381 阅读 · 0 评论 -
Erf
ERF 返回误差函数在上下限之间的积分。如果该函数不可用,并返回错误值 #NAME?,请安装并加载“分析工具库”加载宏。 在“工具”菜单上,单击“加载宏”。 在“可用加载宏”列表中,选中“分析工具库”框,再单击“确定”。 如果必要,请遵循安装程序中的指示。 语法ERF(lower_limit,up原创 2008-12-08 14:27:00 · 1431 阅读 · 0 评论 -
Nine Digits Expression
Problem: Insert + ,-,*,/ signs as necessary in the string 123456789 to form an expression that evaluates to a certain number. Answer: Sub test() getall 2009, 1 getall 2009, 2En原创 2009-02-18 01:31:00 · 922 阅读 · 0 评论 -
Nine-digit Fractions
Problem: Suppose integer A,B(A>B) and Double C were satisified A/B=C and all digits(1-9) each used just once in the all 3 numbers(A,B,C) respectively. An example:152463798÷123456789=1.2349原创 2009-02-17 21:31:00 · 1547 阅读 · 0 评论 -
动态规划一例
题目(http://topic.csdn.net/u/20081208/16/672693a2-ce8e-462a-ba07-a70ff2f0c5a2.html?seed=2109433475):有一个蛋糕,被切成了100份,现将这个100份装到12个盘子中,要求每个盘子中的份数不能为0,并且份数中必须还有数字3,不论个位或者十位,例如13份,37份等。 请给出每个盘子中各装多少份的所有答案。原创 2008-12-08 22:45:00 · 2547 阅读 · 0 评论 -
使用动态规划解决有关数字组合的问题
题目:在SHEET2中列出SHEET1表中重量不超过170,体积不超过200的所有组合(http://club.excelhome.net/viewthread.php?tid=382466&page=1#pid2435030) Sheet1 序号重量体积1253022631327324原创 2008-12-20 13:43:00 · 1838 阅读 · 2 评论 -
Draw a cube on Excel Worksheet
A cube is Composed of two squares and two parallelograms: Sub DrawCube() ActiveSheet.Shapes.AddShape(msoShapeParallelogram, [b2].Left, [b2].Top, 4 * [b2].Width, 4 * [b2].Height).Fill.Transpar原创 2009-02-03 21:49:00 · 1411 阅读 · 0 评论 -
Multi select elements which sums upto a certain number from an array(II)
Give an array and a certain number,how to select some of the elements to sums upto the number? (Also see http://blog.csdn.net/northwolves/archive/2008/11/25/3372338.aspx)The following codes can brin原创 2009-02-03 20:49:00 · 1451 阅读 · 0 评论 -
Google Treasure Hunt 2008---Find the Smallest Prime Number
Question: Find the smallest number that can be expressed as the sum of 3 consecutive prime numbers, the sum of 11 consecutive prime numbers, the sum of 25 consecutive prime numbers, the sum of 171 con原创 2009-01-03 12:27:00 · 1045 阅读 · 0 评论 -
Largest Ten Digit Powers
The idea was Inspirated from the following link: Homogeneous Square Numbers (Provided by mathe, http://bbs.emath.ac.cn/thread-78-1-1.html) Look at the 10-digit number 9876543210,its the large原创 2009-01-11 15:39:00 · 1942 阅读 · 0 评论 -
nth prime number contain n as their substring within 100000000
A small VBA code to get these numbers: Sub Main() Dim i&, j&, k&, n&, num&, a(100000000) As Byte, p(1 To 10000000) As Long num = 1 p(num) = 2 The 1st prime n = 10原创 2009-01-11 21:27:00 · 989 阅读 · 0 评论 -
Smallest Ten Digit Powers
This is a companion piece of Largest Ten Digit Powers . The codes are almostly same,with a few changes only. Function befit(ByVal s As String, ByVal num As Long) As Boolean tell if a string原创 2009-01-11 22:41:00 · 1252 阅读 · 0 评论 -
The four number game
The Four Numbers Game is a mathematical game, as taught by Dr. Paul Sally, Prof. of Mathematics at the University of Chicago. To play this game, draw a square and put a number at each corner, thus: 5_原创 2008-11-24 20:27:00 · 834 阅读 · 0 评论 -
Multi select elements which sums upto a certain number from an array
Give an array and a certain number,how to select some of the elements to sums upto the number?The following codes can bring you one or more solutions out:Sub Solve(ByVal Total As Double, B原创 2008-11-25 19:37:00 · 1761 阅读 · 0 评论 -
随机排列n*n方阵
将n组1-n随机置于n*n的单元格中,使得每行,每列都是1-n的一个全排列 Sub Perm()Dim n As Long, i As Long, j As Long, arr(), brr(), t As Longn = 20ReDim arr(n - 1, n - 1)ReDim brr(n - 1)For i = 0 To n ^ 2 - 1arr(i原创 2008-11-25 21:51:00 · 5225 阅读 · 2 评论 -
一个九位数由1-9数字组成并前N 位被N整除
题目:请将123456789九个数字以特定的顺序排列,组成一个9位数ABCDEFGHI(每个数字只能使用一次),使得:1.第一位数字组成的整数可以被1整除2.第一、二位数字组成的整数可以被2整除3.第一、二、三位数字组成的整数可以被3整除4.第一、二、三、四位数字组成的整数可以被4整除......9.第一、二、三...九位数字组成的整数可以被9整除 分析:通常想法是遍历9!=原创 2008-11-26 19:13:00 · 8573 阅读 · 1 评论 -
Special Folders
<!-- /* Font Definitions */ @font-face {font-family:SimSun; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variab原创 2009-05-22 11:09:00 · 981 阅读 · 0 评论 -
VBA从人民银行网站获取5个币种的历史汇率信息
Sub 汇率()Dim url As String, arr, v() As String, i As Long, n As Long, p As Long, html As Stringurl = "http://www.pbc.gov.cn/huobizhengce/huobizhengcegongju/huilvzhengce/renminbihuilvjiaoyishoupanj原创 2009-11-05 21:30:00 · 3919 阅读 · 2 评论 -
VBA代码控制DTPicker控件的下拉日期表显示
DTPicker1控件的下拉按钮请问怎么写代码可以使得DTPicker控件的下拉日期表显示出来呢?!Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _(ByVal hWnd As Long, _ByVal wMsg As Long, _ByVal wParam As Long,原创 2009-11-05 21:25:00 · 6863 阅读 · 0 评论 -
整数三角形题目两则
问题1: 周长不大于n,边长为整数的三角形有多少个?解法: Function p(ByVal n As Long)周长n的三角形的个数If n Mod 2 Then n = n + 3p = Round(n ^ 2 / 48)End FunctionSub Main()Dim i As Long, cFor i = 1 To 10 ^ 6c = c +原创 2010-02-23 23:21:00 · 1684 阅读 · 0 评论 -
Continued Fraction of Squareroot
Continued Fraction can be find in http://mathworld.wolfram.com/ContinuedFraction.html Function ContinuedFraction(ByVal n As Long)Dim root As Long, p As Long, q As Long, b() As String, temp As Lo原创 2010-02-25 22:42:00 · 1378 阅读 · 1 评论 -
Fundamental Solution to Pell's Equation
From Wikipedia,Pells equationis any Diophantine equation of the formwhere n is a nonsquare integer and x and y are integers. We can calculate the x,y for certain n with the followi原创 2010-01-03 13:19:00 · 1748 阅读 · 1 评论 -
An UDF to calculate weekday
It seems feasible . Function myweekday(ByVal y As Long, ByVal m As Long, ByVal d As Long) As Long Dim bias As Long If m > 2 Then bias = m - 2 Else bias = 10 + m原创 2010-01-09 23:50:00 · 1237 阅读 · 0 评论 -
ProjectEuler 125
http://projecteuler.net/index.php?section=problems&id=125 Problem 12504 August 2006 The palindromic number 595 is interesting because it can be written as the sum of consecutive squares原创 2010-04-30 16:07:00 · 2012 阅读 · 0 评论 -
Get Integer sided triangles for which the area/perimeter ratio is integral
Problem: Consider the triangle with sides 6, 8 and 10. It can be seen that the perimeter and the area are both equal to 24. So the area/perimeter ratio is equal to 1. Consider also the原创 2010-05-04 23:19:00 · 1777 阅读 · 0 评论 -
分解质因数
分解质因数原创 2010-07-06 22:07:00 · 2612 阅读 · 2 评论 -
如何计算数据组合在全排序组合中的行值
VBA计算数据组合在全排序组合中的行值原创 2010-07-06 21:12:00 · 3071 阅读 · 2 评论 -
Select n numbers from 1 to m with all of array 'all' and none of array 'none'
How to select n numbers from 1 to m with all of array all and none of array none? Try the following codes,please. Sub getall(ByVal m As Long, ByVal n As Long, ByRef all, ByRef none) Select原创 2009-12-15 22:07:00 · 1534 阅读 · 0 评论 -
Solutions to place plus or minus signs to a non-zero digits sequence 123456789 so that result of thus described arithmetic opera
Its very easy to solve the problem,but maybe useful for elementary students. Sub getall() Dim s(300) As String, v(300) As Long, result As Long, temp As Long, x(1 To 17) As String, t, op原创 2009-12-06 21:43:00 · 1483 阅读 · 0 评论 -
An example of responseXML.getElementsByTagName
To read nodes of a certain tagname of an xml file,its easy to access: Sub Test()Dim http As Object, nod, nod2Set http = CreateObject("Microsoft.XMLHTTP")http.Open "get", "http://www.w3s原创 2009-10-27 19:24:00 · 840 阅读 · 0 评论 -
Select a table of certain webpage
Test the folowing codes,please: Sub Selecttable(ByVal url As String, ByVal n As Long) Dim t, r As Object, i As Long WebBrowser1.Navigate url, False Do While Sheet1.WebBrowser1.read原创 2009-10-27 19:34:00 · 1133 阅读 · 4 评论 -
一元多项式的幂
Function PowerPolynomial(ByVal f As String, ByVal n As Long) As String If n = 1 Then power = f: Exit Function Dim a() As Long, b, c(), s() As String, max As Long, i As Long, j As Long, k As原创 2010-01-17 14:23:00 · 1257 阅读 · 0 评论 -
一道趣味数学题(二)
123456789这九个按顺序排列的数,要求在它们之间插入若干个+,-,*,/ ,使其结果正好等于100如: 1*2*3*4+5+6+7*8+9=100 以下代码在http://blog.csdn.net/northwolves/archive/2004/07/25/51038.aspx基础上修改而成: Sub main() 开始计算getall 100getall 10原创 2009-11-20 13:23:00 · 9811 阅读 · 22 评论 -
Harmonic number sum
Problem1: Least k such that H(k) >= n, where H(k) is the harmonic number sum_{i=1..k} 1/i. Sub Harmonic_number_sum()Dim s As Double, i As Long, n As Longn = 1For i = 1 To 300000000s = s原创 2009-11-20 22:50:00 · 1360 阅读 · 0 评论 -
VB获取网页下文字的链接地址
题目: 如何获取网页下文字的链接地址 窗口有WebBrowser1,和一个Text1 现在 Private Sub Form_Load() WebBrowser1.Navigate "http://www.baidu.com" End Sub 打开窗体显示百度的首页,要求滑动鼠标到“新闻”时 Text1里显示http://news.baidu.com/ 滑动到“帖吧”时 Text1里显原创 2009-11-24 21:31:00 · 3394 阅读 · 3 评论 -
Number of sets of natural numbers less than n which sum to n.
The integer sequence was in : A111133 Seems easy. Sub Calc() Dim n As Long, count(), i As Long n = 500 ReDim count(n) count(0) = 1 For i = 1 To n For j = n To原创 2010-01-17 17:07:00 · 1567 阅读 · 0 评论 -
VBA获取新浪博客列表
Sub Blogsina() Const url As String = "http://www.google.cn/search?q=site%3Ablog.sina.com.cn/u/&num=100&start=" Dim n As Long, p As Long, s() As String, u() As String, i As Long With Cre原创 2010-01-25 16:57:00 · 2330 阅读 · 2 评论