Qbasicnews.com
April 04, 2020, 08:34:17 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1] 2 3
  Print  
Author Topic: Looking for a Command.  (Read 7136 times)
Licentia
Member
*
Posts: 57



« on: October 12, 2004, 08:02:23 PM »

I'm looking for a command.  It's the command for opening a string variable and dividing it into several variables.  I have looked yesterday and today through several tutorials for that command and i'm not finding it, nor can I find the website with the big Qbasic Advanced commands list.  It was an awesome list.

  Does anyone know the command I am refering to?  I think it starts with an M.  It's like mcg or something.  And does anyone know the website of that QBasic Advanced commands list?  It has the commands, and then you can click on most of them and then it gives instructions on how the command works.
Logged
Z!re
*/-\*
*****
Posts: 4599


« Reply #1 on: October 12, 2004, 08:11:45 PM »

Code:
MID$()
Logged
Licentia
Member
*
Posts: 57



« Reply #2 on: October 12, 2004, 08:39:39 PM »

Quote from: "Z!re"
Code:
MID$()


  So easy to find info on a command when you know what the command is.  Thanks!
Logged
Crono
Member
*
Posts: 65



WWW
« Reply #3 on: October 13, 2004, 06:24:11 AM »

Here: http://forum.qbasicnews.com/viewtopic.php?t=6991

I hope its usefull to ya, kinda looks like the same question
Logged
whitetiger0990
__/--\__
*****
Posts: 2964



WWW
« Reply #4 on: October 13, 2004, 08:31:22 AM »

Quote from: "Licentia"
And does anyone know the website of that QBasic Advanced commands list?  It has the commands, and then you can click on most of them and then it gives instructions on how the command works.


Both in the qbasic help and http://qbasicnews.com/qboho/
Logged


[size=10]Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.[/size]
TheBigBasicQ
*/-\*
*****
Posts: 4550



WWW
« Reply #5 on: October 13, 2004, 01:19:46 PM »

do you want to tokenize the string? i.e. break it up into small words?

For example:
s$ = "hi this is some string"

tokenize(s$) would break up the string into:

hi

this

is

some

string
Logged
Oz
I hold this place together
*****
Posts: 923



« Reply #6 on: October 13, 2004, 05:29:11 PM »

[syntax="qbasic"]' A slightly more `workable` example

CLS

'Get 2 variables
INPUT "String: ", string1$
INPUT "Sub-string:", substring1$

'make them lower case.....jsut to be safe
string1$ = lcase$(string1$)
substring1$ = lcase$(substring1$)

'Find the substring....will return 0 if it isn't in the original string
'If it is there, it will tell you where it is located (index)
location% = INSTR(string1$, substring1$)

IF location% > 1 THEN

 'Get the length of the substring
 l% = len(substring1$)

 'Get a copy of the substring
 a$ = MID$(string1$, location%, l%)

 'This should be equal, but I'm just going to be thorough because I can be
 IF substring1$ = a$ THEN
  PRINT "Found "; substring1$; " in "; string1$
 END IF

END IF

'I hate using END but if im going to give an example, I should probably be thorough about it
END[/syntax]

Oz~
Logged
Licentia
Member
*
Posts: 57



« Reply #7 on: October 14, 2004, 08:22:51 PM »

Quote from: "TheBigBasicQ"
do you want to tokenize the string? i.e. break it up into small words?

For example:
s$ = "hi this is some string"

tokenize(s$) would break up the string into:

hi

this

is

some

string


  Yeah, I think that's what I want.  Basically I am trying to make lottery programs.  Here is a combo example:

  12 24 36 39 42 47

  I can get Qbasic to open that from a text file, but each combination becomes a single variable.  What I want then is to open the variable and divide the numbers into different variables.  12 - a 24 - b 36 - c 39 - d etc.

  I don't think the MID command will do that, now that i've looked at it a little.  I'll research the tokenize command.  Thanks.
Logged
Oz
I hold this place together
*****
Posts: 923



« Reply #8 on: October 14, 2004, 10:18:42 PM »

tokenize isn't a built in command....

TBBQ was suggesting using the MID$() command in a subroutine to find what you want

Oz~
Logged
Oz
I hold this place together
*****
Posts: 923



