Guidance
指路人
g.yi.org
software / rapidq / Examples / File & Directory / Simple Address Book.bas

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' Simple Address Book
' Sample program for QfileStream, UDTs
' Mesut Akcan
' 10 Sept. 2000
' http://kaynak.cjb.net
' makcan@s...
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     $INCLUDE "RAPIDQ.INC"
     $TYPECHECK ON

     DECLARE SUB SetFocus LIB "USER32" ALIAS "SetFocus" (HWnd AS LONG)
     DECLARE SUB RNew
     DECLARE SUB RSave
     DECLARE SUB RDelete

     DECLARE SUB FClose
     DECLARE SUB RNo
     DECLARE SUB edRnoKeyP (Key AS BYTE)
     DECLARE SUB RRead(no AS LONG)
     DECLARE SUB btnClick(sender AS QBUTTON)

     TYPE tRecord
      name AS STRING * 18
      lastn AS STRING * 18
      tel1 AS STRING * 18
      tel2 AS STRING * 18
      addr AS STRING * 50
     END TYPE

     CREATE Form AS QFORM
      CAPTION = "Simple Address Book"
      Borderstyle = 1
      DelBorderIcons(2)
      Width = 255
      Height = 273
      Center
      CREATE Label1 AS QLABEL
       CAPTION = "Rec.No:"
       Left = 4
       Top = 8
       Width = 40
      END CREATE
      CREATE Label2 AS QLABEL
       CAPTION = "Name"
       Left = 4
       Top = 32
       Width = 40
      END CREATE
      CREATE Label3 AS QLABEL
       CAPTION = "Last name"
       Left = 4
       Top = 56
       Width = 56
      END CREATE
      CREATE Label4 AS QLABEL
       CAPTION = "T.phone1"
       Left = 4
       Top = 80
       Width = 48
      END CREATE
      CREATE Label5 AS QLABEL
       CAPTION = "T.phone2"
       Left = 4
       Top = 104
       Width = 56
      END CREATE
      CREATE Label6 AS QLABEL
       CAPTION = "Address"
       Left = 4
       Top = 152
       Width = 40
      END CREATE
      CREATE edRno AS QEDIT
       Left = 59
       Top = 5
       Width = 56
       OnKeypress = edRnoKeyP
      END CREATE
      CREATE Edit1 AS QEDIT
       Left = 59
       Top = 28
       Width = 180
       TabOrder = 0
      END CREATE
      CREATE Edit2 AS QEDIT
       Left = 59
       Top = 52
       Width = 180
       TabOrder = 1
      END CREATE
      CREATE Edit3 AS QEDIT
       Left = 59
       Top = 76
       Width = 180
       TabOrder = 2
      END CREATE
      CREATE Edit4 AS QEDIT
       Left = 59
       Top = 100
       Width = 180
       TabOrder = 3
      END CREATE
      CREATE RichEdit1 AS QRICHEDIT
       Left = 59
       Top = 125
       Width = 180
       Height = 75
       PlainText = True
       ScrollBars = ssVertical
       TabOrder = 4
      END CREATE
      CREATE btnGet AS QBUTTON
       CAPTION = "&Get"
       Left = 125
       Top = 4
       Width = 56
       Height = 22
       Tag = 0
       OnClick = btnClick
      END CREATE
      CREATE Button1 AS QBUTTON
       CAPTION = "&New"
       Left = 9
       Top = 212
       Width = 43
       TabOrder = 5
       font.bold = True
       Tag = 1
       OnClick = btnClick
      END CREATE
      CREATE Button2 AS QBUTTON
       CAPTION = "&Save"
       Left = 57
       Top = 212
       Width = 43
       TabOrder = 6
       font.bold = True
       Tag = 2
       OnClick = btnClick
      END CREATE
      CREATE Button3 AS QBUTTON
       CAPTION = "&Delete"
       Left = 105
       Top = 212
       Width = 43
       TabOrder = 7
       font.bold = True
       Tag = 3
       OnClick = btnClick
      END CREATE
      CREATE Button4 AS QBUTTON
       CAPTION = "|<"
       Left = 153
       Top = 212
       Width = 19
       TabOrder = 8
       font.bold = True
       Tag = 4
       OnClick = btnClick
      END CREATE
      CREATE Button5 AS QBUTTON
       CAPTION = "<"
       Left = 177
       Top = 212
       Width = 19
       TabOrder = 9
       font.bold = True
       Tag = 5
       OnClick = btnClick
      END CREATE
      CREATE Button6 AS QBUTTON
       CAPTION = ">"
       Left = 201
       Top = 212
       Width = 19
       TabOrder = 10
       font.bold = True
       Tag = 6
       OnClick = btnClick
      END CREATE
      CREATE Button7 AS QBUTTON
       CAPTION = ">|"
       Left = 225
       Top = 212
       Width = 19
       TabOrder = 11
       font.bold = True
       Tag = 7
       OnClick = btnClick
      END CREATE
      onClose = FClose
     END CREATE

     DIM person AS tRecord
     DIM file AS QFILESTREAM
     DIM rsize AS WORD, recno AS LONG

     CHDIR (COMMAND$(0)-application.exename)

     rsize = SIZEOF(person)
     DEFSTR fName = "rec.dat"
     IF FILEEXISTS(fName) = FALSE THEN file.OPEN(fName,fmCreate):file.CLOSE
     file.OPEN(fName,fmOpenReadWrite)
     CALL Rnew

     Form.SHOWMODAL
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     SUB btnClick (Sender AS QBUTTON)
      SELECT CASE Sender.Tag
      CASE 0: CALL RRead(VAL(edRno.text)-1) ' Get
      CASE 1: CALL RNew ' New
      CASE 2: CALL RSave ' Save
      CASE 3: CALL RDelete ' Delete
      CASE 4: CALL RRead(0) ' First
      CASE 5: CALL RRead(recno-1) ' Prev.
      CASE 6: CALL RRead(recno+1) ' Next
      CASE 7: CALL RRead(file.size\rsize-1) ' Last
      END SELECT
     END SUB

     SUB RNew 'New Click
      edit1.text = ""
      edit2.text = ""
      edit3.text = ""
      edit4.text = ""
      richedit1.text=""
      recno = file.size\rsize
      CALL RNo
      SetFocus(edit1.handle)
     END SUB

     SUB RSave 'Save Click
      WITH person
       .name = edit1.text
       .lastn = edit2.text
       .tel1 = edit3.text
       .tel2 = edit4.text
       .addr = richedit1.text
      END WITH
      file.position = recno * rsize
      file.WriteUDT(person)
      CALL RNew
     END SUB

     SUB RDelete 'Delete Click
      DIM kno AS LONG, n AS LONG ,lastRno AS LONG
      kno = VAL(edRno.text)-1
      lastRno = file.size\rsize-1
      IF (kno<0) OR (kno>lastRno) THEN
       SHOWMESSAGE "Bad Record Number !"
       EXIT SUB
      END IF
      DIM file2 AS QFILESTREAM
      DEFSTR f2name = "~temp.tmp"
      file2.OPEN(f2name,fmCreate)
      FOR n = 0 TO lastRno
       IF n<>kno THEN
        file.position = n * rsize
        file2.CopyFrom(File,rsize)
       END IF
      NEXT
      file2.CLOSE
      file.CLOSE
      KILL fName
      RENAME f2name, fName
      file.OPEN(fName,fmOpenReadWrite)
      IF kno<>0 THEN kno--
      CALL RRead(kno)
     END SUB

     SUB RRead(no AS LONG) ' Read Record
      DIM poz AS LONG
      poz = no * rsize
      IF (poz<0) OR (poz>(file.size-1)) THEN
       SOUND 4000,3
       EXIT SUB
      END IF
      file.position = poz
      file.readUDT(person)
      WITH person
       edit1.text = .name
       edit2.text = .lastn
       edit3.text = .tel1
       edit4.text = .tel2
       richedit1.text = .addr
      END WITH
      recno = no
      CALL RNo
     END SUB

     SUB edRnoKeyP (Key AS BYTE) ' if press Enter key
      IF key = 13 THEN CALL btnClick(btnGet) 'Get Button, key13 = Enter
     END SUB

     SUB RNo : edRno.text = STR$(recno+1):END SUB
     SUB FClose : file.CLOSE : END SUB
掌柜推荐
 
 
¥860.00 ·
 
 
¥410.00 ·
 
 
¥288.00 ·
 
 
¥918.00 ·
 
 
¥288.00 ·
 
 
¥264.00 ·
© Sun 2024-11-24  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2002-09-26 19:05:32