You are on page 1of 47

vb:

--------------------------------------------------------------------------------
flexgridcolumncolor msflexgrid1, 2, vbred
flexgridrowcolor msflexgrid1, 3, vbblue
--------------------------------------------------------------------------------

vb:
--------------------------------------------------------------------------------
public sub flexgridcolumncolor(flexgrid as msflexgrid, byval lcolumn as long,
byval lcolor as long)
dim lprevcol as long, lprevcolsel as long
dim lprevrow as long, lprevrowsel as long
dim lprevfillstyle as long

if lcolumn > flexgrid.cols - 1 then exit sub

with flexgrid

' store the current settings


lprevcol = .col
lprevrow = .row
lprevcolsel = .colsel
lprevrowsel = .rowsel
lprevfillstyle = .fillstyle

' change the backcolor


.col = lcolumn
.row = .fixedrows
.colsel = lcolumn
.rowsel = .rows - 1
.fillstyle = flexfillrepeat
.cellbackcolor = lcolor

' reset the settings


.col = lprevcol
.row = lprevrow
.colsel = lprevcolsel
.rowsel = lprevrowsel
.fillstyle = lprevfillstyle
end with
end sub

public sub flexgridrowcolor(flexgrid as msflexgrid, byval lrow as long, byval


lcolor as long)
dim lprevcol as long, lprevcolsel as long
dim lprevrow as long, lprevrowsel as long
dim lprevfillstyle as long

if lrow > flexgrid.rows - 1 then exit sub

with flexgrid

' store the current settings


lprevcol = .col
lprevrow = .row
lprevcolsel = .colsel
lprevrowsel = .rowsel
lprevfillstyle = .fillstyle

' change the backcolor


.col = .fixedcols
.row = lrow
.colsel = .cols - 1
.rowsel = lrow
.fillstyle = flexfillrepeat
.cellbackcolor = lcolor

' reset the settings


.col = lprevcol
.row = lprevrow
.colsel = lprevcolsel
.rowsel = lprevrowsel
.fillstyle = lprevfillstyle
end with
end sub
--------------------------------------------------------------------------------

flyguy
view public profile
send a private message to flyguy
find all posts by flyguy
add flyguy to your buddy list

#25 7 nov 2003, 09:24 am


flyguy
lost soul
retired moderator
* guru * join date: may 2001
location: vorlon
posts: 15,392

autoresize of columns in mshflexgrid with multiple bands

--------------------------------------------------------------------------------

vb:
--------------------------------------------------------------------------------
public function fg_autosizecols(mygrid as mshflexgrid, _
optional byval lfirstcol as long = -1, _
optional byval llastcol as long = -1, _
optional bcheckfont as boolean = false)

dim lcol as long, lrow as long, lcurcol as long, lcurrow as long


dim lcellwidth as long, lcolwidth as long
dim bfontbold as boolean
dim dfontsize as double
dim sfontname as string

if bcheckfont then
' save the forms font settings
bfontbold = me.fontbold
sfontname = me.fontname
dfontsize = me.fontsize
end if

with mygrid
.redraw = false

if bcheckfont then
lcurrow = .row
lcurcol = .col
end if

if lfirstcol = -1 then lfirstcol = 0

' special for mshflexgrid with multiple bands


if llastcol = -1 then
llastcol = 0
for i = 0 to .bands - 1
llastcol = llastcol + .cols(i)
next i
llastcol = llastcol - 1
end if

for lcol = lfirstcol to llastcol


lcolwidth = 0
if bcheckfont then .col = lcol
for lrow = 0 to .rows - 1
if bcheckfont then
.row = lrow
me.fontbold = .cellfontbold
me.fontname = .cellfontname
me.fontsize = .cellfontsize
end if
lcellwidth = me.textwidth(.textmatrix(lrow, lcol))
if lcellwidth > lcolwidth then lcolwidth = lcellwidth
next lrow
.colwidth(lcol) = lcolwidth + me.textwidth("ww")
next lcol

if bcheckfont then
.row = lcurrow
.col = lcurcol
end if

.redraw = true
end with

if bcheckfont then
' restore the forms font settings
me.fontbold = bfontbold
me.fontname = sfontname
me.fontsize = dfontsize
end if

end function
--------------------------------------------------------------------------------

flyguy
view public profile
send a private message to flyguy
find all posts by flyguy
add flyguy to your buddy list

#26 1 dec 2003, 07:04 am


flyguy
lost soul
retired moderator
* guru * join date: may 2001
location: vorlon
posts: 15,392

printing msflexgrid using sendmessage api

--------------------------------------------------------------------------------

the original code can be found on activevb.de

vb:
--------------------------------------------------------------------------------
'dieser source stammt von http://www.activevb.de
'und kann frei verwendet werden. f�r eventuelle sch�den
'wird nicht gehaftet.

'um fehler oder fragen zu kl�ren, nutzen sie bitte unser forum.
'ansonsten viel spa� und erfolg mit diesem source!

'------------- anfang projektdatei projekt1.vbp -------------


' die komponente 'microsoft flexgrid control 6.0 (sp3)
' (msflxgrd.ocx)' wird ben�tigt.
'--------- anfang formular "form1" alias form1.frm ---------

'control commandbutton: command1


'control flexgrid: msflexgrid1

option explicit

private declare function sendmessage lib "user32" alias _


"sendmessagea" (byval hwnd as long, byval wmsg as _
long, byval wparam as long, byval lparam as long) _
as long

const wm_user = &h400


const vp_formatrange = wm_user + 125
const vp_yesido = 456654

private type rect


left as long
top as long
right as long
bottom as long
end type

private type tformatrange


hdc as long
hdctarget as long
rc as rect
rcpage as rect
end type

private sub command1_click()


call printgrid(msflexgrid1, 20, 25, 20, 20, _
"activevb - flexgrid drucken �ber " & _
"vp_formatrange", "")
end sub

private sub form_load()


dim zahl%

' fill the flex with 'random' data


with msflexgrid1
.colwidth(0) = 1000
.colwidth(1) = 2000
.colwidth(2) = 2600
.colalignment(3) = 0
.colwidth(3) = 500
.colwidth(4) = 2800
.textarray(0) = "name"
.textarray(1) = "e-mail"
.textarray(2) = "homepage"
.textarray(3) = "nr."
.textarray(4) = "sonstiges"

for zahl = 1 to 9
.additem "dirk lietzow" & vbtab & "dirk@activevb.de" & _
vbtab & "www.activevb.de" & vbtab & zahl & vbtab & _
"alle f�r einen, einer f�r alle ..."
next zahl

' 1. leere zeile l�schen


.removeitem 1

' formatierungsbeispiele
.col = 2
.row = 2
.cellfontname = "arial"
.cellfontsize = 11
.col = 2
.row = 3
.cellfontname = "arial"
.cellfontsize = 12
.col = 2
.row = 4
.cellfontname = "arial"
.cellfontsize = 14
.cellfontbold = true
.rowheight(.row) = 500
.col = 2
.row = 6
.cellbackcolor = &h8000000f
.col = 2
.row = 8
.cellfontname = "courier new"
.cellfontsize = 12
.cellfontbold = true
.cellforecolor = vbwhite
.cellbackcolor = &hc00000
.rowheight(.row) = 500
end with
end sub

sub printgrid(grid as msflexgrid, byval leftmargin as single, _


byval topmargin as single, byval rightmargin as _
single, byval bottommargin as single, titel as _
string, datum as string, optional many as integer)

dim trange as tformatrange


dim lreturn as long
dim dname as string
dim dschacht as integer
dim gbeg as long
dim copycw() as long
dim gref as boolean
dim x%

gref = false
if many > 0 then
' set the number of columns to be printed
' all columns > many get a colwidth = 0
if grid.cols > many then
gbeg = grid.cols - many
redim copycw(gbeg)
grid.redraw = false
for x = many to grid.cols - 1
copycw(x - many) = grid.colwidth(x)
grid.colwidth(x) = 0
next x
gref = true
end if
end if

'with wparam <> 0 can be checked


'whether the control supports opp, if it does then the value
'456654 (vp_yesido) will be returned
lreturn = sendmessage(grid.hwnd, vp_formatrange, 1, 0)

if lreturn = vp_yesido then

' fill the trange structure


printer.scalemode = vbpixels

with trange
.hdc = printer.hdc

' height and width (in pixel)


.rcpage.right = printer.scalewidth
.rcpage.bottom = printer.scaleheight

' set the printing range in pixels


.rc.left = printer.scalex(leftmargin, vbmillimeters)
.rc.top = printer.scaley(topmargin, vbmillimeters)
.rc.right = .rcpage.right - printer.scalex(rightmargin, _
vbmillimeters)
.rc.bottom = .rcpage.bottom - printer.scaley(bottommargin, _
vbmillimeters)
end with

