Qbasicnews.com

Full Version: Help with MID$ and LEN
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi.

- I got two SUB's, one that writes out a message in the shape of a string called text$ (SUB PrintMsg) and one that creates this string (SUB MsgWriting).

- The string can be as long as 8 x 50 characters, defending on how many enemies that hits you at the same time ( from 1 to 8 enemies can strike the player at the same time).

- I wan't the program to display each enemy-attack per line (one line of information, then PressAnyKey and then the next enemy-attack and so on).

- Right now, I've tried to make it so each enemy-attack-text-message get's 50 character (the engine adds spaces until the message reached 50 character)


Code below: Both SUB's have been cuted, but they display what's needed. And yes, mmonattacktext$ = text$

Code:
SUB printmsg (text$)

LOCATE 1, 1: PRINT SPACE$(79)

IF LEN(text$) < 79 THEN                                                      
LOCATE 1, 1: PRINT text$                                                  
ELSE                                                                        
                                                                            
textstart = 1                                                          
textlenght = 50                                                            

FOR x = 1 TO LEN(text$) / 50                                                  
showtext$ = MID$(text$, textstart, 50)                              
LOCATE 1, 1: PRINT showtext$ + " -more-": pak: LOCATE 1, 1: PRINT SPACE$(79)
textstart = textstart + 50                                                  
NEXT x                                                                      
                                                                          
END IF                                                                      

END SUB


SUB MsgWriting ()

FOR  monnumatt = 1 to numenemies

a$ = RTRIM$(Monster(MonNum).MName)
damage = Rand(MAttacks(MonAttNum).AttackDice, MAttacks(MonAttNum).AttackDice * MAttacks(MonAttNum).AttackSides)

monattacktext$ = a$ + " " + RTRIM$(MAttacks(MonAttNum).AttackDesc) + " you for " + LTRIM$(STR$(damage)) + " damage! "
mmonattacktext$ = mmonattacktext$ + monattacktext$ + SPACE$(50 - LEN(monattacktext$))

      Player.ptemphitpoints = Player.ptemphitpoints - damage

ELSE

a$ = RTRIM$(Monster(MonNum).MName)

   monattacktext$ = a$ + " misses You! "
  mmonattacktext$ = mmonattacktext$ + monattacktext$ + SPACE$(50 - LEN(monattacktext$))

  END IF

  NEXT monnumatt
END IF


END SUB
So what's the problem?

Do you want to take one string and print them with a maximum length? Is that it?
Do you want to actually have a carriage return (enter?)
doh...sorry, I fixed it myself. Sorry again :oops:

The problem I had (and also the thing I forgot to mention) was in the SUB PrintMsg: The code forced the player to PressAnyKey even if the sub was displaying the last 50 character of text from text$.

Anyways, it's fixed...thanks anyway.. *jocke blushes and then walks away in the sunset...* :wink: