Author Topic: text editor  (Read 3683 times)

0 Members and 1 Guest are viewing this topic.

Offline badger

  • Forum Regular
  • Posts: 148
    • View Profile
text editor
« on: October 02, 2020, 03:30:57 pm »
Hello

Is there a text editor that could be used in code. call it with a name given by the programmer and when exited it is saved by that name. something that maybe could be included in a .bi or something.

Phil

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: text editor
« Reply #1 on: October 02, 2020, 03:58:57 pm »
Be sure to save this code before testing it.

Code: QB64: [Select]
  1. OPEN "Test file edit.txt" FOR OUTPUT AS #1 ' <<<< this will erase the last file contents if any
  2. PRINT #1, "Type in your stuff. Save the file and exit."
  3. SHELL "Test file edit.txt" ' <<<<<<<<<< this calls up your default text editor to edit this file
  4.  
  5. 'after you exit the editor this will come up, you can do whatever you want with file contents
  6.  
  7. OPEN "Test file edit.txt" FOR INPUT AS #1
  8.     LINE INPUT #1, fline$
  9.     PRINT fline$
  10.  
  11.  

Update: added some more notes
« Last Edit: October 02, 2020, 05:18:05 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: text editor
« Reply #2 on: October 02, 2020, 05:18:51 pm »
@badger Is that cool or what?

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: text editor
« Reply #3 on: October 02, 2020, 05:34:58 pm »
I think I still have my mini-word processor in the big programs board at the Tapatalk QBasic Forum. Even small WPs are around 1000 lines of code. I was actually thinking of fiddling with the new _INSTRREV in a resize demo. Maybe I'll do some of that for fun today, but I have a bunch of other web related stuff on my plate.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline badger

  • Forum Regular
  • Posts: 148
    • View Profile
Re: text editor
« Reply #4 on: October 02, 2020, 05:36:12 pm »
Hello

@bplus


I am going to look at this because i need a 250 or better field for a item description so i will see if i can use this. I dont see any reason i cant... The operation will type in an inventory id that will be the name of the file.


Badger


Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: text editor
« Reply #5 on: October 02, 2020, 05:38:57 pm »
Yeah some time ago I was wanting an editor but man! this method sure beats reinventing the wheel.

I used this method for a data entry form for customizing a mine field in a Minesweeper game.

I asked all my questions in a text file and put = signs for user to fill out form, then they save the file, exit and I read all the stuff to the right of the = signs to setup the Minesweeper Game.
« Last Edit: October 02, 2020, 05:43:28 pm by bplus »

Offline badger

  • Forum Regular
  • Posts: 148
    • View Profile
Re: text editor
« Reply #6 on: October 02, 2020, 05:41:19 pm »
Hello

@Pete
i am rather database oriented so if you come up with an incode wp that a person could include that would be very sweet.

The system i am creating is a small custom pos system for my wife and her wedding gown business. she is doing pretty good sold 160 gowns this year. so that is why i am posting a lot. I have not used qb since the 90s. I have been using vb i dont like vb or sql so the integer64 is better than what i used to use in qb4.5 (btrieve) gave qb4.5 4m records this far surpasses that ..

badger

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
Re: text editor
« Reply #7 on: October 02, 2020, 05:45:12 pm »
A simple text editing box that is keyboard only, arrows keys, backspace, enter might be simple enough but a full blown one with mouse, copy/paste, undo/redo, etc is going to require a lot of code

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: text editor
« Reply #8 on: October 02, 2020, 05:47:32 pm »
A simple text editing box that is keyboard only, arrows keys, backspace, enter might be simple enough but a full blown one with mouse, copy/paste, undo/redo, etc is going to require a lot of code

Yeah, seems like a job for a regular Text Editor :)

Offline badger

  • Forum Regular
  • Posts: 148
    • View Profile
Re: text editor
« Reply #9 on: October 02, 2020, 05:53:39 pm »
Hello

@bplus


this is what i am going to use it is a little changed from your code but i need the name to be dynamic


Badger
Code: QB64: [Select]
  1. DIM sdesc AS STRING * 10
  2. sdesc = "0000000001"
  3.  
  4. OPEN sdesc + ".txt" FOR OUTPUT AS #1 ' <<<< this will erase the last file contents if any
  5. 'PRINT #1, "Type in your stuff. Save the file and exit."
  6. SHELL sdesc + ".txt" ' <<<<<<<<<< this calls up your default text editor to edit this file
  7.  
  8. 'after you exit the editor this will come up, you can do whatever you want with file contents
  9.  
  10. OPEN sdesc + ".txt" FOR INPUT AS #1
  11.         LINE INPUT #1, fline$
  12.         PRINT fline$
  13.  
  14.  

