Weekly Qbasic and Qb64 Lesson Topics
October 24, 2017, 06:19:04 am
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 1186 times)
GarrisonRicketson
Admin
Administrator
Hero Member
*****
Posts: 583



WWW
« on: April 11, 2011, 07:30:41 am »

This would be a new , subject ,at least for me, I did this code, not much,
to open note pad, and this text file "open.txt

Code:
  REM Opens notepad, then I want the text in open.txt to display in qb64
CHDIR "C:\Documents and settings\all users"
SHELL "open.txt"
 
However I would also like it to show the text in the file, in the program, after it opens note pad. Hope I make sense ?
from Garry
Report Spam   Logged

Social Buttons

OlDosLover
Guest
« Reply #1 on: April 15, 2011, 08:25:22 am »

Hi all,
    Please explain this idea more Garry. It is a simple matter to create a text file , write to it and close it. It is also easy to open it and read it into a string dim. Usually this is done in your program. It sounds like you wish to do this in the QB64 editor?
OlDosLover.
Report Spam   Logged
GarrisonRicketson
Admin
Administrator
Hero Member
*****
Posts: 583



WWW
« Reply #2 on: April 15, 2011, 07:12:39 pm »

Quote
It is a simple matter to create a text file , write to it and close it. It is also easy to open it and read it into a string dim. Usually this is done in your program.
Ok, well to be honest, not exactly sure, mostly I wanted to explore, this as it is a new process to me,  but yes what I am trying , is to open the textfile, and have the text display in my program, for example, it could be text giveing instructions, to a game, or even the program,... or it could be text explaining about a image, that follows. So for example,  the program might run like this,..
First it opens, the text file and displays the text, then without clearing the screen, it also loads a image, that shows just below the text,  and at the bottom, the hit anykey to continue,  which either would exit, or if I had more text and images, the next one would display.Sort of like a image viewer.
   As I think about this it is giveing me more ideas,...but lets just keep it simple at first,....I guess eventually it could lead to a "story book", the prgram starts with a book (closed), almost full screen, with the title on the Cover, hit any key to continue, when any key is it, the book opens to the first page,  Text: This a story about a turtle , and belwo the text a turtle, any key to continue, opens the second page,...but all that I think later,....
 Also  , but different, if it is possible, to open a file, and add to it, or "edit", but in the program, and save it, that would be interesting, if it is possible, but really it is a simple matter to use note pad, open the file, edit and save it,...or cut and paste it into the qb64 editor, where one can also edit...but that is not really what I was thinking.  
 I am sure if I look hard enough, the information, to do the text and a image is already in one of your tutorials,...Or some where, but guess sort of "lazy", Hee!,
 So ok anyway hope this makes more sense.
Obviously, I could also do something like this:
Code:
  Screen 12
          PRINT " This my text explaining  this pitchure"
          PRINT "And so one, but if there are several lines of text"
          Print " This is not very convient."      
          _ Loadimage ,syntex follows
          _putimage , syntex follows
            Next
CLS
              ' More  text and images
of course this is not really working code, either, but it seens like it  would be easier, if it can open a text file, and display that,  and then Load and put the image below the text, the rest would be easy, because it would just be repeating the same code, but different text files, and images.
 Thanks, from Garry
Take a look at this,:
http://weeklyqbasicandqb64lesson.smfforfree.com/index.php/topic,136.msg712.html#msg712
 it is sort of what I would like to do, but getting the text from a outside file, not haveing it written into the program. In this, since it is just short text it is ok, but if it was a large amount of text, it
seems it would be better to use a outside file , Library ?
« Last Edit: April 16, 2011, 01:29:08 am by OlDosLover » Report Spam   Logged

OlDosLover
Guest
« Reply #3 on: April 16, 2011, 01:27:50 am »

Hi all,
    Oki Garry i understand now. What threw me was your original code that did shell. I'll put together an example for you in the next few days.

OlDosLover.
« Last Edit: April 16, 2011, 01:31:06 am by OlDosLover » Report Spam   Logged
OlDosLover
Guest
« Reply #4 on: April 21, 2011, 10:22:27 am »

