Guidance
指路人
g.yi.org
Guidance Forums / Rapid-Q Basic / Searching dat-file again (I?m new at this)

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

  
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. Searching dat-file again (I?m new at this)
#964
Posted by: 2003-05-23 14:00:27
I?ve got two answers to my question the last time, but as a said in the subject text....I'm a newbe :).
There is a program on the internet "Simple address book", i?ve wrote my code like they did in that program. But instead of searching the dat-file by record nummber, i want to search by a name and then get all the data for that name presented.

Grateful for answers.
Message2. Re: Searching datfile again (I?m new at this)
#965
Posted by: cajino 2003-05-23 15:00:39
Try this simple-sample program :)


$INCLUDE "RAPIDQ.INC"
DECLARE SUB Button1Click (Sender AS QBUTTON)
Dim Stri as QStringList

CREATE Form AS QFORM
    Caption = "Form1"
    Width = 320
    Height = 240
    Center
    CREATE Label1 AS QLABEL
        Caption = ""
        Left = 21
        Top = 92
        Width = 128
        Height = 21
        Transparent = 1
    END CREATE
    CREATE Label2 AS QLABEL
        Caption = ""
        Left = 22
        Top = 126
        Width = 96
        Height = 21
        Transparent = 1
    END CREATE
    CREATE Label3 AS QLABEL
        Caption = ""
        Left = 28
        Top = 169
        Width = 104
        Height = 21
        Transparent = 1
    END CREATE
    CREATE Edit1 AS QEDIT
        Text = ""
        Left = 50
        Top = 32
    END CREATE
    CREATE Button1 AS QBUTTON
        Caption = "Search"
        Left = 194
        Top = 32
        TabOrder = 1
        OnClick = Button1Click
    END CREATE
END CREATE


Form.ShowModal


SUB Button1Click (Sender AS QBUTTON)
search$=Edit1.Text
Stri.Loadfromfile("c:rapidqfile.dat")
lines=Stri.Itemcount
for i=0 to lines -1
compare$=Field$(Stri.Item(i), "$", 1)
if search$=compare$ then
Label1.Caption=Field$(Stri.Item(i), "$", 1)
Label2.Caption=Field$(Stri.Item(i), "$", 2)
Label3.Caption=Field$(Stri.Item(i), "$", 3)

end if
next


END SUB


P.S. file.dat has this structure:

John$Rodeo dr.$Los Angeles
Ted$22nd St.$New York
Luigi$Via Garibaldi$Rome

Bye
Cajino
Message3. Re: Searching datfile again (I?m new at this)
#966
Posted by: guidance 2003-05-23 15:58:06
One method:
Read all data in memory (array of the structure), then search this array by the name, suitable for small data file;
Or another:
Read a block of data in, search, then next block, suitable for large data file.
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Fri 2024-4-26  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0