' initialize printer


printer.print vbnullstring

' print page (n)


do
printer.currentx = printer.scalex(leftmargin, vbmillimeters)
printer.currenty = printer.scaley(10, vbmillimeters)
if titel <> "" then printer.print titel

printer.currentx = printer.scalex(leftmargin, vbmillimeters)


printer.currenty = printer.scaley(16, vbmillimeters)

if datum <> "" then


printer.print datum
else
printer.print format(date, "dd.mm.yyyy")
end if
lreturn = sendmessage(grid.hwnd, vp_formatrange, 0, _
varptr(trange))

if lreturn < 0 then


exit do
else
printer.newpage
end if
loop
printer.enddoc

'reset
lreturn = sendmessage(grid.hwnd, vp_formatrange, 0, 0)
end if

if gref then
' reset all columns to their original width
for x = many to grid.cols - 1
grid.colwidth(x) = copycw(x - many)
next x
grid.redraw = true
end if
end sub

'---------- ende formular "form1" alias form1.frm ----------


'-------------- ende projektdatei projekt1.vbp --------------
--------------------------------------------------------------------------------

flyguy
view public profile
send a private message to flyguy
find all posts by flyguy
add flyguy to your buddy list

#27 13 jan 2004, 05:01 pm


flyguy
lost soul
retired moderator
* guru * join date: may 2001
location: vorlon
posts: 15,392

flexspread class

--------------------------------------------------------------------------------

i created a class to extend the functionality of the msflexgrid with excel like
functions.

the class supports cell editing, but you can also add formula's and expressions in
the cell.

like in excel if the text starts with a "=" then the rest of the text is parsed.

simple cell references can be used using [] -> [row,col]

i added two range functions myself: sum and avg

vb:
--------------------------------------------------------------------------------
cflexspread.textformula(4, 3) = "=sum([1,1]:[3,3])"
cflexspread.textformula(4, 3) = "=avg([1,1]:[3,3])"
--------------------------------------------------------------------------------

for all other mathematical functions i used the eval method of the scriptcontrol
which can be combined with cell references.

vb:
--------------------------------------------------------------------------------
cflexspread.textformula(4, 3) = "=[1,1] * sin([3,3]))"
--------------------------------------------------------------------------------

also added 3 events:

vb:
--------------------------------------------------------------------------------
private sub cflexspread_afteredit(row as long, col as long)
debug.print "afteredit", row, col
end sub

private sub cflexspread_beforeedit(row as long, col as long, cancel as boolean)


debug.print "before", row, col
' lock column 3
cancel = (col = 3)
end sub

private sub cflexspread_evalerror(row as long, col as long)


debug.print "evalerror", row, col
end sub
--------------------------------------------------------------------------------
attached files flexspread.zip (5.2 kb, 292 views)

--------------------------------------------------------------------------------
last edited by flyguy : 20 jan 2004 at 11:32 am.

flyguy
view public profile
send a private message to flyguy
find all posts by flyguy
add flyguy to your buddy list

#28 5 jul 2004, 05:00 pm


flyguy
lost soul
retired moderator
* guru * join date: may 2001
location: vorlon
posts: 15,392

saving / load msflexgrid settings / data

--------------------------------------------------------------------------------

another sample using a class to save / load the settings of the msflexgrid to /
from a ini style file.

it can save / load the general flexgrid settings, the general layout, the cell
data and the layout of the cells.

code from form1

vb:
--------------------------------------------------------------------------------
option explicit

private sub form_load()


dim lcol as long, lrow as long

' just fill the first grid with some data


' note: you can resize the columns using the mouse
with msflexgrid1
.cols = 10
.rows = 12
.colalignment(-1) = flexaligncentercenter
.fixedcols = 2
.fixedrows = 2
.allowuserresizing = flexresizecolumns
for lrow = 0 to .rows - 1
for lcol = 0 to .cols - 1
.textmatrix(lrow, lcol) = "r" & lrow & "c" & lcol
if lrow / 3 = lrow \ 3 then
if lcol / 2 = lcol \ 2 then
.row = lrow
.col = lcol
.cellfontbold = true
end if
end if
next lcol
next lrow
end with
end sub

' the save button


private sub command1_click()
dim cflexsettings as clsflexsettings

set cflexsettings = new clsflexsettings


set cflexsettings.flexgrid = msflexgrid1
cflexsettings.savesettings "c:\test.flex", true, true, true, true
me.caption = "c:\test.flex"
end sub

' the load button


private sub command2_click()
dim cflexsettings as clsflexsettings

set cflexsettings = new clsflexsettings


set cflexsettings.flexgrid = msflexgrid2
cflexsettings.loadsettings "c:\test.flex", true, true, true, true

end sub
--------------------------------------------------------------------------------

attached files flexsettings.zip (10.1 kb, 218 views)

flyguy
view public profile
send a private message to flyguy
find all posts by flyguy
add flyguy to your buddy list

#29 10 jul 2004, 04:30 pm


flyguy
lost soul
retired moderator
* guru * join date: may 2001
location: vorlon
posts: 15,392

using the msflexgrid as a calendar

--------------------------------------------------------------------------------

sample using the msflexgrid as a month calendar like outlook.

vb:
--------------------------------------------------------------------------------
'---------------------------------------------------------------------------------
------
' module : form1
' datetime : 11-7-2004 00:28
' author : flyguy
' purpose : sample using flexgrid as month calendar
'---------------------------------------------------------------------------------
------
option explicit

private m_ldate as long ' the date we are working on

private sub form_load()


m_ldate = date
drawgrid m_ldate
end sub

private sub command1_click()


m_ldate = dateadd("m", -1, m_ldate)
drawgrid m_ldate
end sub

private sub command2_click()


m_ldate = dateadd("m", 1, m_ldate)
drawgrid m_ldate
end sub

private sub form_resize()


' i really don't care about errors when resizing
on error resume next

command2.left = me.scalewidth - command1.left - command2.width


with msflexgrid1
.left = command1.left
.top = 2 * command1.top + command2.height
.move .left, .top, me.scalewidth - 2 * .left, me.scaleheight - .top - .left
end with

' also update the grid interior


sizegrid
end sub

'---------------------------------------------------------------------------------
------
' procedure : msflexgrid1_dblclick
' datetime : 10-7-2004 23:55
' author : flyguy
' purpose : to enter some data in the clicked cell
'---------------------------------------------------------------------------------
------
'
private sub msflexgrid1_dblclick()
dim lrow as long
dim lcol as long
dim stext as string

with msflexgrid1
lrow = .mouserow
lcol = .mousecol
if lrow / 2 = lrow \ 2 then lrow = lrow + 1
stext = inputbox(.textmatrix(lrow - 1, lcol), , .textmatrix(lrow, lcol))
if strptr(stext) <> 0 then .textmatrix(lrow, lcol) = stext
end with
end sub
private sub msflexgrid1_mousedown(button as integer, shift as integer, x as
single, y as single)
setcellfocus
end sub

private sub msflexgrid1_mousemove(button as integer, shift as integer, x as


single, y as single)
if button = vbleftbutton then setcellfocus
end sub

'---------------------------------------------------------------------------------
------
' procedure : drawgrid
' datetime : 11-7-2004 00:23
' author : flyguy
' purpose : draw the calendar for the given month
'---------------------------------------------------------------------------------
------
'
private sub drawgrid(byval thedate as long)
dim lfirstdate as long
dim llastdate as long
dim lfirstcol as long
dim lcol as long, lrow as long, lrows as long
dim ldate as long

me.caption = format(thedate, "mmmm yyyy")

' get the 1st and last day of the month


lfirstdate = dateserial(year(thedate), month(thedate), 1)
llastdate = dateserial(year(thedate), month(thedate) + 1, 1) - 1

' the starting column


lfirstcol = weekday(lfirstdate, vbusesystemdayofweek) - 1

' determine the number of weeks


lrows = datediff("ww", lfirstdate, llastdate, vbusesystemdayofweek) + 1

with msflexgrid1
' no borders etc to autosize nicely
.borderstyle = flexbordernone
.appearance = flexflat
.scrollbars = flexscrollbarnone

' just some color settings


.gridcolor = vb3dface
.backcolor = .gridcolor

' no highlighting
.highlight = flexhighlightnever
.focusrect = flexfocuslight

' enable texts to span multiple lines


.wordwrap = true

' number of days in a week <img src=\"x_images/images/smilies/wink.gif\"


border=\"0\" alt=\"\" title=\"wink\" class=\"inlineimg\" />
.cols = 7
' for the date header
.rows = lrows * 2
.clear

