Qbasicnews.com

QBasic => QB Discussion & Programming Help => Topic started by: casonon on June 04, 2003, 12:50:35 PM



Title: Another Question - File opening and writing
Post by: casonon on June 04, 2003, 12:50:35 PM
Hello all,

1st let me say thanks to all of those that have helped me with my previous posts.

Now onto my new problem.   :???:  
With the program I am writing, I would like to be able to open what I call a running file and have the program add to it.  Basically it would work like this.  I will ask the user several questions.  For this example lets us name, age.  After I have the information, I want to be able to open a file that has the same information from other people and then add the new information to the list.  And then have the computer assign the person a number based off a number in the opened file.  So if the user is the 10th person entering the information, the program would assign him the number 10 and the next person to use the program would get assigned 11.  

I would like the file to look something like this.
""""""""""""""""""""""""""""""""""""""""""""""""
Number (assigned)                  Name                  Age
**                                 Chris          22
ect....

""""""""""""""""""""""""""""""""""""""""""""""""

Also, I will need to be able to search this file for key words later on and list any information based on that search.

So if I search for the person with the number 15, I will get the following information

Number - Name - Age

Also if I search for anyone with the age of 22, I would recieve all persons of that age in the above format.

Then I need to save the file and exit the program.

Everytime this program is run I need it to open and get the last number added and then assign the next number in order.  I would like it to allow alphanumerics.  So the first number would start with A1 and the go to A2 and so on.

This might sound confusing, please if you have questions let me know.  I would appreciate any input.


Title: Another Question - File opening and writing
Post by: toonski84 on June 04, 2003, 05:43:21 PM
I might be confused as to what you're asking, but here's a way to save a simple flatfile database in qb.

Code:
TYPE data
  name as string * 15 ' this string can only be 15 chars long
  age as integer
  petsname as string * 15
END TYPE

' to write a record
DIM recordx as data
recordx.name = "Jane Doe"
recordx.age = 25
recordx.petsname = "Jofers"

open "datafile.dat" for binary as 1
  seek lof(1) + 1
  put #1, , recordx
close 1

' to retrieve records

dim records(100) as data ' max: 100 entries.

open "datafile.dat" for binary as 1
  do until eof(1)
    get #1, , records(n)
    numrecords = numrecords + 1
  loop
close 1


of course, this is off the top of my head and may not work.  but that's how a flatfile db ought to be done in qb.


Title: Another Question - File opening and writing
Post by: Phydaux on June 04, 2003, 11:03:37 PM
Quote from: "toonski84"
TYPE info
  personsName as string * 15 ' this string can only be 15 chars long
  age as integer
  petsname as string * 15
END TYPE

' to write a record
DIM recordx as info
recordx.PersonsName = "Jane Doe"
recordx.age = 25
recordx.petsname = "Jofers"

open "datafile.dat" for binary as 1
  seek #1, lof(1) + 1
  put #1, , recordx
close 1

' to retrieve records

dim records(100) as data ' max: 100 entries.

open "datafile.dat" for binary as 1
  do until eof(1)
    get #1, , records(n)
    numrecords = numrecords + 1
  loop
close 1
Added and ammended parts of code. (NAME and DATA are reserved.)

If you wan't to search the file, without loading the whole file into an array, you could use this.
Code:
'this code assumes you have alread defined recordx

OPEN "datafile.dat" FOR BINARY AS #1
   numberOfRecords% = LOF(1) / LEN(recordx)
   FOR record% = 1 to numberOfRecords%
      GET #1, record%, recordx

      'each of the strings are saved as 15 characters,
      'so it would normaly equal "Jane Doe       "
      IF RTRIM$(recordx.personsName) = "Jane Doe" THEN
         REM do what you want with it
      END IF
   NEXT record%
CLOSE #1
You will obviously have to add in your own parts of code to decide what part of the record to search, what to search for, and what happenes when you find something.


Title: Another Question - File opening and writing
Post by: toonski84 on June 04, 2003, 11:05:01 PM
thanks -- i forgot about that :P

quick note:  numrecords is the number of records after the database has been loaded.
quick note:  I noticed you dont load the entire thing.  gotcha.


Title: Another Question - File opening and writing
Post by: Neo on June 05, 2003, 07:04:39 AM
lol
Typed by heart right?


Title: Thanks, But I am really confused.
Post by: casonon on June 05, 2003, 07:40:48 AM
I think you guys understand what I want, But can someone please explain to me what is writen in the code that appears.  I am really confused as to what is going on.  I guess I want to understand each step along the way. Kind of like this.

"""""""""""""""
' to write a record
DIM recordx as info
recordx.PersonsName = "Jane Doe"
recordx.age = 25
recordx.petsname = "Jofers"
"""""""""""""""

I am not sure what this means.
Thanks for bearing with me.  It has been so long since I programmed last.

Thanks
Chris


Title: Idea?
Post by: casonon on June 05, 2003, 08:19:00 AM
Maybe someone could email me some programs that use the .dat files in a similar situation as to what I am looking for that way I could see exactly how they are used in a program.  Just and Idea.
If so, email to csonon@ironmount.biz

Thanks all


Title: Another Question - File opening and writing
Post by: Phydaux on June 05, 2003, 10:39:31 AM
There are basicaly two types of file you can have, sequential and random access.
Sequential files are writtn to and read from in order, from begenning to end (like a tape)
Random access files can be read from and written to at any point (like a CD)

Sequential access files are only really usefull for logs or times when the file isn't going to change often, and be read through from begenning to end.

A Random access file is more usefull for when you want a flatfile database of something. (like a phone book)

A Random access file holds information in RECORDS, a record is a group of information (like name and address) all combined into one.
E.G.
Code:
Phydaux        4 My street                   (029) 20893232
is 1 record containing three strings of lengths 15, 30, 15 respectivly.

This record is a specific DATA TYPE (like an integer, or string) and must be defined.
Code:
TYPE info
   first AS STRING * 15
   street AS STRING * 30
   telephone AS STRING * 15
