Beruflich Dokumente
Kultur Dokumente
dim i as long
with draw1
'graph is a pie chart
.graphtype = dgtpie
new chart
subroutine printflexgridrows prints rows in the flexgrid. if there are too many
columns to fit on a single page, it prints multiple pages arranged horizontally.
it starts at row start_row and leaves start_row pointing to the next row to print
when it is done.
the routine loops through the rows starting with start_row to see how tall they
are and determine how many rows will fit on a page.
' print the horizontal pages for the next set of rows that
' will
' fit on a page vertically. start with row start_row.
' leave start_row pointing to the first row after those
' printed.
private sub printflexgridrows(byval flx as msflexgrid, _
byref start_row as integer, byval l_margin as single, _
byval t_margin as single, byval r_margin as single, _
byval b_margin as single, byval page_x as single, byval _
page_y as single, byval page_r as integer)
dim ymax as single
dim c as integer
dim stop_row as integer
dim page_c as integer
with flxdata
' see which rows will fit on this page.
' start with the first row.
stop_row = start_row
ymax = t_margin + .rowheight(stop_row) + 2 * vgap
do
if stop_row + 1 >= .rows then exit do
if ymax + .rowheight(stop_row + 1) + 2 * vgap > _
b_margin then exit do
ymax = ymax + .rowheight(stop_row + 1) + 2 * _
vgap
stop_row = stop_row + 1
loop
' print the horizontal pages for the rows start_row through
' stop_row
' starting with column start_col.
' leave start_col pointing to the first column after those
' printed.
private sub printflexgridrowcolumns(byval flx as _
msflexgrid, byval start_row as integer, byval stop_row _
as integer, byref start_col as integer, byval l_margin _
as single, byval t_margin as single, byval r_margin as _
single, byval b_margin as single, byval page_x as _
single, byval page_y as single, byval page_r as _
integer, byval page_c as integer)
dim xmax as single
dim ymax as single
dim r as integer
dim c as integer
dim stop_col as integer
dim x as single
dim y as single
dim page_txt as string
with flxdata
' see which columns will fit on this page.
' start with the first column.
stop_col = start_col
xmax = l_margin + .colwidth(stop_col) + 2 * hgap
do
if stop_col + 1 >= .cols then exit do
if xmax + .colwidth(stop_col + 1) + 2 * hgap > _
r_margin then exit do
xmax = xmax + .colwidth(stop_col + 1) + 2 * hgap
stop_col = stop_col + 1
loop
x = l_margin
for c = start_col to stop_col
'(debug) printer.line (x, t_margin)-step(60,
' 60), , b
printer.line (x, t_margin)-(x, ymax)
x = x + .colwidth(c) + 2 * hgap
next c
printer.line (x, t_margin)-(x, ymax)
end with
dim irow as integer ' index variable for the current row
dim icol as integer ' index variable for the current row
' insert random data into cells for the two series:
randomize now()
for irow = 1 to cnumrows
for icol = 1 to cnumcols
atemp(irow, icol) = int(rnd * 50) + 1
next icol
next irow
osheet.range("a1").resize(cnumrows, cnumcols).value = atemp
oxl.usercontrol = true
end sub
upperleftcell = activecell.address
numbpoints = 20
redim data(numbpoints - 1)
for i = 0 to numbpoints - 1
data(i) = i + 1
next i
redim data(numbpoints - 1, 0)
for i = 0 to numbpoints - 1
data(i, 0) = i + 1
next i
charts.add
activechart.charttype = xllinemarkers
activechart.setsourcedata source:=sheets("sheet1").range("a1:a20")
activechart.location where:=xllocationasobject, name:="sheet1"
for more flexibility, set the source of the graph to a variable rather than a
string. use the range of the data on the worksheet. this allows you to change the
graph data in code. in the code below, on the right hand side of the equation, the
term range(upperleftcell) represents the upper left cell, and the term
range(upperleftcell).offset(numbpoints, 0) represents the lower right cell of the
outer range.
upperleftcell = "a1"
numbpoints = 50
' put the data on the active sheet (one column)
set datarange = range(range(upperleftcell), range(upperleftcell)._
offset(numbpoints-1, 0))
datarange.value = data
sheetname = activesheet.name
charts.add
with activechart
.hastitle = true
.charttitle.characters.text = "my chart"
.charttype = xllinemarkers
.setsourcedata source:=datarange, plotby:=xlcolumns
.location where:=xllocationasobject, name:=sheetname
end with
sub normno()
iteration = range("c4").value
mean = range("c5").value
sd = range("c6").value
alpha = range("c3").value
redim arr(iteration) as single
for i = 1 to iteration
arr(i) = gauss * sd + mean
cells(6, 6) = i
next i
end sub
'***********************************************************************
'* return random numbers from standard normal distribution *
'***********************************************************************
function gauss()
10 v1 = 2 * rnd - 1
v2 = 2 * rnd - 1
r = v1 ^ 2 + v2 ^ 2
if (r >= 1) then goto 10
fac = sqr(-2 * log(r) / r)
gauss = v2 * fac
end function
'**********************************************************************
'* sort the numbers generated
*
'**********************************************************************
for j = 2 to n
temp = arr(j)
for i = j - 1 to 1 step -1
if (arr(i) <= temp) then goto 10
arr(i + 1) = arr(i)
next i
i = 0
10 arr(i + 1) = temp
next j
end sub
'********************************************************************
'* construct historgram distribution
*
'********************************************************************
for i = 1 to m
freq(i) = 0
next i
for i = 1 to n
if (arr(i) <= breaks(1)) then freq(1) = freq(1) + 1
if (arr(i) >= breaks(m - 1)) then freq(m) = freq(m) + 1
for j = 2 to m - 1
if (arr(i) > breaks(j - 1) and arr(i) <= breaks(j)) then freq(j) =
freq(j) + 1
next j
next i
for i = 1 to m
cells(i + 2, 8) = breaks(i)
cells(i + 2, 9) = freq(i)
next i
end sub
(1)
(3)
'create a recordset from all the records in the orders table
dim snwind as string
dim conn as new adodb.connection
dim rs as adodb.recordset
snwind = _
"c:\program files\microsoft office\office\samples\northwind.mdb"
conn.open "provider=microsoft.jet.oledb.4.0;data source=" & _
snwind & ";"
conn.cursorlocation = aduseclient
set rs = conn.execute("orders", , adcmdtable)
(4)
'create a new workbook in excel
dim oexcel as object
dim obook as object
dim osheet as object
set oexcel = createobject("excel.application")
set obook = oexcel.workbooks.add
set osheet = obook.worksheets(1)
clipboard.settext sdata
(7)
'create a new instance of excel
dim oexcel as object
dim obook as object
dim osheet as object
set oexcel = createobject("excel.application")
(8)
'create a new connection object for book1.xls
dim conn as new adodb.connection
conn.open "provider=microsoft.jet.oledb.4.0;" & _
"data source=c:\book1.xls;extended properties=excel 8.0;"
conn.execute "insert into mytable (firstname, lastname)" & _
" values ('bill', 'brown')"
conn.execute "insert into mytable (firstname, lastname)" & _
" values ('joe', 'thomas')"
conn.close
(10)
'initiate a dde communication with excel
text1.linkmode = 0
text1.linktopic = "excel|mybook.xls"
text1.linkitem = "r1c1:r2c3"
text1.linkmode = 1
'poke the text in text1 to the r1c1:r2c3 in mybook.xls
text1.text = "one" & vbtab & "two" & vbtab & "three" & vbcr & _
"four" & vbtab & "five" & vbtab & "six"
text1.linkpoke
'execute commands to select cell a1 (same as r1c1) and change the font
'format
text1.linkexecute "[select(""r1c1"")]"
text1.linkexecute "[font.properties(""times new roman"",""bold"",10)]"
class randomtest {
from this program. if you run it your results should be slightly different. after
all this is supposed to be random. these results are pretty much what you would
expect from a reasonably random generator. if you have a fast cpu and some time to
spare, try bringing the number of tests up to a billion or so, and see if the
counts for the different digits get any closer to each other.
with m_rsdata
.open strsql, oradb
redim strname(.fields.count) as string
'this gives titles in a down fashion.
'to go across, one must go b1,c1,d1 for which i do not have a loop
for iloop=1 to .fields.count-1
xlsheet.range("b" & .fields(iloop).name & ).cells=.fields(iloop).name
next iloop
intheight = 5
while not .eof
xlsheet.range("b" & intheight).cells =
format$(.fields("some_date"), "ddd mmm d")
xlsheet.range("c" & intheight).cells = .fields(1) & " "
xlsheet.range("d" & intheight).cells = .fields(1) & " "
xlsheet.range("e" & intheight).cells = .fields(1) & " "
xlsheet.range("f" & intheight).cells = .fields(1) & " "
xlsheet.range("z" & intheight).cells = .fields(1) & " "
intheight = intheight + 1
.movenext
wend
.close
end with
for icount = 1 to 2 'the number of named ranges (which should be the number of
fields)
xlseries.add "range" & icount
xlseries.item(icount).name = strname(icount)
next icount
exit sub
curve in picture
option explicit
currentx = 3000
currenty = 100
print "y"
currentx = 5800
currenty = 2400
print "x"
end sub
5000
if msflexgrid1.mouserow = 0 or msflexgrid1.mousecol = 0 then
text4.visible = false
exit sub
else
text4.visible = false
text4.top = msflexgrid1.top + msflexgrid1.celltop
text4.left = msflexgrid1.left + msflexgrid1.cellleft
text4.width = msflexgrid1.cellwidth
text4.height = msflexgrid1.cellheight
text4.text = msflexgrid1.text
text4.visible = true
text4.setfocus
end if
msflexgrid1.text = text4.text
text1.visible = false
text1.top = msflexgrid2.top + msflexgrid2.celltop
text1.left = msflexgrid2.left + msflexgrid2.cellleft
text1.width = msflexgrid2.cellwidth
text1.height = msflexgrid2.cellheight
text1.text = msflexgrid2.text
text1.visible = true
text1.setfocus
end if
msflexgrid2.text = text1.text
form1.drawwidth = 2
for x = -1500 to 1500 step 10
y = (sin(x * pi / 1500)) * 2000
'print y
pset (xcent + x, ycent - y), rgb(0, 200, 0)
pset (xcent + x + (x / 2), ycent + y), rgb(200, 0, 0)
next x
currentx = 3100
currenty = 100
print "y"
currentx = 5800
currenty = 2400
print "x"
end sub
3003.
dim t as single
dim x0 as single
dim y0 as single
dim x1 as single
dim y1 as single
t = 0#
x1 = x(t, pt0.x, pt1.x, pt2.x, pt3.x)
y1 = y(t, pt0.y, pt1.y, pt2.y, pt3.y)
t = t + dt
do while t < 1#
x0 = x1
y0 = y1
x1 = x(t, pt0.x, pt1.x, pt2.x, pt3.x)
y1 = y(t, pt0.y, pt1.y, pt2.y, pt3.y)
pic.line (x0, y0)-(x1, y1)
t = t + dt
loop