« Reply #9 on: October 14, 2004, 10:34:36 PM »

[syntax="qbasic"]
DECLARE FUNCTION num%(info AS STRING)
DECLARE FUNCTION find.word$(info AS STRING, index AS INTEGER)

blarg$="24 59 14 62 0"

number% = num%(blarg$)

FOR i% = 1 TO number%

 PRINT find.word$(blarg$, i%)

NEXT i%

FUNCTION num%(info AS STRING)

l% = LEN(info)

FOR a% = 1 TO l%
 temp$ = MID$(info, a%, 1)
 IF temp$ = " " THEN num% = num% + 1
NEXT

END FUNCTION

FUNCTION find.word$(info AS STRING, index AS INTEGER)

l% = LEN(info)

FOR a% = 1 TO l%

 temp$ = MID$(info, a%, 1)
 IF temp$ = " " THEN pl% = pl% + 1

 IF pl% = index THEN
  FOR b% = 1 TO (l% - a%)
   c$ = MID$(info, b%, 1)
   IF c$ = " " THEN
    find.word$ = MID$(info, a%, b%)
    EXIT FUNCTION
   END IF
  NEXT b%
 END IF

NEXT a%

END FUNCTION

[/syntax]

I think that pretty code should do the work nicely

Oz~
Logged
TheBigBasicQ
*/-\*
*****
Posts: 4550



WWW
« Reply #10 on: October 17, 2004, 09:00:17 AM »

i dunno why you guyz got confused about my 'tokenize' question o.O

licentia heres a sample code which tokenizes a given string. You will have to modify it to make it a function Wink.

[syntax="qbasic"]CLS

s$ = "I r teh 1337 sentence"

DO
    ps% = INSTR(s$, " ")

    IF INSTR(s$, " ") = 0 THEN
        PRINT s$
        EXIT DO
    ELSE
        PRINT LEFT$(s$, ps% - 1)
    END IF

    s$ = RIGHT$(s$, LEN(s$) - ps%)
LOOP
[/syntax]
Logged
Licentia
Member
*
Posts: 57



« Reply #11 on: October 18, 2004, 02:20:02 PM »

Quote from: "whitetiger0990"
Quote from: "Licentia"
And does anyone know the website of that QBasic Advanced commands list?  It has the commands, and then you can click on most of them and then it gives instructions on how the command works.


Both in the qbasic help and http://qbasicnews.com/qboho/


  This is awesome.  http://qbasicnews.com/qboho/qck-9997.shtml

  That must be like every command.  I've never seen half of them.
Logged
Licentia
Member
*
Posts: 57



« Reply #12 on: October 18, 2004, 02:32:13 PM »

Quote from: "TheBigBasicQ"
i dunno why you guyz got confused about my 'tokenize' question o.O

licentia heres a sample code which tokenizes a given string. You will have to modify it to make it a function Wink.

[syntax="qbasic"]CLS

s$ = "I r teh 1337 sentence"

DO
    ps% = INSTR(s$, " ")

    IF INSTR(s$, " ") = 0 THEN
        PRINT s$
        EXIT DO
    ELSE
        PRINT LEFT$(s$, ps% - 1)
    END IF

    s$ = RIGHT$(s$, LEN(s$) - ps%)
LOOP
[/syntax]


  I don't understand it, but thanks.  It works great!  I'll figure it out.

  Thanks to all the other people who've helped.
Logged
adosorken
*/-\*
*****
Posts: 3655



WWW
« Reply #13 on: October 18, 2004, 02:48:41 PM »

Licentia: it works by seperating the string into pieces by way of splitting them at the spaces. The INSTR$ function finds the spaces and uses the value to know where to split up the string. It's pretty easy once you get the hang of the basics. Cheesy
Logged

I'd knock on wood, but my desk is particle board.
Licentia
Member
*
Posts: 57



« Reply #14 on: October 18, 2004, 08:59:27 PM »

Quote from: "adosorken"
Licentia: it works by seperating the string into pieces by way of splitting them at the spaces. The INSTR$ function finds the spaces and uses the value to know where to split up the string. It's pretty easy once you get the hang of the basics. Cheesy


  Thanks for that clarification.  It definitely helps.
Logged
Pages: [1] 2 3
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!