Hi all,
    Here's a simple demo that opens an existing file and reads the number of lines inside the file. It then prints them out to the screen.
Code:
DEFLNG A-Z
SCREEN _NEWIMAGE(640, 480, 32)
CLS

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


LOCATE 1, 20
PRINT "There are "; maxlines&; " in this file + here they are"
maxlines& = 0
ThisFile% = FREEFILE 'get next free file handle must be integer

OPEN "message.txt" FOR INPUT AS #ThisFile%
DO
  INPUT #ThisFile%, temp$
  maxlines& = maxlines& + 1
  LOCATE maxlines& + 2, 1
  PRINT temp$
LOOP WHILE NOT EOF(ThisFile%)
temp$ = "" 'dump contents of string
CLOSE #ThisFile%

SLEEP
SYSTEM

Here is the contents of the file. Paste this into notepad and save as message.txt and then place into the qb64 folder.
Quote
I am the ghost comeing to save the world
Hey help me EAT some dots!
Well im waiting for you to do something!
Ghost's  who ya gonna call!
Get me into notepad and i'll eat more!
Well Garry whens Mick gonna give me more!
Nuclear reactors dont scare me!!!
Proton Pills are my favourite foods!

Any questions? If so please ask. Note if you edited the txt file and added a comma then it will display an extra line!
OlDosLover.
« Last Edit: April 21, 2011, 10:24:00 am by OlDosLover » Report Spam   Logged
GarrisonRicketson
Admin
Administrator
Hero Member
*****
Posts: 583



WWW
« Reply #5 on: April 21, 2011, 11:44:02 am »

Ok, thanks, I tried it, and no problem,...now I think I have what I need,
as I allready know how to load a image,...later IŽll show you what I did.
Thanks
from Garry
Report Spam   Logged

OlDosLover
Guest
« Reply #6 on: April 22, 2011, 08:51:20 pm »

Hi all,
    Here's another version that uses your print text across the screen program with a file of text messages to display
Code:
DEFLNG A-Z

SCREEN _NEWIMAGE(640, 480, 32)
WorkPage& = _LOADIMAGE("NEWGHOST_blu1.png")
CLS

GOSUB MakPhrases 'get the amount of lines so we can make a dim to gather them
IF maxlines& <> 0 THEN
  DIM Phrases$(maxlines&)
  GOSUB FillDim 'read individual phrases into the string dim
ELSE
  PRINT "File not found": _DELAY 3: END
END IF
_DELAY .5

_DEST 0
Textprn$ = "Hello World !!!": RRow% = 2: CColumn% = 6: z% = 0: Pause! = .5
GOSUB Showtext
GOSUB Pickphrase
RRow% = 15: CColumn% = 20: z% = 0: Pause! = .050

DO
  FOR x = 0 TO 261 STEP 67
    _PUTIMAGE (100, 100)-(220, 190), WorkPage&, 0, (x, 0)-(x + 67, 67)
    _DELAY .08
  NEXT
  GOSUB Showtext

  LOCATE RRow%, CColumn%
  PRINT STRING$(Length%, 32)

  LOCATE 25, 4
  PRINT " press + hold escape to exit"
  GOSUB Pickphrase
LOOP UNTIL _KEYDOWN(27)
SYSTEM
END
'--------------------------------------------------------------------------

Showtext:
z% = 0
Length% = LEN(Textprn$)
FOR a = 1 TO Length%
  LOCATE RRow%, CColumn% + z%
  PRINT MID$(Textprn$, a, 1)
  z% = z% + 1
  _DELAY Pause!
NEXT a
RETURN

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

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

Pickphrase:
Whatone% = INT(RND * maxlines&) 'make a random number to select exact phrase
Textprn$ = Phrases$(Whatone%)
RETURN
And here's the contents of the text file. You can add on or subtract lines in the file .
Quote
I am the ghost comeing to save the world
Hey help me EAT some dots!
Well im waiting for you to do something!
Ghost's  who ya gonna call!
Get me into notepad and i'll eat more!
Well Garry whens Mick gonna give me more!
Nuclear reactors dont scare me!!!
Proton Pills are my favourite foods!
OlDosLover
Report Spam   Logged
GarrisonRicketson
Admin
Administrator
Hero Member
*****
Posts: 583



