Basic

Moderators: None (Apply to moderate this forum)
Number of threads: 1675
Number of posts: 4764

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Qbasic-Array Posted by Hugo2k99 on 22 Apr 2001 at 2:52 PM
I need the user to enter a phrase, every letter of the phrase is to go into an array, which I would then display. The problem is that phrase would include commas and points, but when I type a comma, I get a "redo from start". How can I allow the user to enter commas into the phrase.

This is what I have:

INPUT "Enter a phrase: ", Phrase$
PRINT
Length = LEN(Phrase$)
PRINT Length
DIM Word$(1 TO Length)
FOR Count = 1 TO Length
Letter$ = MID$(Phrase$, Count, 1)
Word$(Count) = Letter$
PRINT Word$(Count);
NEXT Count




Report
Re: Qbasic-Array Posted by Dr. COM WIZ on 22 Apr 2001 at 9:12 PM
: I need the user to enter a phrase, every letter of the phrase is to go into an array, which I would then display. The problem is that phrase would include commas and points, but when I type a comma, I get a "redo from start". How can I allow the user to enter commas into the phrase.
:
: This is what I have:
:
: INPUT "Enter a phrase: ", Phrase$
: PRINT
: Length = LEN(Phrase$)
: PRINT Length
: DIM Word$(1 TO Length)
: FOR Count = 1 TO Length
: Letter$ = MID$(Phrase$, Count, 1)
: Word$(Count) = Letter$
: PRINT Word$(Count);
: NEXT Count
:
: The answer to your question is very simple. I, too had this problem once before when I was 12. Just do this:

LINE INPUT "Enter a phrase: ";Phrase$


LINE INPUT will allow the user to enter any punctuation or symbols. However, LINE INPUT will never prompt the user with a question mark as does INPUT. So, if you're asking the user a question, you must insert the question mark.
:
:


Report
Re: Qbasic-Array Posted by Dr. COM WIZ on 22 Apr 2001 at 9:13 PM
: : I need the user to enter a phrase, every letter of the phrase is to go into an array, which I would then display. The problem is that phrase would include commas and points, but when I type a comma, I get a "redo from start". How can I allow the user to enter commas into the phrase.
: :
: : This is what I have:
: :
: : INPUT "Enter a phrase: ", Phrase$
: : PRINT
: : Length = LEN(Phrase$)
: : PRINT Length
: : DIM Word$(1 TO Length)
: : FOR Count = 1 TO Length
: : Letter$ = MID$(Phrase$, Count, 1)
: : Word$(Count) = Letter$
: : PRINT Word$(Count);
: : NEXT Count
: :
: : The answer to your question is very simple. I, too had this problem once before when I was 12. Just do this:
:
:
: LINE INPUT "Enter a phrase: ";Phrase$
: 

:
: LINE INPUT will allow the user to enter any punctuation or symbols. However, LINE INPUT will never prompt the user with a question mark as does INPUT. So, if you're asking the user a question, you must insert the question mark.
--Dr. COM WIZ
: :
: :
:
:

This has been,
Dr. COM WIZ
PS Thank you and goodnight!


Report
Re: Qbasic-Array (Another way) Posted by BASIC Friend on 23 Apr 2001 at 9:49 AM
: I need the user to enter a phrase, every letter of the phrase is to go into an array, which I would then display. The problem is that phrase would include commas and points, but when I type a comma, I get a "redo from start". How can I allow the user to enter commas into the phrase.
:
: This is what I have:
:
: INPUT "Enter a phrase: ", Phrase$
: PRINT
: Length = LEN(Phrase$)
: PRINT Length
: DIM Word$(1 TO Length)
: FOR Count = 1 TO Length
: Letter$ = MID$(Phrase$, Count, 1)
: Word$(Count) = Letter$
: PRINT Word$(Count);
: NEXT Count
:
:
:
:

What comwiz said. But, I was looking at your code and I realized that you could use a function to simulate an array of characters.(strings are arrays of characters anyways).

I'm writing this on the fly, so there might be a bug or two in it.

FUNCTION CharArray$(a$,n%)
    l% = LEN(a$)
    r$ = ""
    IF NOT n% > l% THEN
        r$ = MID$(a$, n%, 1)
        END IF
    CharArray$ = r$
END FUNCTION

INPUT "Enter a phrase: ", Phrase$
PRINT
Length% = LEN(Phrase$)
PRINT Length%
FOR Count% = 1 TO Length%
    PRINT CharArray$(Phrase$, count%)
NEXT Count%

This only works for getting the element from the string.


Report
Thank you. Posted by Hugo2k99 on 23 Apr 2001 at 1:45 PM
Thanks for the help.




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.