END TYPE
This defines the data type info. To use these in a variable you need to declare the variable. You cannot use info like a variable, as it would be as silly as saying LET INTEGER = 4.

Code:
DIM person AS info

if you wanted to hold info on more than one person at a time you would just define person as an array.
Code:
DIM person(1 TO 100) AS info



You cannot just write information directly to the person variable (unless the data passed to it is already in the correct format, like reading from a file (but we'll get to that)) but you can write to the different parts like you would a normal variable.
Code:
person.first = "Phydaux"
INPUT "Your street is"; person.street


to save this stuff to a file, you first need to open one. N.B. if the file doesn't exist then it will automaticaly be created.
Code:
OPEN "address.book" FOR RANDOM AS #1 LEN = LEN(person)
this opens up the file "address.book" with RANDOM access, as file number 1, and declares that each record is the length of the person varable.

Now the file is open you can write to it. To write to a file you use the PUT command, where you can specify which file and record to write to, and what to write.
Code:
PUT #1, recnum%, person
This writes all the information stored in person into the recnum% record.
deciding which record to write to is up to you.

To GET information from a file, we use the GET command. It uses exactly the same syntax as the put command.

After we are done with the file make sure to close it or other programs wont be able to access it.
Code:
CLOSE #1
END and SYSTEM also close all open files, but thats a bit lazy and can make it hard to follow a programs layout.

This should be a whole working program randomly accessing the file.
Code:
TYPE info
   first AS STRING * 15
   street AS STRING * 30
   telephone AS STRING * 15
END TYPE

DIM person AS info

OPEN "address.book" FOR RANDOM AS #1 LEN = LEN(person)
   DO
      'this finds how many records there are
      numberOfRecords% = LOF(1) / LEN(person)
      CLS
      PRINT "1) Write info"
      PRINT "2) Read info"
      PRINT "3) Change info"
      PRINT
      PRINT "4) Quit"
      DO
         key$ = INKEY$
      LOOP WHILE VAL(key$) < 1 OR VAL(key$) > 4

      SELECT CASE VAL(key$)
         CASE 1
            'adds information to the file

            INPUT "Name   :", person.first
            INPUT "Street :", person.street
            INPUT "Tel.   :", person.telephone
            PUT #1, numberOfRecords% + 1, person
         CASE 2
            'this will find all the people who share the same first name
            'it can easly be changed to search other parts of the record

            INPUT "Whos information do you want to find"; who$
            FOR record% = 1 TO numberOfRecords%
               GET #1, record%, person
               
               IF RTRIM$(person.first) = who$ THEN
                  PRINT "Name   :"; person.first
                  PRINT "Street :"; person.street
                  PRINT "Tel.   :"; person.telephone
                  PRINT
               END IF
            NEXT record%
            PRINT "press any key to continue..."
            DO: LOOP UNTIL INKEY$ <> ""

         CASE 3
            'this will find all the people who share the same first name
            'and change the information about them

            INPUT "Whos information do you want to change"; who$
            FOR record% = 1 TO numberOfRecords%
               GET #1, record%, person
               IF RTRIM$(person.first) = who$ THEN
                  INPUT "Name   :", person.first
                  INPUT "Street :", person.street
                  INPUT "Tel.   :", person.telephone
                  PUT #1, record%, person
               END IF
            NEXT record%
      END SELECT
   LOOP UNTIL key$ = "4"
CLOSE #1
END
You should obviously refine and talor this to your own needs :) HTH


Title: Almost there..:)
Post by: casonon on June 05, 2003, 12:10:44 PM
Ok I think I somewhat but not really understand what you are saying.  But here is some code that I entered into my program based off what you told me.  But I get an error when I try and run the program.  The error says "excpected: expression".  No clue what that means. Here is the code.

""""""""""""""""""""""""""""""
   TYPE INFO
      NAME AS STRING * 15
      DATE AS STRING * 10
      PNAME AS STRING *40
      PRNAME AS STRING *30
      PROJECT AS STRING *15
   END TYPE
   DIM LOG AS INFO
   OPEN "C:\PART.LOG" FOR RANDOM AS #1 LEN = (LOG)
   DO
   NUMBEROFPARTS% = LOF(1) / LEN(LOG)
   PUT #1, NUMBEROFPARTS% + 1, LOG
   CLOSE#1
   END
""""""""""""""""""""""""""""""

thanks
Chris


Title: Another Question - File opening and writing
Post by: toonski84 on June 05, 2003, 12:58:16 PM
I find the random mode rather... sucky.  I've always preferred binary because it gives you more control.  But that's just me.

it's giving you that error because LOG is a function.  You can't name your variable that.


Title: Another Question - File opening and writing
Post by: casonon on June 05, 2003, 01:50:09 PM
toonski.  If yoou can explain your version to me I might like it to.  I would like to have more control.  I just didn't understand your code to well.  
Thanks
Chris


Title: Another Question - File opening and writing
Post by: casonon on June 05, 2003, 01:54:48 PM
There might be an error because of the LOG but it never gets that far.  I get the error at the AS in the first line of the Type Info.


Title: Your first problem appeared to be that "NAME" is
Post by: Glenn on June 05, 2003, 02:33:01 PM
the name of another intrinsic QB function.  I changed it to "ANAME" and that part works.  I then changed "LOG" to "LOG1" and changed "LEN = (LOG1) to "LEN = "LEN(LOG1)".  I then got up to the point where LEN(LOG1) was zero and dividing by that is a no-no.  I then got to the point where NUMBEROFPARTS% generated an overflow.  So I changed the "%" to a "&" to make a LONG integer.  (I think the real problem was just that the variable was 0 and PUTting to a 0-position is a no-no.  However, it seems that that variable certainly could possibly exceed 32,767.)  Then I got to the point where there was no "LOOP" statement for the "DO" statement, so I fixed that.  You need to add a termination condition for your loop and actually define some data to output.