WWW
« Reply #7 on: April 27, 2011, 09:19:40 pm »

OK , now I am ready to ask some questions on this,...Since the enire code is already posted I don't see the need,...
Code:
 
  LOCATE 25, 4
  PRINT " press + hold escape to exit"
  GOSUB Pickphrase
LOOP UNTIL _KEYDOWN(27)
SYSTEM
END 
Is how it is now,Now see below----
 
Code:
       LOCATE 24, 4
    PRINT " press + hold escape to exit"
    LOCATE 25, 4
    PRINT "Use page down to move to next page,pageup to move back to the previous"
    GOSUB Pickphrase
LOOP UNTIL _KEYDOWN(27)
SYSTEM
END     
I Guess, the main loop would end sort of like this, the idea being after ,the text has been read, the user can "pagedown" to get the next image, and text,...That seems realtively simple to me, as it would be repeating the same code, but just loading a new image, with appropriate text,....From what I understand, I would need to free the first image, and the text file,..So maybe I can figure it out, but If you can give me a example, that would be nice, the last item is:
Code:
PRINT STRING$(Length%, 32)   
If 32 is changed, say to 64 will that increase the length of line it can display ? I guess I can just try that and see, I ask because I was trying with some different text, but the lines were longer, also lots of commas, so after I read your comment on the commas, I took them out, but it still errored, finally, by shortening all the lines, I got it working,....
guess thats about it from Garry
and thanks,...
Report Spam   Logged

OlDosLover
Guest
« Reply #8 on: April 27, 2011, 10:37:29 pm »

Hi all,
    Nice question Garry. From your comment i think you wish to load a lengthy text file and display 1 page onscreen. Then the user would use page down and up to navigate the file onscreen. At users end the program would terminate with a press of the escape key. If this is so then some of the above code can be reused.
    Basically here's a skeleton of how to do it.
1] open the file
2] read through and get amount of lines
3] close the file
4] open the file again , read an amount of lines and display those onscreen
5] await user keypress to move up,down or exit
6] on page down ,cls the screen, read another amount of lines from the text file starting at the last line read
7] exit program , close the file.

    I'll put together an example of this for you.
Quote
PRINT STRING$(Length%, 32)
    This is a string function to build a string. The Length% refers to the length of the string you want created and the 32 refers to the ascii number of the symbol to use. This string could have been written as
String$(20,32) which means a string of 20 spaces.
OlDosLover.
Report Spam   Logged
GarrisonRicketson
Admin
Administrator
Hero Member
*****
Posts: 583



WWW
« Reply #9 on: April 27, 2011, 11:07:50 pm »

Quote
From your comment i think you wish to load a lengthy text file and display 1 page onscreen. Then the user would use page down and up to navigate the file onscreen. 
I was just about to go to bed, but I figured I better say something, before you do to much,....This is not exactly what I ment, but I suppose it could work, except, In most cases the text wouldn't be that long, but also each new page would have a new pitchure, maybe useing the page down keys, is where I confused it, it might be better PRINT " Use N for the next page"
ESC to exit, at any time,...or when the program ends it exits automatic.
 I was looking at the ABC thing and I noticed there appears to be some stuff on loading html with qbasic, or qb64,...If that is the case, I may be better of doing it that way,...as this is a simple thing to do useing html,...However at this point, if I want to run a html doc, I open it with google, and run it,...If I can get qb64 to open and load a html document,
the who thing would be easier,....
  Guess I am just kind of exploreing different ways of doing the same thing,...
 It is to say what it would do for example, .... the code we have now,
 the ghost appears with some text, what he says, N key, (or page down), next, Pacman appears, also with some text,...N key (next) so on and so on,...
Hope that makes more sense,.....
from Garry
Report Spam   Logged

OlDosLover
Guest
« Reply #10 on: April 27, 2011, 11:20:25 pm »

Hi all,
    Sorry Garry i carnt seem to grasp what it is that you want. You description is too vague for me. Please explain again being as accurate as possible please. It seems you are asking about the example program i did. I thought you were talking and asking about files generally. Like open and display a files contents to the screen. Sorry again for not understanding mate.