lrow = 0
lcol = lfirstcol - 1
for ldate = lfirstdate to llastdate
' column and row counters
lcol = lcol + 1
if lcol > 6 then
lrow = lrow + 2
lcol = 0
end if

' format the date header of the cell


.col = lcol
.row = lrow
.textmatrix(lrow, lcol) = formatdatetime(ldate, vbshortdate)
.cellalignment = flexalignrighttop
' different color for weekend days
if weekday(ldate, vbmonday) > 5 then
.cellbackcolor = rgb(239, 239, 239)
else
.cellbackcolor = vbwhite
end if
' make it yellow when today
if ldate = date then .cellbackcolor = vbyellow

' format the data cell


.row = lrow + 1
.cellbackcolor = vbwhite
.cellalignment = flexalignlefttop
.cellfontbold = true
' different color for weekend days
if weekday(ldate, vbmonday) > 5 then
.cellbackcolor = rgb(239, 239, 239)
else
.cellbackcolor = vbwhite
end if
' make it yellow when today
if ldate = date then .cellbackcolor = vbinfobackground
next ldate

' no fixed columns/rows


.fixedrows = 0
.fixedcols = 0

' set the initial focus


.col = lfirstcol
.row = 1

sizegrid

.redraw = true
end with
end sub
'---------------------------------------------------------------------------------
------
' procedure : sizegrid
' datetime : 11-7-2004 00:23
' author : flyguy
' purpose : resize the cells when the grid is resized
'---------------------------------------------------------------------------------
------
'
private sub sizegrid()
dim lrowheight as long
dim lrow as long

' don't care about resize errors


on error resume next

with msflexgrid1
.redraw = false

' set the width of all columns


.colwidth(-1) = int(.width / .cols)

' correct the width of last column


.colwidth(.cols - 1) = .colwidth(.cols - 1) + (.width - .cols *
.colwidth(.cols - 1))

' calculate the height of the data cells


lrowheight = (.height - (.rows / 2) * .rowheight(0)) / (.rows / 2)

' set the height of the data cells


for lrow = 1 to .rows - 1 step 2
.rowheight(lrow) = lrowheight
next lrow

.redraw = true
end with

end sub

'---------------------------------------------------------------------------------
------
' procedure : setcellfocus
' datetime : 10-7-2004 23:56
' author : flyguy
' purpose : make sure to set the focus to the data part
'---------------------------------------------------------------------------------
------
'
private sub setcellfocus()
dim lrow as long
dim lcol as long

with msflexgrid1
lrow = .mouserow
lcol = .mousecol
if lrow >= 0 and lcol >= 0 then
if lrow / 2 = lrow \ 2 then lrow = lrow + 1
.row = lrow
.col = lcol
end if
end with
end sub
--------------------------------------------------------------------------------

attached images flexcalendar1.gif (12.9 kb, 287 views)


flexcalendar2.gif (13.4 kb, 271 views)

flyguy
view public profile
send a private message to flyguy
find all posts by flyguy
add flyguy to your buddy list

#30 16 aug 2004, 09:56 am


flyguy
lost soul
retired moderator
* guru * join date: may 2001
location: vorlon
posts: 15,392

the power of the fillstyle property and a cell replacement function.

--------------------------------------------------------------------------------

using the fillstyle property you can change a range of cells with a single
command.
but you always have to take care about the current selected row, col, rowsel and
colsel properties.
that's why i wrote a generic function which is capable of changing most of the
cell properties with a single command.

vb:
--------------------------------------------------------------------------------
option explicit

private enum fgcellstyle


fgcsbackcolor = 1
fgcsforecolor = 2
fgcstext = 3
fgcstextstyle = 4
fgcsfontname = 5
fgcsfontbold = 6
fgcsfontitalic = 7
fgcsallignment = 8
end enum

private sub form_load()


with msflexgrid1
.cols = 10
.rows = 10
end with

fg_cell msflexgrid1, fgcsbackcolor, 1, 1, 7, 7, rgb(191, 191, 255)


fg_cell msflexgrid1, fgcsbackcolor, 3, 2, 7, 5, vbgreen
fg_cell msflexgrid1, fgcsforecolor, 1, 4, 3, 6, vbred
fg_cell msflexgrid1, fgcstext, 1, 1, 5, 5, "hello"
fg_cell msflexgrid1, fgcsfontbold, 2, 3, 5, 6, true
fg_cell msflexgrid1, fgcsallignment, 2, 4, 3, 4, flexalignrightcenter
fg_cell msflexgrid1, fgcsfontname, 1, 3, 2, 5, "arial"
fg_cell msflexgrid1, fgcstextstyle, 1, 1, 3, 3, flextextraised
end sub

private sub fg_cell(fg as msflexgrid, byval what as fgcellstyle, row1 as long,


col1 as long, row2 as long, col2 as long, value as variant)
dim prevrowcol(3) as long ' to store the actual settings
dim prevfillstyle as integer ' to store the actual settings

with fg
.redraw = false

' store current settings


prevrowcol(0) = .row
prevrowcol(1) = .col
prevrowcol(2) = .rowsel
prevrowcol(3) = .colsel
prevfillstyle = .fillstyle

' set the range


.fillstyle = flexfillrepeat
.row = row1
.col = col1
.rowsel = row2
.colsel = col2

' apply changes


select case what
case fgcsbackcolor
.cellbackcolor = value
case fgcsforecolor
.cellforecolor = value
case fgcstext
.text = value
case fgcstextstyle
.celltextstyle = value
case fgcsfontname
.cellfontname = value
case fgcsfontbold
.cellfontbold = value
case fgcsfontitalic
.cellfontitalic = value
case fgcsallignment
.cellalignment = value
end select

' restore settings


.fillstyle = prevfillstyle
.row = prevrowcol(0)
.col = prevrowcol(1)
.rowsel = prevrowcol(2)
.colsel = prevrowcol(3)

.redraw = true
end with
end sub
--------------------------------------------------------------------------------

attached images cellstyles.gif (9.9 kb, 285 views)

flyguy
view public profile
send a private message to flyguy
find all posts by flyguy
add flyguy to your buddy list

#31 27 dec 2004, 02:02 am


flyguy
lost soul
retired moderator
* guru * join date: may 2001
location: vorlon
posts: 15,392

multicolumn sort: the next generation

--------------------------------------------------------------------------------

quote:
originally posted by flyguy
the msflexgrid does have some capabilities for sorting.
it works great if you want to sort 1 column.
if you want to sort multiple columns the flexgrid always sorts them from left to
right and all in the same order (ascending/descending).

in the previous sort sample i used a stable sorting mechanisme, which means you
sort the data in multiple steps while trying to preserve the orginal data order
for other columns.
somehow it isn't that stable at all and there are some problems when mixing
ascending and descending sorting.

in the next sample i used a different technique which is not stable, but does the
multi column sorting in a single step.

for this sample you need a form with:


1. msflexgrid control named msflexgrid1
1. command button named command1

vb:
--------------------------------------------------------------------------------
'---------------------------------------------------------------------------------
------
' module : form1
' datetime : 27-12-2004
' author : flyguy
' purpose : demo for sorting multiple columns, data showed in a msflexgrid
'---------------------------------------------------------------------------------
------
option explicit
private sub form_load()
dim lrow as long, lcol as long

' just fill the grid with some random data


with msflexgrid1
.cols = 6
.rows = 10
for lrow = .fixedrows to .rows - 1
for lcol = .fixedcols to .cols - 1
.textmatrix(lrow, lcol) = int(rnd * 4)
next lcol
next lrow
end with
end sub

private sub command1_click()


dim adata() as string
dim lrow as long, lcol as long
dim ccolumn as collection, corder as collection

' put the grid data in a string array


with msflexgrid1
redim adata(.rows - .fixedrows - 1, .cols - .fixedcols - 1)
for lrow = .fixedrows to .rows - 1
for lcol = .fixedcols to .cols - 1
adata(lrow - .fixedrows, lcol - .fixedcols) = .textmatrix(lrow, lcol)
next lcol
next lrow
end with

' set the sorting parameters


set ccolumn = new collection
set corder = new collection

ccolumn.add 0
corder.add 1 ' sort ascending

ccolumn.add 1
corder.add -1 ' sort descending

ccolumn.add 2
corder.add 1 ' sort ascending

' sort the grid


shellsortmulticolumn adata, ccolumn, corder

' put the data back in the grid


with msflexgrid1
for lrow = .fixedrows to .rows - 1
for lcol = .fixedcols to .cols - 1
.textmatrix(lrow, lcol) = adata(lrow - .fixedrows, lcol - .fixedcols)
next lcol
next lrow
end with

end sub
--------------------------------------------------------------------------------
in a module:

vb:
--------------------------------------------------------------------------------
'---------------------------------------------------------------------------------
------
' module : modshellsort
' datetime : 27-12-2004
' author : flyguy
'---------------------------------------------------------------------------------
------
option explicit

