Weekly Qbasic and Qb64 Lesson Topics
March 28, 2024, 02:50:45 pm
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Want to see a specific Tutorial? ASK!
 
  Home Help Search Arcade Links Staff List Login Register  

Opens Notepad,but need to know more

Pages: 1 [2]
  Print  
Author Topic: Opens Notepad,but need to know more  (Read 1927 times)
guest
Guest
« Reply #15 on: May 12, 2011, 04:41:37 pm »


    Garry here is another finished example that synchronises the pictures with the text. I think that is what you originally wanted. I cleared the screen to solve the problem of deleting the displayed text. Note a few changes
1] Line Input <-- allows commas to be read as part of the line and not a break in the line
2] Original dim now is reduced by 1 as array elements start at zero and not at one as expected
3]  New text file . Removed a blank line
4] This will fail if the line of text is too long.

    One of the reasons this seemed hard was that you cut and pasted code that didnt fit correctly together. I decided to simplify so that you have an example. Please note that the select case that decides the picture to display is HARD coded to a file of 5 lines. If you wanted to use another file of different length then you will have to add or subtract from the gosub.

Quote
This is a story about 4 men.
Bob-- Ths is BOB "hello nice to meet you."
Jim-- All he dose is sit and think all day, he never speaks and so we still do not know what it is he is thinking.
Joe-- He is half indian, and always likes to dance
Pete--Pete always likes to play soccer.
Here's the code
Code:
DEFLNG A-Z

SCREEN _NEWIMAGE(640, 480, 32) '<- what the observer sees
WorkPage& = _LOADIMAGE("4men.png") '<- all the graphics

CLS
_DEST 0 '<- point to the observer screen
GOSUB MakPhrases 'get the amount of lines so we can make a dim to gather them

LOCATE 2, 10
PRINT "THIS IS A STORY ABOUT 4 MEN "
Whatone% = 0 '<- set variable to zero


RRow% = 15: CColumn% = 20: z% = 0: Pause! = .050 'needed for the showtext routine

DO
  GOSUB Showpic 'sync pic with text
  RRow% = 15: CColumn% = 1
  GOSUB Showtext 'show text with the effect
  Dummy$ = INPUT$(1) 'wait for keypress
  CLS
  LOCATE 20, 10: PRINT " press + hold escape to exit or any key to contimue"
  GOSUB Pickphrase 'get next phrase
LOOP UNTIL _KEYDOWN(27)
SYSTEM
END
'--------------------------------------------------------------------------
Showpic:
SELECT CASE Whatone%
  CASE 0

  CASE 1
    x = 0
    _PUTIMAGE (100, 100)-(220, 190), WorkPage&, 0, (x, 0)-(x + 67, 67)
  CASE 2
    x = 67
    _PUTIMAGE (100, 100)-(220, 190), WorkPage&, 0, (x, 0)-(x + 67, 67)
  CASE 3
    x = 134
    _PUTIMAGE (100, 100)-(220, 190), WorkPage&, 0, (x, 0)-(x + 67, 67)
  CASE 4
    x = 201
    _PUTIMAGE (100, 100)-(220, 190), WorkPage&, 0, (x, 0)-(x + 67, 67)
END SELECT
RETURN

Showtext:
z% = 0
Length% = LEN(Textprn$)
FOR a = 1 TO Length%
  LOCATE RRow%, CColumn% + z% '
  PRINT MID$(Textprn$, a, 1)
  z% = z% + 1
  IF CColumn% + z% >= 79 THEN
    RRow% = RRow% + 1
    CColumn% = CColumn% - 60
  END IF
  _DELAY Pause!
NEXT a
RETURN

MakPhrases:
maxlines& = 0
ThisFile% = FREEFILE 'get next free file handle must be integer
OPEN "4men.txt" FOR INPUT AS #ThisFile%
DO
  INPUT #ThisFile%, temp$
  maxlines& = maxlines& + 1
LOOP WHILE NOT EOF(ThisFile%)
temp$ = "" 'dump contents of string
CLOSE #ThisFile%
'check maxlines to make sure file is not empty
IF maxlines& <> 0 THEN
  DIM Phrases$(maxlines& - 1) 'note arrys start at element zero not ONE as expected!!!
  GOSUB FillDim 'read individual phrases into the string dim
ELSE
  PRINT "File not found": _DELAY 3: END
END IF
_DELAY .5

RETURN

FillDim:
maxlines& = 0
ThisFile% = FREEFILE 'get next free file handle must be integer
OPEN "4men.txt" FOR INPUT AS #ThisFile%
DO
  LINE INPUT #ThisFile%, temp$
  Phrases$(maxlines&) = temp$
  maxlines& = maxlines& + 1
LOOP WHILE NOT EOF(ThisFile%)
temp$ = "" 'dump contents of string
CLOSE #ThisFile%
RETURN

Pickphrase:
Whatone% = Whatone% + 1
IF Whatone% > maxlines& - 1 THEN Whatone% = 0
Textprn$ = Phrases$(Whatone%)
RETURN

« Last Edit: March 24, 2012, 05:05:59 pm by GarrisonRicketson » Report Spam   Logged

Pages: 1 [2]
  Print  
 
Jump to:  

Powered by EzPortal
Bookmark this site! | Upgrade This Forum
SMF For Free - Create your own Forum


Powered by SMF | SMF © 2016, Simple Machines
Privacy Policy