Offline badger

  • Forum Regular
  • Posts: 148
    • View Profile
Re: text editor
« Reply #10 on: October 02, 2020, 05:55:19 pm »
Hello

@bplus

i dont need much more than keyboard and such. no mouse or anything. but i think what you gave will work


Badger

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: text editor
« Reply #11 on: October 02, 2020, 07:01:25 pm »
You don't need the time crunch headache of a custom coded  WP at this point. What Mark posted is a good idea, use the operating system's like Notepad (default) or Wordpad, for now. If you want to use Wordpad, just be sure you save it as regular text, that means use a .txt suffix. The rtf of Wordpad would mess up your database big time. Notepad has almost no bells and whistles and no spell checking, but it will always save as .txt. Anyway, to try Wordpad, you would do a shell as:

SHELL "wordpad " + CHR$(34) + "test file edit test.txt" + CHR$(34)

I usually use CHR$(34), the qute character, to offset the sometimes problem of spaces occurring in a file name. Actually, I usually avoid using spaces in a file name, and just put hyphens in place of a space.

Also note that QB64 can use SHELL _DONTWAIT if you ever want your program to continue before the app it opened with shell is terminated. Without _DONTWAIT your QB64 app will be suspended until the app it opened is closed. So if you mess up a SHELL call without using it, you might need to open task manager to close out your QB64 exe file as the app being shelled to will fail to open, but the QB64 app running won't know that! It will just stay open, in a suspended state, waiting for you to close an app that you can't close, because it never opened. Anyway, just a heads up.

Pete

Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline badger

  • Forum Regular
  • Posts: 148
    • View Profile
Re: text editor
« Reply #12 on: October 02, 2020, 07:27:06 pm »
Hello Pete

that works just fine along with _fileexist to see if the file is there if not open a new file LOL thanks very very much

Badger

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: text editor
« Reply #13 on: October 02, 2020, 09:22:49 pm »
It's a hack of sorts, but I did a lot of stuff like that in my early days, for productivity sake. later, I goofed around with stuff like this...

Code: QB64: [Select]
  1. a$ = "This is a test for resizing a window and using the _INSTRREV keyword. I want to see if there is a more compact way to wrap text, using this method. The following is the results of my testing... Here is a test of a solid block of characters 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 and a solid block of characters at the end $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$."
  2.     start = 1
  3.     x$ = ""
  4.     DO
  5.         m$ = MID$(a$, start, _WIDTH)
  6.         IF INSTR(m$, CHR$(32)) = 0 THEN ' Solid line of text.
  7.             x$ = x$ + m$
  8.             start = start + _WIDTH
  9.         END IF
  10.         IF RIGHT$(MID$(a$, start, _WIDTH + 1), 1) = CHR$(32) OR LEN(m$) < _WIDTH THEN
  11.             x$ = RTRIM$(x$ + MID$(a$, start, _WIDTH + 1))
  12.             IF LEN(m$) < _WIDTH THEN EXIT DO
  13.             start = start + _WIDTH + 1
  14.         ELSE
  15.             k = _INSTRREV(m$, CHR$(32))
  16.             IF k THEN
  17.                 x$ = x$ + MID$(a$, start, k) + STRING$(_WIDTH - k, 42)
  18.                 start = start + k
  19.             END IF
  20.         END IF
  21.        101
  22.     LOOP
  23.     CLS: LOCATE 1, 1
  24.     PRINT x$
  25.     LOCATE _HEIGHT, 1: PRINT "Width ="; _WIDTH; "    ";
  26.     DO
  27.         b$ = INKEY$
  28.         IF LEN(b$) THEN
  29.             SELECT CASE b$
  30.                 CASE CHR$(0) + "K"
  31.                     IF _WIDTH >= 15 THEN x = _WIDTH - 1: _DELAY .05
  32.                 CASE CHR$(0) + "M"
  33.                     IF _WIDTH <= 160 THEN x = _WIDTH + 1: _DELAY .05
  34.                 CASE CHR$(27)
  35.                     SYSTEM
  36.             END SELECT
  37.             EXIT DO
  38.         END IF
  39.     LOOP
  40.     WIDTH x, 25
  41.  

That code will demonstrate a word wrap using the new _INSTRREV keyword, and also prints to the screen as a single variable, instead of line by line variables, such as arrays. In other words, it converts the large string into a format that the screen will accept, without cutting words.

Use the arrow left and right keys to widen or narrow the screen. The word wrap will adjust to every width change.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/