TYPE INFO
ANAME AS STRING * 15
DATE AS STRING * 10
PNAME AS STRING * 40
PRNAME AS STRING * 30
PROJECT AS STRING * 15
END TYPE
DIM LOG1 AS INFO
OPEN "C:\PART.LOG" FOR RANDOM AS #1 LEN = LEN(LOG1)
DO
NUMBEROFPARTS& = LOF(1) / LEN(LOG1)
PUT #1, NUMBEROFPARTS& + 1, LOG1
LOOP
CLOSE #1
END


Title: Another Question - File opening and writing
Post by: Phydaux on June 06, 2003, 07:31:00 AM
Quote from: "toonski84"
I find the random mode rather... sucky.  I've always preferred binary because it gives you more control.  But that's just me.
I just use random mode because I can't see a condition (with what he's trying to do) where binary mode would be of more use.


Title: Another Question - File opening and writing
Post by: casonon on June 06, 2003, 08:26:59 AM
Ok. Using the methods posted by toonski & phydaux, I arrived at the follwing code.

""""""""""""""""""""""""""""""""
NAME.VERIFY:
LG.DT$ = DATE$
CLS
PRINT "NAME : "; LG.PERNAME$
PRINT
PRINT "DATE : "; LG.DT$
PRINT
PRINT "PART NAME : "; LG.PNAME$
PRINT
PRINT "PROJECT : "; LG.PRJNAME$
PRINT
PRINT "PROJECT TITLE : "; LG.PRONAME$
PRINT
PRINT "IS THIS INFORMATION CORRECT (y/n)"
DO
   KEY$ = INKEY$
   IF KEY$ = "y" OR KEY$ = "Y" THEN
      GOTO WRITE.NEW
   END IF
   IF KEY$ = "n" OR KEY$ = "N" THEN
      GOTO NEW.PART.NUMBER
   END IF
LOOP WHILE KEY$ < "Y" OR KEY$ > "N"


WRITE.NEW:
TYPE INFO
   PERNAME AS STRING * 10
   DT AS STRING * 8
   PNAME AS STRING * 35
   PRJNAME AS STRING * 12
   PRONAME AS STRING * 25
END TYPE

DIM LG AS INFO

OPEN "C:\TEST.DAT" FOR BINARY AS #1
   SEEK #1, LOF(1) + 1
   PUT #1,, LG
CLOSE#1
""""""""""""""""""""""""""""""""""""""""
Now, I get an error when trying to run this that says "Identifer can not contain period."  which I don't understand since you guys have them in your examples.  Please advise what I need to do to fix this.

Thanks


Title: I think your error is related to the labels you're using...
Post by: Glenn on June 06, 2003, 09:42:18 AM
with the GOTO statement.  The examples using "." in the variable names involved *user-defined variables*.


Title: Another Question - File opening and writing
Post by: casonon on June 06, 2003, 10:09:24 AM
Glenn,

How would I correct this problem.  I am still a little in the dark on how this whole thing works with writing the files and the information to the files.

Thanks


Title: Another Question - File opening and writing
Post by: Neo on June 06, 2003, 10:14:31 AM
Quote from: "casonon"
Ok. Using the methods posted by toonski & phydaux, I arrived at the follwing code.

""""""""""""""""""""""""""""""""
NAMEVERIFY:
LG.DT$ = DATE$
CLS
PRINT "NAME : "; LG.PERNAME$
PRINT
PRINT "DATE : "; LG.DT$
PRINT
PRINT "PART NAME : "; LG.PNAME$
PRINT
PRINT "PROJECT : "; LG.PRJNAME$
PRINT
PRINT "PROJECT TITLE : "; LG.PRONAME$
PRINT
PRINT "IS THIS INFORMATION CORRECT (y/n)"
DO
   KEY$ = INKEY$
   IF KEY$ = "y" OR KEY$ = "Y" THEN
      GOTO WRITENEW
   END IF
   IF KEY$ = "n" OR KEY$ = "N" THEN
      GOTO NEWPARTNUMBER
   END IF
LOOP WHILE KEY$ < "Y" OR KEY$ > "N"


WRITENEW:
TYPE INFO
   PERNAME AS STRING * 10
   DT AS STRING * 8
   PNAME AS STRING * 35
   PRJNAME AS STRING * 12
   PRONAME AS STRING * 25
END TYPE

DIM LG AS INFO

OPEN "C:\TEST.DAT" FOR BINARY AS #1
   SEEK #1, LOF(1) + 1
   PUT #1,, LG
CLOSE#1
""""""""""""""""""""""""""""""""""""""""
Now, I get an error when trying to run this that says "Identifer can not contain period."  which I don't understand since you guys have them in your examples.  Please advise what I need to do to fix this.

Thanks


Changed text is red

The error you got was summoned from the fact that you used reserved words in your variable and lable names. This is, of course, not allowed.


Title: Well, I would've said what neo said. :)
Post by: Glenn on June 06, 2003, 10:22:23 AM
(Just take out the "." in the offending labels.)


Title: Another Question - File opening and writing
Post by: Neo on June 06, 2003, 10:27:44 AM
A mistake often made by starting programmers, once you know you don't do it ever again :)


Title: Another Question - File opening and writing
Post by: casonon on June 06, 2003, 10:45:42 AM
Ok..
I changed the code to be what you said. And I get the same error.  I should have told you were the error was.  It wasn't at the name.verify:. It was at the LG.PERNAME$
""""""""""""""""""""
NAMEVERIFY:
LG.DT$ = DATE$
CLS
PRINT "NAME : "; LG.PERNAME$  <---- HERE
PRINT
""""""""""""""""""""

Any ideas?
Thanks


Title: Another Question - File opening and writing
Post by: Neo on June 06, 2003, 10:47:28 AM
:roll:


Title: Is "PERNAME$"...
Post by: Glenn on June 06, 2003, 11:02:09 AM
defined in a user-defined type and is LG typed as that type?   (I'm not sure you can use a variable length string in a user-defined type, but I'll go perform an experiment in a minute.)


Title: Re: Is "PERNAME$"...
Post by: Mango on June 06, 2003, 11:26:53 AM
Quote from: "Glenn"
(I'm not sure you can use a variable length string in a user-defined type, but I'll go perform an experiment in a minute.)


I you can't use variable length string in a user-defined type.  I just tried to find the quote from the *original, paper-bound qb4.5 manual* sitting at my feet...but no luck...I do recall having read this though...although I'm not smart enough to use user-defined types...


Title: Yup. I just confirmed it with an experiment...
Post by: Glenn on June 06, 2003, 11:44:09 AM
However, I suspect that casanon didn't actually put PERNAME$ in a user-defined type because he would have gotten a different error message in that case.


Title: Another Question - File opening and writing
Post by: casonon on June 06, 2003, 12:19:38 PM
Ok. Here is the entire code.  I want to place the infromation that is in the nameverify: area into the file.

Code:

OPTION.PAGE:
CLS
PRINT TAB(25); "IRON MOUNTAIN PART LOG"
PRINT
PRINT "1. OBTAIN NEW PART NUMBER"
PRINT "2. SEARCH PART LOG"
PRINT "3. VIEW ENTIRE PROJECT PART LOG"
DO
KEY$ = INKEY$
LOOP WHILE KEY$ < "1" OR KEY$ > "4"

SELECT CASE KEY$
CASE "1"
GOTO NEW.PART.NUMBER
CASE "2"
CLS
PRINT "2 WORKS"
CASE "3"
CLS
PRINT "3 WORKS"
END SELECT

NEW.PART.NUMBER:
CLS
INPUT "PLEASE ENTER YOUR INITALS"; LG.PERNAME$
CLS
PRINT
PRINT "SELECT A PROJECT"
PRINT
PRINT " 1. BEDRAILS"
PRINT " 2. BOUNCERS"
PRINT " 3. CARSEATS"
PRINT " 4. HIGH CHAIRS"
PRINT " 5. HOOK ON CHAIRS"
PRINT " 6. JUMPERS"
PRINT " 7. PNP"
PRINT " 8. STROLLERS"
PRINT " 9. WALKERS AND ENTERTAINERS"
DO
KEY$ = INKEY$
LOOP WHILE KEY$ < "1" OR KEY$ > "9"

SELECT CASE KEY$
CASE "1"
LG.PRJNAME$ = "BEDRAILS"
CASE "2"
LG.PRJNAME$ = "BOUNCERS"
CASE "3"
LG.PRJNAME$ = "CARSEATS"
CASE "4"
LG.PRJNAME$ = "HIGH CHAIRS"
CASE "5"
LG.PRJNAME$ = "HOOK ON CHAIRS"
CASE "6"
LG.PRJNAME$ = "JUMPERS"
CASE "7"
LG.PRJNAME$ = "PLAY YARDS"
CASE "8"
LG.PRJNAME$ = "STROLLERS"
CASE "9"
LG.PRJNAME$ = "WALKERS & ENTERTAINERS"
END SELECT

CLS
INPUT "ENTER THE TITLE OF THE PROJECT"; LG.PRONAME$
CLS
PRINT
PRINT " 1. ENTER YOUR OWN PART NAME"
PRINT " 2. USE NAME WIZARD"
DO
KEY$ = INKEY$
LOOP WHILE KEY$ < "1" OR KEY$ > "2"

SELECT CASE KEY$
CASE "1"
GOTO NAMING
CASE "2"
GOTO NAME.WIZARD
END SELECT

NAMING:
CLS
INPUT "ENTER THE NAME FOR YOUR PART"; LG.PNAME$
GOTO NAMEVERIFY

NAME.WIZARD:
CLS
PRINT
PRINT " 1. TUBE"
PRINT " 2. TRAY"
PRINT " 3. HOUSING"
PRINT " 4. WHEEL"
PRINT
INPUT "SELECT A PRIMARY DESCRIPTIVE NAME FOR YOUR PART"; DES.1$
SELECT CASE DES.1$
CASE "1"
NAME.1$ = "TUBE"
GOTO TUBE.WIZ
CASE "2"
NAME.1$ = "TRAY"
GOTO TRAY.WIZ
CASE "3"
NAME.1$ = "HOUSING"
GOTO HOUS.WIZ
CASE "4"
NAME.1$ = "WHEEL"
GOTO WHEEL.WIZ
CASE ELSE
NAME.1$ = DES.1$
GOTO OWN.WIZ.1
END SELECT
END

TUBE.WIZ:
CLS
PRINT
PRINT " 1. STROLLER"
PRINT " 2. HIGH CHAIR"
PRINT " 3. SWING"
PRINT " 4. PLAY YARD"
PRINT
INPUT "SELECT A SECONDARY DESCRIPTIVE NAME FOR YOUR PART OR ENTER YOUR OWN"; DES.2$
SELECT CASE DES.2$
CASE "1"
NAME.2$ = "STROLLER"
CASE "2"
NAME.2$ = "HIGH CHAIR"
CASE "3"
NAME.2$ = "SWING"
CASE "4"
NAME.2$ = "PNP"
CASE ELSE
NAME.2$ = DES.2$
END SELECT
CLS
PRINT
PRINT " 1. FRONT LEG"
PRINT " 2. REAR LEG"
PRINT " 3. BASKET TUBE"
PRINT " 4. CROSS TUBE"
PRINT
INPUT "SELECT A LOCATION FOR THE TUBE OR ENTER A DESCRIPTIVE AREA OF YOUR OWN"; DES.3$
SELECT CASE DES.3$
CASE "1"
NAME.3$ = "FRONT LEG"
CASE "2"
NAME.3$ = "REAR LEG"
CASE "3"
NAME.3$ = "BASKET TUBE"
CASE "4"
NAME.3$ = "CROSS TUBE"
CASE ELSE
NAME.3$ = DES.3$
END SELECT
GOTO NAME.VERIFY.WIZ

