Listviews By Hand

General development discussion.

Moderators: Susan Smith, admin, Gabriel

Post Reply
Gabriel
Posts: 412
Joined: Sun Aug 10, 2008 7:37 am
Location: Arlington, TX
Contact:

Listviews By Hand

Post by Gabriel »

Someone at the conference asked me to share some examples of populating a listview by hand. Here's one I do for one of my customers.

This code is copy and pasted out of one of my programs. I attempted to remove parts of the program that were not relevant, but its possible that I removed something on accident that was important. So please feel free to ask any questions you have, and if you notice something missing, point it out, and i'll try to correct the example.

Code: Select all

 ! Customer Listview Data
    dim Clv_Acct$(1), Clv_Name$(1)*25, Clv_Street$(1)*30,Clv_Town$(1)*12
    dim Clv_Surname$(1)*8, Clv_Type$(1), Clv_Zip$(1)*5, CLV_Route$(1)*5
    dim Clv_DepDate$(1)*10, Clv_Phone$(1)

    dim Clv_Notify$(1), Clv_SMan$(1)
 !
    dim Clv_BadSort$(1)

    dim Clv_Start(1), Clv_End(1), Clv_Color$(1)
 ! Customer Listview Headings
    dim Clientheadings$(13), Clientwidths(13), Clientspec$(13)
    for I=1 to udim(mat ClientHeadings$)
       read Clientheadings$(I), Clientwidths(I), Clientspec$(I)
    next I
 !
    data "Acct",4,"C 5"
    data "Client Name",11,"CC 25"
    data "Street Address",12,"CC 30"
    data "Town",7,"CC 12"
    data "Zip",4,"C 5"
    data "Phone",9,"CC 14"
    data "N",2,"CC 1"
    data "Sort",4,"CC 8"
    data "Dep Date",6,"CC 10"
    data "Type",7,"CC 12"
    data "Rte",3,"CC 5"
    data "Sm",3,"CC 2"
    data "B",1,"CC 1"
    
    
                ! Read the contents of the listview into arrays
                mat Clv_Acct$(0) : mat Clv_Name$(0) : mat Clv_Street$(0) : mat Clv_Town$(0)
                mat Clv_Surname$(0) : mat Clv_Type$(0) : mat Clv_Zip$(0) : mat Clv_DepDate$(0)
                mat Clv_Notify$(0) : mat Clv_Sman$(0) : mat Clv_BadSort$(0) : mat Clv_Phone$(0)

                let Color_Index=1
                mat Clv_Start(Color_Index)
                mat Clv_End(Color_Index)
                mat Clv_Color$(Color_Index)

                let Clv_Start(Color_Index)=1
                let Clv_End(Color_Index)=1
                let Clv_Color$(Color_Index)="[INPUT]"

                let ActiveFile=fnOpen("actvfl85", mat Active$, mat Active, mat Form$,1)
                read #ActiveFile, using ctlform : Maxaccountnum
                let MaxAccountNum=lrec(ActiveFile)+1

                let AccountPic$="PIC("&rpt$("#",len(str$(MaxAccountNum)))&")"

                do
                   read #ActiveFile, using form$(ActiveFile) : mat Active$, mat Active eof Ignore     ! QJ

                   if File(ActiveFile)=0 then  ! Read Successful
                      if (ShowInactive$(1:1)="^" and Active$(ac_Prg)="I") or (ShowActive$(1:1)="^" and Active$(ac_prg)="A") then
                         if fnCanViewThis(SalesmanFilter$,Active$(ac_sman),(Active$(ac_prg)=="I")) then
                            let Clv_Index=Udim(Mat Clv_Acct$)+1
                            mat Clv_Acct$(Clv_Index)
                            mat Clv_Name$(Clv_Index)
                            mat Clv_Street$(Clv_Index)
                            mat Clv_Town$(Clv_Index)
                            mat Clv_Zip$(Clv_Index)
                            mat Clv_Notify$(Clv_Index)
                            mat Clv_Surname$(Clv_Index)
                            mat Clv_Type$(Clv_Index)
                            mat Clv_Route$(Clv_Index)
                            mat Clv_DepDate$(Clv_Index)
                            mat Clv_Sman$(Clv_Index)
                            mat Clv_BadSort$(Clv_Index)
                            mat Clv_Phone$(Clv_Index)

                            let Clv_Acct$(Clv_Index)=Cnvrt$(AccountPic$,Rec(ActiveFile))
                            let Clv_Name$(Clv_Index)=Active$(ac_Name)
                            let Clv_Street$(Clv_Index)=Trim$(Active$(ac_Add1)(Pos(Active$(ac_Add1)," ")+1:25))&", "&Active$(ac_Add1)(1:Pos(Active$(ac_Add1)," ")-1)
                            let Clv_Town$(Clv_Index)=Active$(ac_Add2)
                            let Clv_Zip$(Clv_Index)=Str$(Active(ac_Zip))(1:5)
                            let Clv_Phone$(Clv_Index)=fnFormatPhone$(Active(ac_Phone))
                            let Clv_Notify$(Clv_Index)=Active$(ac_Notify)
                            let Clv_Surname$(Clv_Index)=Active$(ac_Sort)
                            let Clv_Type$(Clv_Index)=Active$(ac_type)
                            let Clv_Route$(Clv_Index)=str$(Active(ac_AutoNum))
                            let Clv_Sman$(Clv_Index)=Active$(ac_sman)
                            let Clv_BadSort$(Clv_Index)=""

                            if Active(ac_d) then
                               let Clv_DepDate$(Clv_Index)=date$(days(cnvrt$("pic(######)",Active(Ac_D)),"yymmdd"),"yy/mm/dd")
                               if val(Clv_DepDate$(Clv_Index)(1:2))>88 then
                                  let Clv_DepDate$(Clv_Index)(1:0)="19"
                               else
                                  let Clv_DepDate$(Clv_Index)(1:0)="20"
                               end if
                            else
                               let Clv_DepDate$(Clv_Index)=""
                            end if

                            ! Color some of the clients (those with invalid addresses) a different color
                            if lwrc$(trim$(Active$(ac_name)))<>"moved" and lwrc$(trim$(Active$(ac_name)))<>"empty" and trim$(active$(ac_add1))(1:8)<>"________" and (len(trim$(Active$(ac_name))) or len(trim$(active$(ac_sort)))) and lwrc$(trim$(Active$(ac_sort)))<>"moved" and lwrc$(trim$(Active$(ac_sort)))<>"blank" and lwrc$(trim$(Active$(ac_sort)))<>"empty" and pos(lwrc$(Active$(ac_name)),lwrc$(trim$(Active$(ac_sort))))<1 then
                               let Color_Index+=1
                               mat Clv_Start(Color_Index)
                               mat Clv_End(Color_Index)
                               mat Clv_Color$(Color_Index)

                               let Clv_Start(Color_Index)=Clv_Index
                               let Clv_End(Color_Index)=Clv_Index
                               let Clv_Color$(Color_Index)="[ERROR]"
                               let Clv_BadSort$(Clv_Index)="B"
                            end if

                            if Clv_Acct$(Clv_Index)=Search$ then let StartHere=Clv_Index
                         end if
                      end if
                   end if
                loop While File(ActiveFile)=0
                close #ActiveFile:
       !
                let CLV_End(1)=Clv_Index

       ! .      ! Draw Screen
                print #Window, fields "2,23,CC 36,[HILITE]" : masfile$(mi_masname)
                print #Window, fields "4,9,24/CR 28" : "Select Client to View/Edit: "
                print #Window, fields "5,9,24/CR 28" : "or Search: "
                print #Window, fields Mat Buttonspec$ : Mat Buttoncaption$
                if FromFunction then
                   print #Window, fields "25,35,CC 12,[BUTTONS],B41" : "Select"
                end if
       !
       ! .      ! Draw and Populate Listview
                print #Window, fields "7,5,LIST 15/74,HEADERS,[LVHEADERS]" : (Mat Clientheadings$, Mat Clientwidths, Mat Clientspec$)

                if udim(mat clv_acct$) then
                   print #Window, fields "7,5,LIST 15/74,=" : (Mat Clv_Acct$,Mat Clv_Name$,Mat Clv_Street$,Mat Clv_Town$,Mat Clv_Zip$,Mat Clv_Phone$,Mat Clv_Notify$,Mat Clv_Surname$,Mat Clv_DepDate$,Mat Clv_Type$,Mat CLV_Route$,Mat CLV_Sman$,mat Clv_BadSort$)
                   print #Window, fields "7,5,LIST 15/74,ATTR" : (Mat Clv_Start, Mat Clv_End, Mat Clv_Color$)
                   print #Window, fields "7,5,LIST 15/74,SORT": 1 ! Presort List On Acct Num
                end if
       !
                let Listviewiscurrent=Yes
             end if
       !
             let SaveShowActive$=ShowActive$
             let SaveShowInActive$=ShowInactive$

             if udim(mat clv_acct$) then
                print #Window, fields "4,34,35/C 25;5,34,35/C 25;22,9,CHECK 18;22,27,CHECK 18" : Search$,Filter$,ShowActive$,ShowInactive$
                if StartHere then
                   let curfld(2,starthere)
                   input #Window, fields "7,5,LIST 15/74,ROWSUB,SELONE,NOWAIT" : Dummy
                end if
                let curfld(1)
                input #Window, fields "4,34,35/SEARCH 25,[INPUT],7,5;5,34,35/FILTER 25,[INPUT],7,5,FULLROW,ALL;7,5,LIST 15/74,ROWSUB,SELONE;22,9,CHECK 18,X,31;22,27,CHECK 18,X,31" : Search$,Filter$,Selectedrow,ShowActive$,ShowInactive$
                ! input #Window, fields "4,34,35/SEARCH 25,[INPUT],7,5;7,5,LIST 15/74,ROWSUB,SELONE;22,9,CHECK 18,X,31;22,27,CHECK 18,X,31" : Search$,Selectedrow,ShowActive$,ShowInactive$
             else
                rinput #Window, fields "4,34,35/SEARCH 25,[INPUT],7,5;5,34,35/FILTER 25,[INPUT],7,5,FULLROW,ALL;22,9,CHECK 18,X,31;22,27,CHECK 18,X,31" : Search$,Filter$,ShowActive$,ShowInactive$
             end if

             if trim$(SaveShowActive$)<>trim$(ShowActive$) or trim$(SaveShowInactive$)<>trim$(ShowInActive$) then
                let Listviewiscurrent=No
             end if

             let Function=Fkey

             if Function=39 then ! Copy Name
                let ActiveFile=fnOpen("actvfl85",mat Active$,mat Active,mat Form$,1)
                read #ActiveFile, using form$(ActiveFile), rec=val(Clv_Acct$(Selectedrow)) : mat Active$, mat Active
                close #ActiveFile:
                let setenv("clipboard",trim$(Active$(ac_Name)))
             end if

             if Function=40 then ! Copy Address
                ...
                ...
             end if
       !
             if Function=35 then
                ...
                ...
             end if

             if Function=36 then ! Import Button Clicked
                ...
                ...
             end if
       !
             if Function=37 then ! Edit
                ...
                ...
             end if
       !
             if Function=0 or Function=201 then
                ! Double Click or Enter
                ...
                ...
             end if
Post Reply