Using VB to realize data entry of Class E-form

Source: Internet
Author: User

----in programming, you often encounter problems with entering large amounts of data in your application, and if you can implement an input interface like a spreadsheet in that program, you can solve the problem.

----VB provides grid control, but it only has display output function, so that it can accept the input data, it must be reformed, in the computer newspapers and periodicals in many articles are discussed in this, but the method is not satisfactory, the author after groping, find the following methods for interested people to refer to.

----First in the VB5.0 environment Form1 put the controls as shown in Figure 1: Text1; GRID1;

Command1; Command2; VSCROLL1; Hscroll1.

Figure 1form1 and its controls

----Double-click Form1 to open the Code window, coding.

Dimin Putcolnum,in Putrownumasinteger

Privatesubcommand2_click ()

End

Endsub

Privatesubform_activate ()

Text1.setfocus ' text box gets focus

Endsub

Privatesubform_load ()

Grid1.colwidth (0) =540

Grid1.rowheight (0) =216 ' cell width and height

In putcolnum=13

columns, rows displayed in putrownum=15 ' table

Grid1.cols=20

Total columns, rows in grid1.rows=20 ' table

hscroll1.height=300

vscroll1.width=300 ' height and width of horizontal and vertical scroll bars

Grid1.height= (in Putrownum 1) '

(grid1.rowheight (0) grid1.gridlinewidth*12)

Hscroll1.height

' 800x600 pixel is 12;640x480 to 15

Grid1.width= (in Putcolnum 1) *

(grid1.colwidth (0) grid1.gridlinewidth*12)

Vscroll1.width

' The height and width of the table

Hscroll1.width=grid1.width-vscroll1.width

Vscroll1.height=grid1.height-hscroll1.height

' Width and height of horizontal and vertical scroll bars

Hscroll1.left=grid1.left

Hscroll1.top=grid1.top Grid1.height-hscroll1.height

' Position of the horizontal scroll bar

Vscroll1.left=grid1.left Grid1.width-vscroll1.width

Vscroll1.top=grid1.top

' Position of the vertical scroll bar

Hscroll1.min=1

Hscroll1.max=grid1.cols-in Putcolnum

Vscroll1.min=1

Vscroll1.max=grid1.rows-in Putrownum

' Range of horizontal and vertical scroll bars

Text1.width=grid1.colwidth (0)

Text1.height=grid1.rowheight (0)

' Width, height of text box

Text1.left=grid1.left grid1.colwidth (0)

Grid1.gridlinewidth*12

Text1.top=grid1.top grid1.rowheight (0)

Grid1.gridlinewidth*12

' Position of the text box

' Initialize Assignment

Text1.visible=true

Fori=1togrid1.cols-1

Grid1.col=i

Grid1.row=0

Grid1.text=str (I)

Grid1.col=0

Grid1.row=i

Grid1.text=str (I)

Nexti

Grid1.col=1

Grid1.row=1 ' grid column, row initial position

Grid1.selstartcol=1

Grid1.selstartrow=1 ' grid cell column, row initial position

Grid1.leftcol=1

Grid1.toprow=1 ' grid in the upper-left corner of the column, row initial position

Endsub

Privatesubgrid1_mousedown (Buttonasinteger,

Shiftasinteger,xassingle,yassingle)

Grid1.col=grid1.selstartcol

Grid1.row=grid1.selstartrow

Text1.text=grid1.text

Colnum=grid1.col-grid1.leftcol 1

Rownum=grid1.row-grid1.toprow 1

Text1.left=grid1.left (grid1.colwidth (0)

GRID1.GRIDLINEWIDTH*12) *colnum

Text1.top=grid1.top (grid1.rowheight (0)

GRID1.GRIDLINEWIDTH*12) *rownum

Endsub

Privatesubgrid1_mouseup (Buttonasinteger,

Shiftasinteger,xassingle,yassingle)

Text1.setfocus

Endsub

Privatesubhscroll1_change ()

Startcol=grid1.leftcol

Grid1.leftcol=hscroll1.value

Grid1.selstartcol=grid1.selstartcol

Grid1.leftcol-startcol

Grid1.col=grid1.selstartcol

Text1.text=grid1.text

Endsub

Privatesubtext1_change ()

Grid1.text=text1.text

Endsub

Privatesubtext1_keydown (keycode

Asinteger,shiftasinteger)

Selectcasekeycode

Case38 ' cursor up

Grid1.text=text1.text

Ifgrid1.selstartrow<2then

Ifgrid1.toprow>1then

Vscroll1.value=vscroll1.value-1

Else

Grid1.selstartrow=1

EndIf

Else

Ifgrid1.toprow=grid1.selstartrowthen

Vscroll1.value=vscroll1.value-1

Else

Grid1.selstartrow=grid1.selstartrow-1

EndIf

EndIf

Grid1.col=grid1.selstartcol

Grid1.row=grid1.selstartrow

Colnum=grid1.col-grid1.leftcol 1

Rownum=grid1.row-grid1.toprow 1

Text1.text=grid1.text

Text1.left=grid1.left (grid1.colwidth (0)

GRID1.GRIDLINEWIDTH*12) *colnum

Text1.top=grid1.top (grid1.rowheight (0)

GRID1.GRIDLINEWIDTH*12) *rownum

Exitsub

Case40 ' cursor down

Grid1.text=text1.text

Ifgrid1.selstartrow>in Putrownum-1then

Ifgrid1.toprow

Vscroll1.value=vscroll1.value 1

Else

Ifvscroll1.value=vscroll1.maxand

Grid1.selstartrow

Grid1.selstartrow=grid1.selstartrow 1

Else

Grid1.selstartrow=grid1.rows-1

EndIf

EndIf

Else

Ifgrid1.toprow=grid1.selstartrow-in Putrownumthen

Vscroll1.value=vscroll1.value 1

Else

Grid1.selstartrow=grid1.selstartrow 1

EndIf

EndIf

Grid1.col=grid1.selstartcol

Grid1.row=grid1.selstartrow

Colnum=grid1.col-grid1.leftcol 1

Rownum=grid1.row-grid1.toprow 1

Text1.text=grid1.text

Text1.left=grid1.left (grid1.colwidth (0)

GRID1.GRIDLINEWIDTH*12) *colnum

Text1.top=grid1.top (grid1.rowheight (0)

GRID1.GRIDLINEWIDTH*12) *rownum

Exitsub->

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.