'---------------------------------------------------------------------------------
------
' procedure : shellsortmulticolumn
' datetime : 27-12-2004
' author : flyguy
' purpose : sort a 2d string array on multiple columns
'---------------------------------------------------------------------------------
------
public sub shellsortmulticolumn(sarray() as string, ccolumns as collection, _
corder as collection)

dim lloop1 as long, lhvalue as long


dim lubound as long, llbound as long
dim lubound2 as long, llbound2 as long
dim lnofcolumns as long
dim acolumns() as long, aorder() as long
dim bsorted as boolean

if ccolumns is nothing then exit sub


if corder is nothing then exit sub
if ccolumns.count <> corder.count then exit sub

lnofcolumns = ccolumns.count
redim acolumns(lnofcolumns)
redim aorder(lnofcolumns)
for lloop1 = 1 to lnofcolumns
acolumns(lloop1) = ccolumns(lloop1)
aorder(lloop1) = corder(lloop1)
next lloop1

lubound = ubound(sarray)
llbound = lbound(sarray)

lubound2 = ubound(sarray, 2)
llbound2 = lbound(sarray, 2)

lhvalue = (lubound - llbound) \ 2

do while lhvalue > llbound


do
bsorted = true
for lloop1 = llbound to lubound - lhvalue
if comparevalues(sarray, lloop1, lloop1 + lhvalue, lnofcolumns, _
acolumns, aorder) then
swaplines sarray, lloop1, lloop1 + lhvalue, llbound2, lubound2
bsorted = false
end if
next lloop1

loop until bsorted


lhvalue = lhvalue \ 2
loop

end sub

'---------------------------------------------------------------------------------
------
' procedure : swaplines
' datetime : 27-12-2004
' author : flyguy
' purpose : swap a row of data in a 2d array
'---------------------------------------------------------------------------------
------
private sub swaplines(byref sarray() as string, lindex1 as long, _
lindex2 as long, llbound as long, lubound as long)

dim i as long, stemp as string

for i = llbound to lubound


stemp = sarray(lindex1, i)
sarray(lindex1, i) = sarray(lindex2, i)
sarray(lindex2, i) = stemp
next i
end sub

'---------------------------------------------------------------------------------
------
' procedure : comparevalues
' datetime : 27-12-2004
' author : flyguy
' purpose : compare column values for multicolumn sorting
'---------------------------------------------------------------------------------
------
private function comparevalues(byref sarray() as string, lindex1 as long, _
lindex2 as long, lnofcolumns as long, acolumns() as long, aorder() as long)

dim i as long
dim lcol as long
dim svalue1 as string, svalue2 as string

for i = 1 to lnofcolumns
lcol = acolumns(i)
if aorder(i) = 1 then
svalue1 = sarray(lindex1, lcol)
svalue2 = sarray(lindex2, lcol)
else
svalue1 = sarray(lindex2, lcol)
svalue2 = sarray(lindex1, lcol)
end if

if svalue1 < svalue2 then


exit for
elseif svalue1 > svalue2 then
comparevalues = true
exit for
end if

next i

end function
--------------------------------------------------------------------------------

flyguy
view public profile
send a private message to flyguy
find all posts by flyguy
add flyguy to your buddy list

#32 15 feb 2005, 01:04 am


flyguy
lost soul
retired moderator
* guru * join date: may 2001
location: vorlon
posts: 15,392

--------------------------------------------------------------------------------

an updated version of comparevalues function to take in account numeric/date


values:

vb:
--------------------------------------------------------------------------------
'---------------------------------------------------------------------------------
------
' procedure : comparevalues
' datetime : 27-12-2004
' author : flyguy
' purpose : compare column values for multicolumn sorting
' revision : 15-02-2005, take in account numeric and date values
'---------------------------------------------------------------------------------
------
private function comparevalues(byref sarray() as string, lindex1 as long, _
lindex2 as long, lnofcolumns as long, acolumns() as long, aorder() as long)

dim i as long
dim lcol as long
dim svalue1 as string, svalue2 as string
dim dvalue1 as double, dvalue2 as double
dim bnumeric as boolean

for i = 1 to lnofcolumns
lcol = acolumns(i)
if aorder(i) = 1 then
svalue1 = sarray(lindex1, lcol)
svalue2 = sarray(lindex2, lcol)
else
svalue1 = sarray(lindex2, lcol)
svalue2 = sarray(lindex1, lcol)
end if

if isdate(svalue1) and isdate(svalue2) then


dvalue1 = cdate(svalue1)
dvalue2 = cdate(svalue2)
bnumeric = true
elseif isnumeric(svalue1) and isnumeric(svalue2) then
dvalue1 = cdbl(svalue1)
dvalue2 = cdbl(svalue2)
bnumeric = true
else
bnumeric = false
end if

if bnumeric then
if dvalue1 < dvalue2 then
exit for
elseif dvalue1 > dvalue2 then
comparevalues = true
exit for
end if
else
if svalue1 < svalue2 then
exit for
elseif svalue1 > svalue2 then
comparevalues = true
exit for
end if
end if
next i

end function
--------------------------------------------------------------------------------

flyguy
view public profile
send a private message to flyguy
find all posts by flyguy
add flyguy to your buddy list

#33 7 apr 2005, 07:36 am


flyguy
lost soul
retired moderator
* guru * join date: may 2001
location: vorlon
posts: 15,392

--------------------------------------------------------------------------------

create html table from msflexgrid control:


vb:
--------------------------------------------------------------------------------
'---------------------------
' module : modflexhtml
' datetime : 7-4-2005
' author : componentone, adapted by flyguy to be used with msflexgrid
' purpose : exporting msflexgrid to html
'---------------------------
option explicit

private declare function getsyscolor lib "user32" (byval nindex as long) as long

private const extrawidth as double = 1.2

'---------------------------
' procedure : htmlcolor
' datetime : 30-1-2004
' author : componentone
' purpose : converts a vb color into html color code
'---------------------------
private function htmlcolor(byval lcolor as long) as string
dim stemp as string

' convert to hex


stemp = hex$(lcolor)

' handle system colors


if len(stemp) > 6 then
if left$(stemp, 1) = "8" then
lcolor = val("&h" & mid$(stemp, 2))
lcolor = getsyscolor(lcolor)
stemp = hex$(lcolor)
end if
end if

' build format


stemp = string(6 - len(stemp), "0") & stemp
htmlcolor = """#" & right$(stemp, 2) & mid$(stemp, 3, 2) & left$(stemp, 2) &
""""
end function

'---------------------------
' procedure : htmltext
' datetime : 30-1-2004
' author : componentone
' purpose : converts a vb string into an html string
'---------------------------
private function htmltext(byval sline as string) as string

if len(sline) = 0 then
htmltext = " "
else
htmltext = replace$(sline, "&", "&")
htmltext = replace$(htmltext, "<", "<")
htmltext = replace$(htmltext, ">", ">")
end if

end function
'---------------------------
' procedure : flexgridtohtml
' datetime : 7-4-2005
' author : componentone, adapted by flyguy to be used with msflexgrid
' purpose : exporting msflexgrid to html
'---------------------------
public function flexgridtohtml(fg as msflexgrid) as string
dim sdata as string, sline as string
dim dtblwidth as double
dim i as long, lrow as long, lcol as long
dim sspan as string
dim lrow1 as long, lrow2 as long, lcol1 as long, lcol2 as long
dim dwidth as double
dim stext as string, stemp as string
dim sbackground as string, lcolor as long
dim sfont as string, sborder as string, sfontfx as string
dim salign as string, scell as string
dim bprocesscell as boolean

with fg
.redraw = false

' get total table width in pixels


dtblwidth = 0
for lcol = 0 to .cols - 1
dtblwidth = dtblwidth + .colwidth(lcol)
next lcol
dtblwidth = extrawidth * dtblwidth / screen.twipsperpixelx

' save table header


sdata = "<table border cellspacing=0 cellpadding=2 valign=center" & _
" bgcolor=" & htmlcolor(.backcolor) & _
" width=" & format(int(dtblwidth)) & _
">" & vbcrlf

' loop through the rows


for lrow = 0 to .rows - 1

sline = ""

' skip hidden rows


if .rowheight(lrow) > 0 then

' start row


sline = "<tr>"

' loop through the columns


for lcol = 0 to .cols - 1

' skip hidden cols


if .colwidth(lcol) > 0 then

.col = lcol
.row = lrow
bprocesscell = true

' handle merges


sspan = ""
getmergedcols fg, lrow, lcol, lcol1, lcol2
getmergedrows fg, lrow, lcol, lrow1, lrow2
if lcol1 < lcol then bprocesscell = false
if lrow1 < lrow then bprocesscell = false