OlDosLover.
Report Spam   Logged
GarrisonRicketson
Admin
Administrator
Hero Member
*****
Posts: 583



WWW
« Reply #11 on: April 28, 2011, 07:09:51 am »

Ok sorry, Forget the previous,...
 Yes, on the example you did,  After it opens, the first image, and text file,
then they would close, and another new image and new text would follow,..
with out closing the program, ...
 My thoughts were, a key press, would tell it when you were ready to see the next file and pitchure,...
 Dose that help ?...disregard the other stuff I said,.....
sorry
from Garry
Report Spam   Logged

OlDosLover
Guest
« Reply #12 on: April 28, 2011, 07:40:03 am »

Hi all,
    Yes i get it now. Yes its possible to read and print a line and then to wait for a keypress before showing the next line of text. Here's a revised example.
Code:
DEFLNG A-Z

SCREEN _NEWIMAGE(640, 480, 32)
WorkPage& = _LOADIMAGE("NEWGHOST_blu1.png")
CLS

GOSUB MakPhrases 'get the amount of lines so we can make a dim to gather them
IF maxlines& <> 0 THEN
  DIM Phrases$(maxlines&)
  GOSUB FillDim 'read individual phrases into the string dim
ELSE
  PRINT "File not found": _DELAY 3: END
END IF
_DELAY .5

_DEST 0
Textprn$ = "Hello World !!!": RRow% = 2: CColumn% = 6: z% = 0: Pause! = .5: Whatone% = 0
GOSUB Showtext
GOSUB Pickphrase
RRow% = 15: CColumn% = 20: z% = 0: Pause! = .050

DO
  FOR x = 0 TO 261 STEP 67
    _PUTIMAGE (100, 100)-(220, 190), WorkPage&, 0, (x, 0)-(x + 67, 67)
    _DELAY .08
  NEXT
  GOSUB Showtext

  SLEEP

  LOCATE RRow%, CColumn%
  PRINT STRING$(Length%, 32)

  LOCATE 25, 4
  PRINT " press + hold escape to exit or any key to contimue"
  GOSUB Pickphrase
LOOP UNTIL _KEYDOWN(27)
SYSTEM
END
'--------------------------------------------------------------------------

Showtext:
z% = 0
Length% = LEN(Textprn$)
FOR a = 1 TO Length%
  LOCATE RRow%, CColumn% + z%
  PRINT MID$(Textprn$, a, 1)
  z% = z% + 1
  _DELAY Pause!
NEXT a
RETURN

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

FillDim:
maxlines& = 0
ThisFile% = FREEFILE 'get next free file handle must be integer
OPEN "message.txt" FOR INPUT AS #ThisFile%
DO
  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% = 1
Textprn$ = Phrases$(Whatone%)
RETURN

Note for some reason where the sleep is i tried to insert While INkey$="":Wend but the editor insisted making the "" into " ".
OlDosLover.
« Last Edit: April 28, 2011, 07:59:10 am by OlDosLover » Report Spam   Logged
GarrisonRicketson
Admin
Administrator
Hero Member
*****
Posts: 583



WWW
« Reply #13 on: April 28, 2011, 06:26:16 pm »

Ok thanks OldDoslover, I just read this, ahve not yet tried it, I need to lie down,
but later this evening, I will try it, I think I have enough to at least be able to make a demo, then it will be much more clear as to what I am trying to do,...
 It may be a few days before I have it though,....and then, part I think of what I confuse you with, was when I mentioned HTML, which would be better in a whole different thread, in the off the wall stuff, sorry to have confused you,...
from Garry,..p.s. after I try the code you have posted, I will let you know.
Report Spam   Logged

OlDosLover
Guest
« Reply #14 on: April 29, 2011, 02:02:46 am »

Hi all,
    Im pretty easy to confuse ask my ex-wife! I think you have raised a few good points in the line of file use. Perhaps its time we did some tuts on files generally. What do you think?
OlDosLover.
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

Buy traffic for your forum/website
traffic-masters
Powered by SMF | SMF © 2016, Simple Machines