In need of help (Using QB4.5) - READ!
Author Message
In need of help (Using QB4.5) - READ!

How can I cut a variable string into sections of 9 or less?? please

Mon, 04 Dec 2000 03:00:00 GMT
In need of help (Using QB4.5) - READ!

Quote:

>How can I cut a variable string into sections of 9 or less?? please

DIM Str AS STRING, Part(1 TO 9) AS STRING
DIM LStr AS INTEGER, LPart AS INTEGER, NbrParts AS INTEGER, Ptr AS INTEGER

INPUT "Enter string: ", Str

LStr = LEN(Str)         ' ** Divide Str into 9 or less Parts **
LPart = LStr \ 9
IF (LPart * 9 < LStr) THEN LPart = LPart + 1
NbrParts = 0: Ptr = 1
WHILE (LStr > 0)
NbrParts = NbrParts + 1
Part(NbrParts) = MID\$(Str, Ptr, LPart)
Ptr = Ptr + LPart
LStr = LStr - LPart
WEND

FOR I% = 1 TO NbrParts   ' ** Show Result **
PRINT I%; Part(I%)
NEXT
END
--
Judson McClendon          This is a faithful saying and worthy of all
Sun Valley Systems        acceptance, that Christ Jesus came into the

(please remove numbers from email id to respond)

Mon, 04 Dec 2000 03:00:00 GMT
In need of help (Using QB4.5) - READ!

|> How can I cut a variable string into sections of 9 or less??

You'll need to use the MID\$ function. (Don't confuse this
with the MID\$ statement that is used on the LEFT side of
the "=".)

Example of MID\$ function:

A\$ = "This is a test."
B\$ = MID\$(A\$, 2, 9)    'makes B\$ = "his is a "

You'll probably want to call MID\$ in a loop, so you'll need
to establish a criterion for breaking out of the loop when
you're done breaking up the string.

If you want to store the sections and use them later, DIM
an array for them. You can figure out how big to make the
array by getting the LEN of the original string, and
calculating how many sections of 9 or less it contains.

Since your question could easily be a homework assignment,
I'll leave the rest up to you. Look up MID\$, LEN, DIM
and maybe FOR/NEXT and DO/LOOP in the help system. For extra
credit, play around with MOD and integer division (\ instead of /).

--
Brian McLaughlin, Technical Writer  |"Thanks to the Internet, misinformation
Integrated Measurement Systems, Inc.| now travels faster than ever before!"
Beaverton, OR, USA                  | ---- Standard disclaimer applies ----

Mon, 04 Dec 2000 03:00:00 GMT

 Page 1 of 1 [ 3 post ]

Relevant Pages