if bprocesscell then
if lcol2 > lcol then sspan = " colspan=" & (lcol2 - lcol + 1)
if lrow2 > lrow then sspan = sspan & " rowspan=" & (lrow2 - lrow +
1)

' get col width


dwidth = 0
for i = lcol1 to lcol2
dwidth = dwidth + .colwidth(i)
next
dwidth = extrawidth * dwidth / screen.twipsperpixelx

' get cell text


stext = htmltext(.textmatrix(lrow, lcol))

' get back color


sbackground = ""
lcolor = .cellbackcolor
if lcolor <> 0 then
sbackground = " bgcolor=" & htmlcolor(lcolor)
elseif lrow < .fixedrows or lcol < .fixedcols then
sbackground = " bgcolor=" & htmlcolor(.backcolorfixed)
end if

' get border color


sborder = ""
if lrow < .fixedrows or lcol < .fixedcols then
sborder = " bordercolor=" & htmlcolor(.gridcolorfixed)
else
sborder = " bordercolor=" & htmlcolor(.gridcolor)
end if

' get fore color and font name


sfont = " size=2"
stemp = .cellfontname
if stemp <> .fontname then
sfont = " face=" & """" & stemp & """"
end if
lcolor = .cellforecolor
if lcolor <> 0 then sfont = " color=" & htmlcolor(lcolor)

' get font effects


sfontfx = ""
if .cellfontbold then sfontfx = sfontfx & "<b>"
if .cellfontitalic then sfontfx = sfontfx & "<i>"
if .cellfontunderline then sfontfx = sfontfx & "<u>"

' get alignment


salign = ""
select case .cellalignment
case flexaligncenterbottom
salign = " align=center valign=bottom"
case flexaligncentercenter
salign = " align=center"
case flexaligncentertop
salign = " align=center valign=top"
case flexalignleftbottom
salign = " valign=bottom"
case flexalignleftcenter
salign = ""
case flexalignlefttop
salign = " valign=top"
case flexalignrightbottom
salign = " align=right valign=bottom"
case flexalignrightcenter
salign = " align=right"
case flexalignrighttop
salign = " align=right valign=top"
case else
if isnumeric(.textmatrix(lrow, lcol)) then
salign = " align=right valign=bottom"
end if
end select

' build html cell string


stemp = """" & format(dwidth / dtblwidth, "#%") & """"
scell = "<td width=" & stemp & sbackground & salign & sborder &
sspan & ">"
if sfont <> "" then scell = scell & "<font" & sfont & ">"
scell = scell & sfontfx & stext
if instr(sfontfx, "b") > 0 then scell = scell & "</b>"
if instr(sfontfx, "i") > 0 then scell = scell & "</i>"
if instr(sfontfx, "u") > 0 then scell = scell & "</u>"
if sfont <> "" then scell = scell & "</font>"

' end cell


scell = scell & "</td>"
sline = sline & scell

end if ' processcell


end if ' .colwidth(lcol) > 0 then

next lcol

' end row


if len(sline) > 0 then sdata = sdata & sline & "</tr>" & vbcrlf

end if ' .rowheight(lrow) > 0 then


next lrow

.redraw = true
end with
' table end
sdata = sdata & "</table></font>"

' return success


flexgridtohtml = sdata
end function

'---------------------------
' procedure : getmergedcols
' datetime : 7-4-2005
' author : flyguy
'---------------------------
private sub getmergedcols(fg as msflexgrid, byval row as long, _
byval col as long, byref lstart as long, byref lend as long)
dim lcol as long
dim lcnt as long

lstart = col
lend = col

with fg
if row < .fixedrows then
for lcol = col - 1 to 0 step -1
if .colwidth(lcol) <> 0 then
if .textmatrix(row, lcol) = .textmatrix(row, col) then
lcnt = lcnt + 1
else
exit for
end if
end if
next lcol
if lcnt > 0 then lstart = col - lcnt

lcnt = 0
for lcol = col + 1 to .cols - 1
if .colwidth(lcol) <> 0 then
if .textmatrix(row, lcol) = .textmatrix(row, col) then
lcnt = lcnt + 1
else
exit for
end if
end if
next lcol
if lcnt > 0 then lend = col + lcnt

end if
end with
end sub

'--------------------------
' procedure : getmergedrows
' datetime : 7-4-2005
' author : flyguy
'--------------------------
private sub getmergedrows(fg as msflexgrid, byval row as long, _
byval col as long, byref lstart as long, byref lend as long)
dim lrow as long
dim lcnt as long

lstart = row
lend = row

with fg
if col < .fixedcols then
for lrow = row - 1 to 0 step -1
if .rowheight(lrow) <> 0 then
if .textmatrix(lrow, col) = .textmatrix(row, col) then
lcnt = lcnt + 1
else
exit for
end if
end if
next lrow
if lcnt > 0 then lstart = row - lcnt

for lrow = row + 1 to .rows - 1


if .rowheight(lrow) <> 0 then
if .textmatrix(lrow, col) = .textmatrix(row, col) then
lcnt = lcnt + 1
else
exit for
end if
end if
next lrow
if lcnt > 0 then lend = row + lcnt
end if

end with
end sub
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
last edited by flyguy : 7 apr 2005 at 07:41 am.

flyguy
view public profile
send a private message to flyguy
find all posts by flyguy
add flyguy to your buddy list

#34 7 apr 2005, 07:39 am


flyguy
lost soul
retired moderator
* guru * join date: may 2001
location: vorlon
posts: 15,392

--------------------------------------------------------------------------------

snippet from ms knowledge base how to put html data on the clipboard, so you can
paste in for example word:

vb:
--------------------------------------------------------------------------------
'---------------------------------------------------------------------------------
------
' module : modclipboardhtml
' datetime : 2-4-2004
' author : microsoft
' purpose : howto: add html code to the clipboard by using visual basic
' revision :
'---------------------------------------------------------------------------------
------

option explicit

private declare function closeclipboard lib "user32" () as long


private declare function openclipboard lib "user32" (byval hwnd as long) as long
private declare function globalalloc lib "kernel32" (byval wflags as long, _
byval dwbytes as long) as long
private declare function setclipboarddata lib "user32" (byval wformat as long, _
byval hmem as long) as long
private declare function emptyclipboard lib "user32" () as long
private declare function registerclipboardformat lib "user32" alias _
"registerclipboardformata" (byval lpstring as string) as long
private declare function globallock lib "kernel32" (byval hmem as long) as long
private declare function globalunlock lib "kernel32" ( _
byval hmem as long) as long
private declare sub copymemory lib "kernel32" alias "rtlmovememory" ( _
pdest as any, psource as any, byval cblength as long)
private declare function getclipboarddata lib "user32" ( _
byval wformat as long) as long
private declare function lstrlen lib "kernel32" alias "lstrlena" ( _
byval lpdata as long) as long

private const m_sdescription = _


"version:1.0" & vbcrlf & _
"starthtml:aaaaaaaaaa" & vbcrlf & _
"endhtml:bbbbbbbbbb" & vbcrlf & _
"startfragment:cccccccccc" & vbcrlf & _
"endfragment:dddddddddd" & vbcrlf

private m_cfhtmlclipformat as long

private function registercf() as long

'register the html clipboard format


if (m_cfhtmlclipformat = 0) then
m_cfhtmlclipformat = registerclipboardformat("html format")
end if
registercf = m_cfhtmlclipformat

end function

public sub puthtmlclipboard(shtmlfragment as string, _


optional scontextstart as string = "<html><body>", _
optional scontextend as string = "</body></html>")

dim sdata as string

if registercf = 0 then exit sub

'add the starting and ending tags for the html fragment
scontextstart = scontextstart & "<!--startfragment -->"
scontextend = "<!--endfragment -->" & scontextend

'build the html given the description, the fragment and the context.
'and, replace the offset place holders in the description with values
'for the offsets of starthmtl, endhtml, startfragment and endfragment.
sdata = m_sdescription & scontextstart & shtmlfragment & scontextend
sdata = replace(sdata, "aaaaaaaaaa", _
format(len(m_sdescription), "0000000000"))
sdata = replace(sdata, "bbbbbbbbbb", format(len(sdata), "0000000000"))
sdata = replace(sdata, "cccccccccc", format(len(m_sdescription & _
scontextstart), "0000000000"))
sdata = replace(sdata, "dddddddddd", format(len(m_sdescription & _
scontextstart & shtmlfragment), "0000000000"))

'add the html code to the clipboard


if cbool(openclipboard(0)) then

dim hmemhandle as long, lpdata as long

hmemhandle = globalalloc(0, len(sdata) + 10)

if cbool(hmemhandle) then

lpdata = globallock(hmemhandle)
if lpdata <> 0 then