TRAY.WIZ:
CLS
PRINT
PRINT " 1. HIGH CHAIR"
PRINT " 2. STROLLER"
PRINT " 3. SWING"
PRINT
INPUT "SELECT A SECONDARY DESCRIPTIVE NAME FOR YOUR PART OR ENTER YOUR OWN"; DES.2$
SELECT CASE DES.2$
CASE "1"
NAME.2$ = "HIGH CHAIR"
CASE "2"
NAME.2$ = "STROLLER"
CASE "3"
NAME.2$ = "SWING"
CASE ELSE
NAME.2$ = DES.2$
END SELECT
CLS
PRINT
PRINT " 1. PARENT"
PRINT " 2. CHILD"
PRINT " 3. PLAY"
PRINT " 4. TOY"
PRINT
INPUT "SELECT A LOCATION FOR THE TRAY OR ENTER A DESCRIPTIVE AREA OF YOUR OWN"; DES.3$
SELECT CASE DES.3$
CASE "1"
NAME.3$ = "PARENT"
CASE "2"
NAME.3$ = "CHILD"
CASE "3"
NAME.3$ = "PLAY"
CASE "4"
NAME.3$ = "TOY"
CASE ELSE
NAME.3$ = DES.3$
END SELECT
GOTO NAME.VERIFY.WIZ

HOUS.WIZ:
CLS
PRINT
PRINT " 1. STROLLER"
PRINT " 2. HIGH CHAIR"
PRINT " 3. SWING"
PRINT " 4. PLAY YARD"
PRINT
INPUT "SELECT A SECONDARY DESCRIPTIVE NAME FOR YOUR PART OR ENTER YOUR OWN"; DES.2$
SELECT CASE DES.2$
CASE "1"
NAME.2$ = "STROLLER"
CASE "2"
NAME.2$ = "HIGH CHAIR"
CASE "3"
NAME.2$ = "SWING"
CASE "4"
NAME.2$ = "PNP"
CASE ELSE
NAME.2$ = DES.2$
END SELECT
CLS
PRINT
PRINT " 1. FOLD"
PRINT " 2. SUPPORT"
PRINT " 3. SWIVEL"
PRINT " 4. RECLINE"
PRINT
INPUT "SELECT A LOCATION FOR THE HOUSING OR ENTER A DESCRIPTIVE AREA OF YOUR OWN"; DES.3$
SELECT CASE DES.3$
CASE "1"
NAME.3$ = "FOLD"
CASE "2"
NAME.3$ = "SUPPORT"
CASE "3"
NAME.3$ = "SWIVEL"
CASE "4"
NAME.3$ = "RECLINE"
CASE ELSE
NAME.3$ = DES.3$
END SELECT
GOTO NAME.VERIFY.WIZ

WHEEL.WIZ:
CLS
PRINT
PRINT " 1. STROLLER"
PRINT " 2. HIGH CHAIR"
PRINT " 3. PLAY YARD"
PRINT
INPUT "SELECT A SECONDARY DESCRIPTIVE NAME FOR YOUR PART OR ENTER YOUR OWN"; DES.2$
SELECT CASE DES.2$
CASE "1"
NAME.2$ = "STROLLER"
CASE "2"
NAME.2$ = "HIGH CHAIR"
CASE "3"
NAME.2$ = "PLAY YARD"
CASE ELSE
NAME.2$ = DES.2$
END SELECT
CLS
PRINT
PRINT " 1. 6"
PRINT " 2. 7"
PRINT " 3. 8"
PRINT " 4. 8.5"
PRINT
INPUT "SELECT A DIAMETER FOR THE WHEEL OR ENTER A DIAMETER OF YOUR OWN"; DES.3$
SELECT CASE DES.3$
CASE "1"
NAME.3$ = "6"
CASE "2"
NAME.3$ = "7"
CASE "3"
NAME.3$ = "8"
CASE "4"
NAME.3$ = "8.5"
CASE ELSE
NAME.3$ = DES.3$
END SELECT
GOTO NAME.VERIFY.WIZ

OWN.WIZ.1:
CLS
PRINT
PRINT " 1. BEDRAILS"
PRINT " 2. BOUNCERS"
PRINT " 3. CARSEATS"
PRINT " 4. HIGH CHAIRS"
PRINT " 5. HOOK ON CHAIRS"
PRINT " 6. JUMPERS"
PRINT " 7. PNP"
PRINT " 8. STROLLERS"
PRINT " 9. WALKERS AND ENTERTAINERS"
PRINT
INPUT "SELECT A SECONDARY DESCRIPTIVE NAME FOR YOUR PART OR ENTER YOUR OWN"; DES.2$
SELECT CASE DES.2$
CASE "1"
NAME.2$ = "BEDRAIL"
CASE "2"
NAME.2$ = "BOUNCER"
CASE "3"
NAME.2$ = "CARSEAT"
CASE "4"
NAME.2$ = "HIGH CHAIR"
CASE "5"
NAME.2$ = "HOOK ON CHAIR"
CASE "6"
NAME.2$ = "JUMPER"
CASE "7"
NAME.2$ = "PLAY YARD"
CASE "8"
NAME.2$ = "STROLLER"
CASE "9"
NAME.2$ = "WALKER - ENTERTAINER"
CASE ELSE
NAME.2$ = DES.2$
END SELECT
CLS
INPUT "ENTER A LOCATION FOR THE PART"; DES.3$
NAME.3$ = DES.3$
GOTO NAME.VERIFY.WIZ

NAME.VERIFY.WIZ:
S$ = "-"
CLS
PRINT
PRINT "NEW PART NAME : "; NAME.1$; "-"; NAME.2$; "-"; NAME.3$
PRINT
PRINT "IS THIS INFORMATION CORRECT (y/n)"
DO
KEY$ = INKEY$
IF KEY$ = "y" OR KEY$ = "Y" THEN
LG.PNAME$ = NAME.1$ + S$ + NAME.2$ + S$ + NAME.3$
GOTO NAMEVERIFY
END IF
IF KEY$ = "n" OR KEY$ = "N" THEN
GOTO NAME.WIZARD
END IF
LOOP WHILE KEY$ < "Y" OR KEY$ > "N"

