Студопедия

Главная страница Случайная страница

Разделы сайта

АвтомобилиАстрономияБиологияГеографияДом и садДругие языкиДругоеИнформатикаИсторияКультураЛитератураЛогикаМатематикаМедицинаМеталлургияМеханикаОбразованиеОхрана трудаПедагогикаПолитикаПравоПсихологияРелигияРиторикаСоциологияСпортСтроительствоТехнологияТуризмФизикаФилософияФинансыХимияЧерчениеЭкологияЭкономикаЭлектроника






Selecting Records From Structured Lists Data






You've already seen how to use a FOR/Next/Step loop to select specified fields of items from a list of structured data (in the following case, every 3 items from the list are a name, address, and phone number):

list.create s, myuserslist.add myusers, " John Smith", " 123 Tine Ln. Forest Hills NJ", " 555-1234" ~ " Paul Thompson", " 234 Georgetown Pl. Peanut Grove AL", " 555-2345" ~ " Jim Persee", " 345 Pickles Pike Orange Grove FL", " 555-3456" ~ " George Jones", " 456 Topforge Court Mountain Creek CO", " " ~ " Tim Paulson", " ", " 555-5678" list.size myusers, sizefor i = 1 to size step 3 list.get myusers, i, n$ print " Name: " + n$next i

You can use this technique to allow users to select from a specific field in a record (i.e., in this case, either name, address, or phone number of a user), and then do something useful with the selected data. In this example, the user can select a name from the user data, and then the name, address, and phone number for just that user is displayed:

list.create s, myuserslist.add myusers, " John Smith", " 123 Tine Ln. Forest Hills NJ", " 555-1234" ~ " Paul Thompson", " 234 Georgetown Pl. Peanut Grove AL", " 555-2345" ~ " Jim Persee", " 345 Pickles Pike Orange Grove FL", " 555-3456" ~ " George Jones", " 456 Topforge Court Mountain Creek CO", " " ~ " Tim Paulson", " ", " 555-5678" list.size myusers, size! Create a NEW list containing just the NAMES (using a for loop to! pick out every third item in the list above): list.create s, namelistfor i = 1 to size step 3 list.get myusers, i, n$ list.add namelist, n$next i! Label this section of code, so we can jump back later: selectname:! Allow the user to select a name from the new names list: select s, namelist, " Click and HOLD Any Name to End the Program", dif d = 1 then end! Print the selected record: cls % clear screenlist.get myusers, s, n$ % the selected item (name)print " Name: " print n$list.get myusers, s+1, a$ % the next item, in order (address after name)print " Address: " print a$list.get myusers, s+2, p$ % the next item, in order (phone after address)print " Phone: " print p$! The following loop simply waits for the user to press a key,! then returns to the label above: do inkey$ k$ if ((k$ < > " @") & (k$ < > " key 4")) then let done = 1until donegoto selectname

Get to know the above example well. Experiment with it and commit it to memory. You will find the general concept and code pattern very useful in many situations. You can use it to create common types of data retrieval apps: recipe collections, address books, inventory information lists, etc.






© 2023 :: MyLektsii.ru :: Мои Лекции
Все материалы представленные на сайте исключительно с целью ознакомления читателями и не преследуют коммерческих целей или нарушение авторских прав.
Копирование текстов разрешено только с указанием индексируемой ссылки на источник.