copymemory byval lpdata, byval sdata, len(sdata)


globalunlock hmemhandle
emptyclipboard
setclipboarddata m_cfhtmlclipformat, hmemhandle

end if

end if

call closeclipboard
end if

end sub

public function gethtmlclipboard() as string

dim sdata as string

if registercf = 0 then exit function

if cbool(openclipboard(0)) then

dim hmemhandle as long, lpdata as long


dim nclipsize as long

globalunlock hmemhandle

'retrieve the data from the clipboard


hmemhandle = getclipboarddata(m_cfhtmlclipformat)

if cbool(hmemhandle) then

lpdata = globallock(hmemhandle)
if lpdata <> 0 then
nclipsize = lstrlen(lpdata)
sdata = string(nclipsize + 10, 0)
call copymemory(byval sdata, byval lpdata, nclipsize)

dim nstartfrag as long, nendfrag as long


dim nindx as long

'if startfragment appears in the data's description,


'then retrieve the offset specified in the description
'for the start of the fragment. likewise, if endfragment
'appears in the description, then retrieve the
'corresponding offset.
nindx = instr(sdata, "startfragment:")
if nindx then
nstartfrag = clng(mid(sdata, _
nindx + len("startfragment:"), 10))

end if
nindx = instr(sdata, "endfragment:")
if nindx then
nendfrag = clng(mid(sdata, nindx + len("endfragment:"), 10))
end if

'return the fragment given the starting and ending


'offsets
if (nstartfrag > 0 and nendfrag > 0) then
gethtmlclipboard = mid(sdata, nstartfrag + 1, _
(nendfrag - nstartfrag))
end if

end if

end if

call closeclipboard
end if

end function
--------------------------------------------------------------------------------

flyguy
view public profile
send a private message to flyguy
find all posts by flyguy
add flyguy to your buddy list

i use a simple subroutine that totals the values within columns of a


flexgrid control

-------------------------------------------
dim subtotdebit as single
dim subtotcredit as single
dim totalamount a single
for row = 1 to grid.rows - 1
if isnumeric(grid.cell(flexcptext, row, 3)) then subtotdebit =
round(subtotdebit, 2) + round(csng(grid.cell(flexcptext, row, 3)), 2)
if isnumeric(grid.cell(flexcptext, row, 4)) then subtotcredit =
round(subtotcredit, 2) + round(csng(grid.cell(flexcptext, row, 4)), 2)
next row

if subtotdebit = subtotcredit and subtotdebit = totalamount then


do_a
else
do_b
endif
--------------------------------------------------

in some cases where subtotdebit=subtotcredit and subtotdebit =totalamount


the program moves to do_b instead of the expected do_a. while debugging in
these cases, the values that are displayed at the if.....row exactly match
to each other, such as

subtotdebit =123.45
subtotcredit =123.45
totalamount =123.45

however, the debugger jumps to do_b. how can i solve this, since the
debugger doesn't show that it performs good.

oscar

for i = 0 to msflexgrid1.cols
if not (msflexgrid1.textmatrix(i, 2)) = "" then
msflexgrid1.textmatrix(i, 5) = msflexgrid1.textmatrix(i, 2) / 5
end if
next

for i = 0 to msflexgrid1.cols
if isnumeric (msflexgrid1.textmatrix(i, 2)) then
msflexgrid1.textmatrix(i, 5) = cstr(cdbl(msflexgrid1.textmatrix(i, 2)) /
5)
end if
next

for i = 1 to val
if isnumeric(msflexgrid1.textmatrix(i, 2)) then
if not msflexgrid1.textmatrix(i, 2) = 0 then
msflexgrid1.textmatrix(i, 5) = cstr(msflexgrid1.textmatrix(i, 2) / 5)
else
msgbox (" you cant enter a zero value for volume! ")
exit sub
end if
end if
next

projects
here are summaries of some of the projects we've done. we've been developing
software under the name successful software since 1981. in that time we've
developed applications for a number of different companies and in a variety of
industries. what you see described here by no means includes every project we've
ever worked on. if you are seeking someone with experience not described here,
feel free to call or email us if you would like to talk about it further. (if it
turns out that we don't have the experience you're after, we may be able to refer
you to someone who does.)

order / sales entry, billing, receivables, payables, purchase orders, general


ledger, financial reporting, sales analysis
we've done a number of projects involving order entry, billing, inventory control,
accounts receivable, sales analysis, accounts payable, general ledger, purchase
orders or payroll. these were done for a variety of different types of businesses,
with varying needs as to the type of data that needed to be captured and
processed.

some projects involved creating a new application "from scratch" to handle sales
entry / order entry. some of these applications were designed to "stand alone",
without interfacing to other accounting applications. other applications were done
in a way that integrated with an existing accounting application.

some projects involved modifying the source code for an existing "off-the-shelf"
integrated accounting application to tailor the application to the needs of the
company. this included modifications such as collecting additional data and
carrying it through various update processes, and adding new functionality by
modifying existing screens or adding new ones.

other projects involved exporting sales transaction data on a regular basis from
an existing accounting application, such as peachtree accounting
(www.peachtree.com) or others, to a new custom database. this was to provide
special sales analysis or salesperson summary reporting not available in the
accounting application.

healthcare
developed a system for processing medical claims. the system had screens for
entering medical claims, pre-authorizing medical services to be rendered,
maintaining data on facilities, physicians, health plans, plan members, diagnosis
and procedure codes, and procedure fee schedules. it included a seamlessly
integrated table-driven reporting system (using seagate crystal reports automation
objects). the entire system, including reporting, was designed in a 3-tier
architecture for maximum scalability. data that was analyzed frequently for
decision support purposes was automatically loaded on a daily basis into a
separate datamart database (using star-schema table designs). this allowed large
amounts of data to be queried in seconds.
developed a compensation system for physicians along with another programmer as
part of a four-man team that also included a tester and a report developer. the
application involved mechanisms for pooling, allocating, weighting, and adjusting
charge and payment transactions to calculate compensation amounts. transaction
were pooled and accumulated by various criteria: procedure (cpt) codes, modifiers,
sites, sort keys, payers, etc. the application also handled capitated payments and
fee-for-service transactions.

food production
created an application for a bagel bakery chain to assist with calculating
economic order quantities of various types of dough. the application tracked a
history of usage which it then took into consideration along with pending orders
in suggesting future order quantities.

time & expense billing


created an application for entering time and expense items to be billed to
customers. the application allowed for categorizing various time / expense items,
establishing standard rates for various services, and produced summary reports
that could then be used to provide customers with documentation of services
performed.

price quotes
created an application to assist a supplier with locating the best prices
available from a large number of vendors to satisfy a given customer order. the
application automatically faxed requests for price quotes to vendors through
winfax pro software (made by symantec - www.symantec.com) to facilitate the
process of filling customer orders.

retail / rental / point-of-sale


developed a video rental store application. the application managed 42 video
rental store locations for a chain of stores in san diego. each store captured
rental transactions and member information at point-of-sale workstations. data was
sent and received via modem to a central office computer network comprised of
three large computer systems. the load was balanced across the three computers by
having each of the three computers house the data for 10 - 15 stores in the 42-
store chain. a customer could be a "member" at one store location with a prepaid
movie rental plan, check out a movie at a second location, and return it to a
third location, yet the application correctly updated data in the appropriate
computer system even if the three stores involved happened to span all three
central computers. a transaction was "queued" for updating the moment it was
entered by the sales clerk in the store.

this system had many features, including movie reservations, inter-store


transfers, ability for a sales clerk to access inventory in other stores,
statistics on sales clerk productivity, a system for taking store inventory and
immediately reporting discrepancies, tracking of each individual copy of a movie,
rental patterns in different geographic areas to assist with projecting future
order needs, ability to track rental revenue by title, store, area, etc., ad-hoc
reporting down to a detail transaction level, and many, many more features. the
decision support capabilities of the system enabled the company to maximize
turnover of the product. the operational capabilities of the system enabled them
to excel in providing customer service.

insurance
made various enhancements to an application designed for an insurance carrier in
the los angeles area. improvements were made in the areas of calculating agent
commissions and chargebacks, "re-insurance" calculations and reporting, and
others.
mail order
modified the order entry software of a men's clothing catalog company to check for
"bad risk" orders. this involved checking billing or shipping addresses against a
"bad risk" file provided by an outside vendor. the matching made use of a
"soundex" algorithm. (this is an algorithm that makes it possible to match up
similar-sounding names or streets, and thereby allow for alternate spellings. for
example, "smith", "smyth", and "smythe" could be matched with a soundex
algorithm.) the algorithm had to be coded by hand on this particular assignment.
(in many environments soundex is available as a built-in function.)