NAMEVERIFY:
LG.DT$ = DATE$
CLS
PRINT "NAME : "; LG.PERNAME$
PRINT
PRINT "DATE : "; LG.DT$
PRINT
PRINT "PART NAME : "; LG.PNAME$
PRINT
PRINT "PROJECT : "; LG.PRJNAME$
PRINT
PRINT "PROJECT TITLE : "; LG.PRONAME$
PRINT
PRINT "IS THIS INFORMATION CORRECT (y/n)"
DO
KEY$ = INKEY$
IF KEY$ = "y" OR KEY$ = "Y" THEN
GOTO WRITENEW
END IF
IF KEY$ = "n" OR KEY$ = "N" THEN
GOTO NEW.PARTNUMBER
END IF
LOOP WHILE KEY$ < "Y" OR KEY$ > "N"


WRITENEW:
TYPE INFO
PERNAME AS STRING * 10
DT AS STRING * 8
PNAME AS STRING * 35
PRJNAME AS STRING * 12
PRONAME AS STRING * 25
END TYPE

DIM LG AS INFO

OPEN "C:\TEST.DAT" FOR BINARY AS #1
SEEK #1, LOF(1) + 1
PUT #1,, LG
CLOSE#1



Any suggestions or help is greatly appreciated.
Thanks guys.


Title: Confused.
Post by: casonon on June 06, 2003, 12:36:28 PM
Glenn.

Ok I guess that I don't understand what you mean by a user-defined type.  Also I am not clear on why you can't have the $.  I thought that the $ allowed the answer to an input to be a entry other then a numeric answer.  Maybe you can give me an example of what I should have inorder to get this to work.  Sorry for being such a dumbass.  But after 6 years of not doing this, you kind of forget ALOT.  :roll:   But I appreciate everyones help.

Thanks