budgetary accounting
developed the "encumbrance accounting" portion of an accounting system for
municipalities. (other team members developed other portions of the accounting
system.) this allowed users to enter initial budgeted amounts for each of their
accounts. throughout the year, updates to the general ledger kept track of how
much budgeted money in each account had been "spent" and what was still available.
(this application was eventually purchased by several cities in san diego,
riverside, and san bernardino counties. we later did additional custom programming
on this software for a city in the riverside area to improve the accounts payable
reporting and to make other enhancements.)

sales presentation / marketing


created a number of applications for assisting insurance sales persons in making a
presentation of their product to prospective clients. products involved a
combination of insurance and investments that could be tailored to an individual
client's needs. the calculations required to make the projections for the client
were too complex and tedious to be done manually in a timely fashion. the software
allowed the sales person to enter client profile data and data related to
investment amounts and schedule and have the resulting projections instantly
displayed. the calculations made use of insurance rate table information for age,
sex, and other factors. the projections could be displayed on the screen or
printed out in a 3 - 5 page proposal style.

handheld data collection


developed programming for a water district in the san bernardino area for
collecting water meter data. the programming was done for psion handheld
computers, and enabled them be used by water meter readers in the field. data was
downloaded to the handheld units in the order that the meter reader would walk his
route. the display would include information such as "dog" or other comments to
assist the meter reader in his job. collected data would later be uploaded to the
office computer system and imported into the utility billing application for
generating utility bills.

serial communications
we've done a number of projects involving serial communications. some of these
were: interfacing a bar code reader in a point-of-sale environment. creating
software for capturing and storing digitizer output. (this was a large calcomp
digitizer. it was used with a set of blueprints in construction estimating. the
output contained measurements, computed area, and counts of construction
materials.) communication with a cash register to retrieve the day's transactions
(which it stored internally). communication with an optical mark reader being used
to grade test papers to retrieve its data.

event ticket sales


created many new screens, reports, etc. for an event ticket sales application. the
application kept track of sold / available seats, displayed and printed seat maps,
kept data on season ticket sales, printed tickets, etc. many modifications were
made to facilitate the process of selling tickets and to enhance customer service.

data warehouse / datamart


we've created data warehouse / datamart databases. these systems transform data
from operational systems to facilitate access to the data with end-user reporting
tools. scheduled load sessions automatically refresh data at regular intervals.

payroll direct deposit


programming was done to automate the process of payroll direct deposit. security
of the data and reliability of this mission critical process were large
considerations. data was transmitted to the bank via modem. the program had to
wait for verification of the data, receive batch totals, and present this and
other batch status information to a user. the application included the ability to
search through and display payroll data to enable a user to do research when
investigating reported discrepancies, etc. the system transmitted payroll data for
several thousand employees.

human resources
developed various screens, reports, form letters, and exports of data to
spreadsheet software in a human resource database application. this was to keep up
with ever-changing government regulatory changes related to hcfa, osha, eeo, etc.
in addition, reports and spreadsheet interfaces were developed to assist with the
process of wage rate review, performance reviews, and tracking of employee
licenses and education.

data conversion, import / export


we've done a number of small applications for converting or "transforming" data or
importing / exporting data. sometimes these were designed to run unattended and
check for new incoming data at predetermined intervals. these include moving data
between database and text files, moving from one database to another, moving data
from one operating system to another (such as between unix and windows),
converting from one format of text / binary file to another, converting between
multiple record type formats and single record type formats, compressing /
decompressing data with "zip" files, conversion between ebcdic and ascii, and many
other odds & ends.

privacy considerations
created interfaces from / to a customized human resource database application to
an application designed for random drug testing compliance. modified the human
resource database to assist with tracking employees participating in
rehabilitation. confidentiality of data was a large consideration in developing
the interface that allowed data to be moved between applications. for example,
identifying information such as employee name or social security number could not
be moved through the interface, nor be attached to testing samples. yet, certain
information updated in the drug testing application had to find its way back to
the correct employee in the human resource application.

exchanging data with mainframe systems


designed and implemented a human resources client / server application with data
on 25,000 employees. the application used microsoft access (with a lot of vba
code) and microsoft sql server. the sql server database was refreshed from
mainframe data, importing change records on a nightly basis. change records
contained only those segments of an employee's record that had changed since the
last import. the structure of the import record was table driven in ms access with
the ability to import new record structures from a cobol copybook. (mainframe data
structures were in a constant state of change by programming staff. the ability to
import new structures reduced the programming maintenance that would have
otherwise been required on the corresponding sql table structures.) all processing
described here was done through user friendly interfaces using access screens and
menus. this included structure imports, nightly updates, maintenance of user
security on sql server, table-driven report selection, inquiry screens, etc. users
of the application were physically located throughout the u.s. and accessed the
server through remote terminal client software (citrix winframe) over a wide area
network.

4000
09-13-2005 08:17 am

--------------------------------------------------------------------------------

re: something color with msflexgrid

don't if a cool or not but here's a quicky to do alt row colors:

visual basic
code:-----------------------------------------------------------------------------
---
private sub command1_click()
dim i%, j%

with fgrid
doevents
if .rows < 2 then exit sub 'top row is a header
for j = 1 to .rows - 1
for i = 1 to .cols - 1
.row = j
.col = i
if j mod 2 = 0 then
.cellbackcolor = &hdaf3cf 'light green
else
.cellbackcolor = vbwhite
end if
next i
next j
.row = 2
.col = 2
.setfocus
end with

end sub
--------------------------------------------------------------------------------

hack 09-13-2005 08:19 am

--------------------------------------------------------------------------------

re: something color with msflexgrid

navigation and editing


visual basic
code:-----------------------------------------------------------------------------
---private sub mshflexgrid1_keypress(keyascii as integer)
select case keyascii
case vbkeyreturn, vbkeytab
'move to next cell.
with mshflexgrid1
if .col + 1 <= .cols - 1 then
.col = .col + 1
else
if .row + 1 <= .rows - 1 then
.row = .row + 1
.col = 0
else
.row = 1
.col = 0
end if
end if
end with
case vbkeyback
with mshflexgrid1
'remove the last character, if any.
if len(.text) then
.text = left(.text, len(.text) - 1)
end if
end with

case is < 32

case else
with mshflexgrid1
.text = .text & chr(keyascii)
end with
end select
end sub
--------------------------------------------------------------------------------

rhinobull 09-13-2005 08:51 am

--------------------------------------------------------------------------------

re: something color with msflexgrid

highlighting row with alternative (other than default) color:

visual basic
code:-----------------------------------------------------------------------------
---
option explicit

private const oddrow_color = &hdaf3cf


private const evenrow_color = vbwhite
private const selrow_color = vbyellow

private sub fgrid_click()


'==========================
dim j%, icurrow%
static ilastrow as integer

with fgrid
if .row = 0 then exit sub
icurrow = .row
if .row <> ilastrow then
.row = ilastrow
for j = 1 to .cols - 1
.col = j
if ilastrow mod 2 = 0 then
.cellbackcolor = oddrow_color
else
.cellbackcolor = evenrow_color
end if
next j
else
exit sub
end if
.row = icurrow
for j = 1 to .cols - 1
.col = j
.cellbackcolor = selrow_color
next j
ilastrow = .row
end with

end sub
--------------------------------------------------------------------------------

hack 09-13-2005 09:07 am

--------------------------------------------------------------------------------

export flexgrid to excel

visual basic
code:-----------------------------------------------------------------------------
---dim i as long
dim p as long
dim newcell as string
dim xl as excel.application
set xl = createobject("excel.application")
xl.workbooks.open (app.path & "\book1")
doevents
xl.visible = true
for i = 1 to msflexgrid1.rows - 1
for p = 1 to msflexgrid1.cols - 1
msflexgrid1.col = p
msflexgrid1.row = i
newcell = chr(i + 64) & p
xl.worksheets("sheet1").range(newcell).value = msflexgrid1.text
next
next
--------------------------------------------------------------------------------we
are on a roll rhinobull! :d

rhinobull 09-13-2005 09:36 am

--------------------------------------------------------------------------------

re: something color with msflexgrid

oh yea, we are!!! :p
here is another one: getting selected values (this is really very quick sample):

visual basic
code:-----------------------------------------------------------------------------
---
private sub command1_click()
'================================
dim i%, j%, intendrow%, iendcol%
dim sbuffer$, arvalues() as string

with fgrid
intendrow = .rowsel
iendcol = .colsel
for i = intstartrow to intendrow
sbuffer = sbuffer & .textmatrix(i, iendcol) & vbnewline
next i
end with
arvalues = split(sbuffer, vbnewline)

for i = 0 to ubound(arvalues)
debug.print arvalues(i)
next i

end sub
--------------------------------------------------------------------------------

rhinobull 09-13-2005 09:38 am

--------------------------------------------------------------------------------

re: something color with msflexgrid

:) :) :)
export to a comma separated file:

visual basic
code:-----------------------------------------------------------------------------
---
private sub command1_click()
'============================
dim i%, j%, strrowtext$

screen.mousepointer = vbhourglass
open app.path & "\test.csv" for output as #1
with fgrid
for i = 1 to .rows - 1
strrowtext = ""
for j = 1 to .cols - 1
strrowtext = strrowtext & .textmatrix(i, j) & "," 'vbtab
next j
print #1, strrowtext
next i
end with
close #1
screen.mousepointer = vbdefault

end sub
--------------------------------------------------------------------------------

hack 09-13-2005 09:42 am

--------------------------------------------------------------------------------

re: something color with msflexgrid

cut, copy, paste and delete


visual basic
code:-----------------------------------------------------------------------------
---private sub mnueditcut()
'cut the selection and put it on the clipboard
editcopy
editdelete
end sub

private sub mnueditcopy()


'copy the selection and put it on the clipboard
clipboard.clear
clipboard.settext msflexgrid1.clip
end sub

private sub mnueditpaste()


'insert clipboard contents
if len(clipboard.gettext) then msflexgrid1.clip = _
clipboard.gettext
end sub

private sub mnueditdelete()


'deletes the selection
dim i as integer
dim j as integer
dim strclip as string
with msflexgrid1
for i = 1 to .rowsel
for j = 1 to .colsel
strclip = strclip & "" & vbtab
next
strclip = strclip & vbcr
next
.clip = strclip
end with
end sub

private sub mnueditselectall()


'selects the whole grid
with msflexgrid1
.visible = false
.row = 1
.col = 1
.rowsel = .rows - 1
.colsel = .cols - 1
.toprow = 1
.visible = true
end with
end sub
--------------------------------------------------------------------------------
rhinobull 09-13-2005 10:37 am

--------------------------------------------------------------------------------

re: something color with msflexgrid

hmm ... between the two of us we have covered pretty much so that will give
whatupdoc a good start i'm sure. :thumb:

whatupdoc 09-13-2005 06:22 pm

--------------------------------------------------------------------------------

re: something color with msflexgrid

wow, thanks alot. that really helps

meander 09-13-2005 07:01 pm

--------------------------------------------------------------------------------

re: something color with msflexgrid

wow so much info need to process it all. btw i rated this as execellent since
theres so much good information!

brucevde 09-14-2005 12:26 am

--------------------------------------------------------------------------------

re: something color with msflexgrid

there are a few things you can use to optimize your flexgrid code.

1) use the fillstyle property and work with a range of cells. try to avoid looping
through all rows and all columns. the code below colours alternate rows (similar
to the code already posted) but executes much faster - especially with a large
number of cells.

2) use the redraw property - set it to false before starting the code and back to
true after the code executes. this ensures the grid is not refreshed until after
the process has completed.

visual basic
code:-----------------------------------------------------------------------------
--- dim i as long

with me.msflexgrid1
.redraw = false
.fillstyle = flexfillrepeat

'change background colour of all cells (excluding fixed cells) to white


.row = .fixedrows
.col = .fixedcols
.rowsel = .rows - 1
.colsel = .cols - 1
.cellbackcolor = vbwhite

'change background colour of all cells in each alternate row to light


green
for i = .fixedrows + 1 to .rows - 1 step 2
.row = i
.col = .fixedcols
.colsel = .cols - 1
.cellbackcolor = &hdaf3cf
next

'set back to default


.fillstyle = flexfillsingle

'set current cell to top left


.row = .fixedrows
.col = .fixedcols

.redraw = true
end
with------------------------------------------------------------------------------
--

3)a quick method to clear all cells in the grid.

visual basic
code:-----------------------------------------------------------------------------
--- with me.msflexgrid1
.redraw = false
.fillstyle = flexfillrepeat

'select a range of cells (in this case the entire grid).


.row = .fixedrows
.col = .fixedcols
.rowsel = .rows - 1
.colsel = .cols - 1

.text = "" 'clears out data in all cells.

.fillstyle = flexfillsingle
.row = .fixedrows
.col = .fixedcols

.redraw = true

end
with------------------------------------------------------------------------------
--

4) some properties have the row # or column # as an argument. for example


rowheight, colwidth, colalignment. if every row or every column will be set to the
same value use -1 for the argument. again, no need for looping.

msflexgrid1.rowheight(-1) = 400
msflexgrid1.colalignment(-1) = flexalignrightcenter

ejpotpot 09-30-2005 09:17 pm


--------------------------------------------------------------------------------

re: export flexgrid to excel

hi hack,

i find this one interesting. can you please help a vb6 newbie here on how to
include the column headings into the excel file?

a bunch of thanks to ya'll.

quote:
originally posted by hack
visual basic
code:-----------------------------------------------------------------------------
---dim i as long
dim p as long
dim newcell as string
dim xl as excel.application
set xl = createobject("excel.application")
xl.workbooks.open (app.path & "\book1")
doevents
xl.visible = true
for i = 1 to msflexgrid1.rows - 1
for p = 1 to msflexgrid1.cols - 1
msflexgrid1.col = p
msflexgrid1.row = i
newcell = chr(i + 64) & p
xl.worksheets("sheet1").range(newcell).value = msflexgrid1.text
next
next
--------------------------------------------------------------------------------we
are on a roll rhinobull! :d

rhinobull 11-09-2005 08:28 am

--------------------------------------------------------------------------------

re: something color with msflexgrid

new procedure added that populates flexgrid from comma delimited file:

visual basic
code:-----------------------------------------------------------------------------
---
private sub command1_click()
'=====================================================
dim i%, j%, strheader$, strline$, aritems() as string

screen.mousepointer = vbhourglass
open app.path & "\test.csv" for input as #1
with fgrid
.clear
.rows = 1
'set headers
line input #1, strheader
aritems = split(strheader, ",")
.cols = ubound(aritems) + 1
for j = 0 to ubound(aritems)
.textmatrix(i, j) = aritems(j)
next j

'poop through file and populate rest of a grid


i = 1
do while not eof(1)
'read line
line input #1, strline
if not strline = strheader then
'split values on comma
aritems = split(strline, ",")
'---
.additem ""
for j = 0 to ubound(aritems)
.textmatrix(i, j) = aritems(j)
next j
'---
i = i + 1
end if
loop
end with
close #1
screen.mousepointer = vbdefault

end sub
--------------------------------------------------------------------------------

fishbyname 03-30-2006 05:18 am

--------------------------------------------------------------------------------

re: something color with msflexgrid

i've just used the export to excel code (works great) and i've modified it to
include the column and row headings

visual basic
code:-----------------------------------------------------------------------------
---dim q as long
dim p as long
dim newcell as string
dim xl as excel.application

set xl = createobject("excel.application")
xl.workbooks.open ("d:\university\3rd year\final year project\my
results\book1")
doevents
xl.visible = true

for p = 0 to msflexgrid1.rows - 1
for q = 0 to msflexgrid1.cols - 1
msflexgrid1.col = q
msflexgrid1.row = p
newcell = chr(q + 65) & p + 1
xl.worksheets("sheet1").range(newcell).value = msflexgrid1.text
next
next------------------------------------------------------------------------------
--

brucevde 07-03-2006 09:54 am

--------------------------------------------------------------------------------

re: something color with msflexgrid

allows the user to rearrange the columns using drag/drop.

visual basic
code:-----------------------------------------------------------------------------
---private mlngdragcolumn as long

private sub form_load()


with me.msflexgrid1
.cols = 5
.textmatrix(0, 1) = "column 1"
.textmatrix(0, 2) = "column 2"
.textmatrix(0, 3) = "column 3"
.textmatrix(0, 4) = "column 4"
.dragmode = vbmanual
.dragicon = loadpicture("c:\program files\microsoft visual
studio\common\graphics\icons\dragdrop\drop1pg.ico")
mlngdragcolumn = -1
end with
end sub

private sub msflexgrid1_dragdrop(source as control, x as single, y as single)


if source is msflexgrid1 then
if source.mousecol >= source.fixedcols then
if mlngdragcolumn <> -1 then
source.colposition(source.mousecol) = mlngdragcolumn
end if
end if
end if
end sub

private sub msflexgrid1_mousedown(button as integer, shift as integer, x as


single, y as single)
if button = vbleftbutton then
with msflexgrid1
if .mouserow < .fixedrows and .mousecol >= .fixedcols then
mlngdragcolumn = .mousecol
.drag vbbegindrag
end if
end with
end if
end sub

private sub msflexgrid1_mouseup(button as integer, shift as integer, x as single,


y as single)
mlngdragcolumn = -1
end sub

You might also like