Title: Well, I'm confused as to why this works, but it does...
Post by: Glenn on June 06, 2003, 12:47:41 PM
You 1) left out a "." in a label containing "part.number" (and I don't understand why all of a sudden QB is allowing "." in labels) and you had a "$" on "LG.PERNAME".  And I also had to move your user-defined type structure to the top (before you use variables in it).  The variable type you're defining with the TYPE INFO structure is a user-defined type.



TYPE INFO
   PERNAME AS STRING * 10
   DT AS STRING * 8
   PNAME AS STRING * 35
   PRJNAME AS STRING * 12
   PRONAME AS STRING * 25
END TYPE

DIM LG AS INFO
OPTION.PAGE:
CLS
PRINT TAB(25); "IRON MOUNTAIN PART LOG"
PRINT
PRINT "1. OBTAIN NEW PART NUMBER"
PRINT "2. SEARCH PART LOG"
PRINT "3. VIEW ENTIRE PROJECT PART LOG"
DO
   KEY$ = INKEY$
LOOP WHILE KEY$ < "1" OR KEY$ > "4"

SELECT CASE KEY$
   CASE "1"
      GOTO NEW.PART.NUMBER
   CASE "2"
      CLS
      PRINT "2 WORKS"
   CASE "3"
      CLS
      PRINT "3 WORKS"
END SELECT

NEW.PART.NUMBER:
CLS
INPUT "PLEASE ENTER YOUR INITALS"; LG.PERNAME
CLS
PRINT
PRINT "SELECT A PROJECT"
PRINT
PRINT " 1. BEDRAILS"
PRINT " 2. BOUNCERS"
PRINT " 3. CARSEATS"
PRINT " 4. HIGH CHAIRS"
PRINT " 5. HOOK ON CHAIRS"
PRINT " 6. JUMPERS"
PRINT " 7. PNP"
PRINT " 8. STROLLERS"
PRINT " 9. WALKERS AND ENTERTAINERS"
DO
   KEY$ = INKEY$
LOOP WHILE KEY$ < "1" OR KEY$ > "9"

SELECT CASE KEY$
   CASE "1"
      LG.PRJNAME$ = "BEDRAILS"
   CASE "2"
      LG.PRJNAME$ = "BOUNCERS"
   CASE "3"
      LG.PRJNAME$ = "CARSEATS"
   CASE "4"
      LG.PRJNAME$ = "HIGH CHAIRS"
   CASE "5"
      LG.PRJNAME$ = "HOOK ON CHAIRS"
   CASE "6"
      LG.PRJNAME$ = "JUMPERS"
   CASE "7"
      LG.PRJNAME$ = "PLAY YARDS"
   CASE "8"
      LG.PRJNAME$ = "STROLLERS"
   CASE "9"
      LG.PRJNAME$ = "WALKERS & ENTERTAINERS"
END SELECT

CLS
INPUT "ENTER THE TITLE OF THE PROJECT"; LG.PRONAME$
CLS
PRINT
PRINT " 1. ENTER YOUR OWN PART NAME"
PRINT " 2. USE NAME WIZARD"
DO
   KEY$ = INKEY$
LOOP WHILE KEY$ < "1" OR KEY$ > "2"

SELECT CASE KEY$
   CASE "1"
      GOTO NAMING
   CASE "2"
      GOTO NAME.WIZARD
END SELECT

NAMING:
CLS
INPUT "ENTER THE NAME FOR YOUR PART"; LG.PNAME$
GOTO NAMEVERIFY

NAME.WIZARD:
CLS
PRINT
PRINT " 1. TUBE"
PRINT " 2. TRAY"
PRINT " 3. HOUSING"
PRINT " 4. WHEEL"
PRINT
INPUT "SELECT A PRIMARY DESCRIPTIVE NAME FOR YOUR PART"; DES.1$
   SELECT CASE DES.1$
      CASE "1"
         NAME.1$ = "TUBE"
         GOTO TUBE.WIZ
      CASE "2"
         NAME.1$ = "TRAY"
         GOTO TRAY.WIZ
      CASE "3"
         NAME.1$ = "HOUSING"
         GOTO HOUS.WIZ
      CASE "4"
         NAME.1$ = "WHEEL"
         GOTO WHEEL.WIZ
      CASE ELSE
         NAME.1$ = DES.1$
         GOTO OWN.WIZ.1
   END SELECT
END

TUBE.WIZ:
CLS
PRINT
PRINT " 1. STROLLER"
PRINT " 2. HIGH CHAIR"
PRINT " 3. SWING"
PRINT " 4. PLAY YARD"
PRINT
INPUT "SELECT A SECONDARY DESCRIPTIVE NAME FOR YOUR PART OR ENTER YOUR OWN"; DES.2$
   SELECT CASE DES.2$
      CASE "1"
         NAME.2$ = "STROLLER"
      CASE "2"
         NAME.2$ = "HIGH CHAIR"
      CASE "3"
         NAME.2$ = "SWING"
      CASE "4"
         NAME.2$ = "PNP"
      CASE ELSE
         NAME.2$ = DES.2$
   END SELECT
CLS
PRINT
PRINT " 1. FRONT LEG"
PRINT " 2. REAR LEG"
PRINT " 3. BASKET TUBE"
PRINT " 4. CROSS TUBE"
PRINT
INPUT "SELECT A LOCATION FOR THE TUBE OR ENTER A DESCRIPTIVE AREA OF YOUR OWN"; DES.3$
   SELECT CASE DES.3$
      CASE "1"
         NAME.3$ = "FRONT LEG"
      CASE "2"
         NAME.3$ = "REAR LEG"
      CASE "3"
         NAME.3$ = "BASKET TUBE"
      CASE "4"
         NAME.3$ = "CROSS TUBE"
      CASE ELSE
         NAME.3$ = DES.3$
   END SELECT
   GOTO NAME.VERIFY.WIZ

TRAY.WIZ:
CLS
PRINT
PRINT " 1. HIGH CHAIR"
PRINT " 2. STROLLER"
PRINT " 3. SWING"
PRINT
INPUT "SELECT A SECONDARY DESCRIPTIVE NAME FOR YOUR PART OR ENTER YOUR OWN"; DES.2$
   SELECT CASE DES.2$
      CASE "1"
         NAME.2$ = "HIGH CHAIR"
      CASE "2"
         NAME.2$ = "STROLLER"
      CASE "3"
         NAME.2$ = "SWING"
      CASE ELSE
         NAME.2$ = DES.2$
   END SELECT
CLS
PRINT
PRINT " 1. PARENT"
PRINT " 2. CHILD"
PRINT " 3. PLAY"
PRINT " 4. TOY"
PRINT
INPUT "SELECT A LOCATION FOR THE TRAY OR ENTER A DESCRIPTIVE AREA OF YOUR OWN"; DES.3$
   SELECT CASE DES.3$
      CASE "1"
         NAME.3$ = "PARENT"
      CASE "2"
         NAME.3$ = "CHILD"
      CASE "3"
         NAME.3$ = "PLAY"
      CASE "4"
         NAME.3$ = "TOY"
      CASE ELSE
         NAME.3$ = DES.3$
   END SELECT
   GOTO NAME.VERIFY.WIZ

HOUS.WIZ:
CLS
PRINT
PRINT " 1. STROLLER"
PRINT " 2. HIGH CHAIR"
PRINT " 3. SWING"
PRINT " 4. PLAY YARD"
PRINT
INPUT "SELECT A SECONDARY DESCRIPTIVE NAME FOR YOUR PART OR ENTER YOUR OWN"; DES.2$
   SELECT CASE DES.2$
      CASE "1"
         NAME.2$ = "STROLLER"
      CASE "2"
         NAME.2$ = "HIGH CHAIR"
      CASE "3"
         NAME.2$ = "SWING"
      CASE "4"
         NAME.2$ = "PNP"
      CASE ELSE
         NAME.2$ = DES.2$
   END SELECT
CLS
PRINT
PRINT " 1. FOLD"
PRINT " 2. SUPPORT"
PRINT " 3. SWIVEL"
PRINT " 4. RECLINE"
PRINT
INPUT "SELECT A LOCATION FOR THE HOUSING OR ENTER A DESCRIPTIVE AREA OF YOUR OWN"; DES.3$
   SELECT CASE DES.3$
      CASE "1"
         NAME.3$ = "FOLD"
      CASE "2"
         NAME.3$ = "SUPPORT"
      CASE "3"
         NAME.3$ = "SWIVEL"
      CASE "4"
         NAME.3$ = "RECLINE"
      CASE ELSE
         NAME.3$ = DES.3$
   END SELECT
   GOTO NAME.VERIFY.WIZ

WHEEL.WIZ:
CLS
PRINT
PRINT " 1. STROLLER"
PRINT " 2. HIGH CHAIR"
PRINT " 3. PLAY YARD"
PRINT
INPUT "SELECT A SECONDARY DESCRIPTIVE NAME FOR YOUR PART OR ENTER YOUR OWN"; DES.2$
   SELECT CASE DES.2$
      CASE "1"
         NAME.2$ = "STROLLER"
      CASE "2"
         NAME.2$ = "HIGH CHAIR"
      CASE "3"
         NAME.2$ = "PLAY YARD"
      CASE ELSE
         NAME.2$ = DES.2$
   END SELECT
CLS
PRINT
PRINT " 1. 6"
PRINT " 2. 7"
PRINT " 3. 8"
PRINT " 4. 8.5"
PRINT
INPUT "SELECT A DIAMETER FOR THE WHEEL OR ENTER A DIAMETER OF YOUR OWN"; DES.3$
   SELECT CASE DES.3$
      CASE "1"
         NAME.3$ = "6"
      CASE "2"
         NAME.3$ = "7"
      CASE "3"
         NAME.3$ = "8"
      CASE "4"
         NAME.3$ = "8.5"
      CASE ELSE
         NAME.3$ = DES.3$
   END SELECT
   GOTO NAME.VERIFY.WIZ

OWN.WIZ.1:
CLS
PRINT
PRINT " 1. BEDRAILS"
PRINT " 2. BOUNCERS"
PRINT " 3. CARSEATS"
PRINT " 4. HIGH CHAIRS"
PRINT " 5. HOOK ON CHAIRS"
PRINT " 6. JUMPERS"
PRINT " 7. PNP"
PRINT " 8. STROLLERS"
PRINT " 9. WALKERS AND ENTERTAINERS"
PRINT
INPUT "SELECT A SECONDARY DESCRIPTIVE NAME FOR YOUR PART OR ENTER YOUR OWN"; DES.2$
   SELECT CASE DES.2$
      CASE "1"
         NAME.2$ = "BEDRAIL"
      CASE "2"
         NAME.2$ = "BOUNCER"
      CASE "3"
         NAME.2$ = "CARSEAT"
      CASE "4"
         NAME.2$ = "HIGH CHAIR"
      CASE "5"
         NAME.2$ = "HOOK ON CHAIR"
      CASE "6"
         NAME.2$ = "JUMPER"
      CASE "7"
         NAME.2$ = "PLAY YARD"
      CASE "8"
         NAME.2$ = "STROLLER"
      CASE "9"
         NAME.2$ = "WALKER - ENTERTAINER"
      CASE ELSE
         NAME.2$ = DES.2$
   END SELECT
CLS
INPUT "ENTER A LOCATION FOR THE PART"; DES.3$
   NAME.3$ = DES.3$
   GOTO NAME.VERIFY.WIZ

NAME.VERIFY.WIZ:
S$ = "-"
CLS
PRINT
PRINT "NEW PART NAME : "; NAME.1$; "-"; NAME.2$; "-"; NAME.3$
PRINT
PRINT "IS THIS INFORMATION CORRECT (y/n)"
DO
   KEY$ = INKEY$
   IF KEY$ = "y" OR KEY$ = "Y" THEN
      LG.PNAME$ = NAME.1$ + S$ + NAME.2$ + S$ + NAME.3$
      GOTO NAMEVERIFY
   END IF
   IF KEY$ = "n" OR KEY$ = "N" THEN
      GOTO NAME.WIZARD
   END IF
LOOP WHILE KEY$ < "Y" OR KEY$ > "N"

NAMEVERIFY:
LG.DT$ = DATE$
CLS
PRINT "NAME : "; LG.PERNAME
PRINT
PRINT "DATE : "; LG.DT$
PRINT
PRINT "PART NAME : "; LG.PNAME$
PRINT
PRINT "PROJECT : "; LG.PRJNAME$
PRINT
PRINT "PROJECT TITLE : "; LG.PRONAME$
PRINT
PRINT "IS THIS INFORMATION CORRECT (y/n)"
DO
   KEY$ = INKEY$
   IF KEY$ = "y" OR KEY$ = "Y" THEN
      GOTO WRITENEW
   END IF
   IF KEY$ = "n" OR KEY$ = "N" THEN
      GOTO NEW.PART.NUMBER
   END IF
LOOP WHILE KEY$ < "Y" OR KEY$ > "N"


WRITENEW:

OPEN "C:\TEST.DAT" FOR BINARY AS #1
   SEEK #1, LOF(1) + 1
   PUT #1,, LG
CLOSE#1


Title: THANKS
Post by: casonon on June 06, 2003, 12:57:42 PM
THANK YOU....
I got it to do part of what I wanted.  Now this weekend I need to see if I can get it to search the file.  I REALLY appreciate all the help.
I am sure I will have more questions.

Chris


Title: No problem...
Post by: Glenn on June 06, 2003, 02:09:32 PM
Incidentally, instead of

SEEK #1, LOF(1) + 1
PUT #1,, LG

You can just do

PUT#1, LOF(1) +1, LG

Or if you're writing data sequentially, beginning at the beginning of the file, you can just do

PUT#1,, LG

and forget SEEK or explicitly specifying where to write to altogether.  (PUT# and GET# always by default start at the beginning of the file and then move the file pointer to the byte position after the data written or read.)


Title: Another Question - File opening and writing
Post by: Phydaux on June 07, 2003, 05:37:18 AM
Quote from: "casonon"
Glenn.

Ok I guess that I don't understand what you mean by a user-defined type.  Also I am not clear on why you can't have the $.  I thought that the $ allowed the answer to an input to be a entry other then a numeric answer.  Maybe you can give me an example of what I should have inorder to get this to work.  Sorry for being such a dumbass.  But after 6 years of not doing this, you kind of forget ALOT.  :roll:   But I appreciate everyones help.

Thanks
Just to try and help clear up your understanding of types.
    QBASIC has 5 pre-defined types:
  • Integer - A numeric value, with no decimal point.
  • Long Integer - Like an integer, but with a larger range.
  • Single Precision - A numeric value, with a decimal point.
  • Double Precision - Like a single precision, but with a larger range.
  • String - A string of characters.
A variable can be any of these types, but with QBASIC's loose aproach to programming, you don't have to pre-define them. You just add a data suffex (%, &, !, #, $) e.g. lives%, address$.

You don't have to add a suffex on the end at all you could just predefine the variable using DIM.
E.G.
Code:
DIM myname AS STRING

You could then use myname the same way you would normaly use myname$.


The TYPE statement makes new data types from existing ones.
e.g.
Code:
TYPE  card
   suit AS STRING * 7
   value AS INTEGER
END TYPE


we now have the data type card as well as the existing ones, integer, single, string etc... but there is no data suffex for card so to define a variable as a card data type, we use DIM
Code:
DIM deck(1 TO 52) AS card


Only now instead of writing information to the deck() variable, we need to use the dot-operator (.) to say which part of the user-defined type we are writing to.
e.g. to make card 1 the Ace of Spades
Code:
deck(1).suit = "Spade"
deck(1).value = 1


I really hope this helps, and doesn't confuse the matter more.


Title: "Qbasic 5"? (And I thought "Qbasic 4.5"
Post by: Glenn on June 07, 2003, 11:59:09 AM
enough of a misnomer.)


Title: Another Question - File opening and writing
Post by: toonski84 on June 07, 2003, 12:03:36 PM
I think he meant QBasic has 5, not QBasic 5, though the runtime file in qbasic.exe is brun50.lib (or bcom50.lib, i can't remember).


Title: What "runtime file"...
Post by: Glenn on June 07, 2003, 12:39:55 PM
for QBASIC.EXE?  The runtime libraries for QB 4.5 are in BCOM45.EXE.