Author Topic: Open up another window?  (Read 5600 times)

0 Members and 1 Guest are viewing this topic.

Offline lawsonm1

  • Newbie
  • Posts: 64
    • View Profile
Open up another window?
« on: January 23, 2020, 10:23:40 pm »
Sorry about the poorly worded subject line; but I couldn't figure out how best to fit it all in a single subject line. Basically I want to write a program to input data, store the data, retrieve the data, add to it, etc. I would like the ability to have a new window/app, run concurrently with the main window/app, but be able to display/plot the data I retrieved from the main window/app. For example, the main program would allow me to input stock price data, save, manipulate, and add to the data. Then have an option in the main program be able to open up another window/app to graph out some portion of the data in the main program. Is that possible? And if so, are there limits on how many can be opened up at one time? Thanks, Mike

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Open up another window?
« Reply #1 on: January 23, 2020, 11:05:43 pm »
Have the first program generate and save your data, then SHELL to a second program to read and display that data. 
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Open up another window?
« Reply #2 on: January 24, 2020, 11:20:11 am »
Yep, if you want 3 windows (so you can have all data visible from one while you work in 2nd), write 3 EXE's and let Windows manage which has focus and is under your mouse and getting the keypresses...

It should actually be easier to code with data structure and shared file names, subs and function in a common BI/BM include, in each program you can focus on it's one purpose as each sub or function does same.

Divide and conquer!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Open up another window?
« Reply #3 on: January 24, 2020, 11:52:41 am »
...
Divide and conquer!

I'd rather be fruitful and multiply. At least that was true up to the time QWERKY told be to go forth and multiply myself. Then I had to rethink that one...

Anyway, you can even add a Windows API library call, to keep certain windows in focus, if that ever becomes necessary. Of course if your not using a Windows system... Go multiply yourself! (Just kidding. I don't have a Linux or Mac, so I wouldn't know how to maintain focus in either of those systems.)

Some windows persistence info here:

https://www.qb64.org/forum/index.php?topic=1365.msg105588#msg105588

https://www.qb64.org/forum/index.php?topic=860.msg100590#msg100590

Pete
« Last Edit: January 24, 2020, 12:03:30 pm by Pete »
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Richard Frost

  • Seasoned Forum Regular
  • Posts: 316
  • Needle nardle noo. - Peter Sellers
    • View Profile
Re: Open up another window?
« Reply #4 on: January 24, 2020, 05:53:50 pm »
Why not have your program:
1) Manage multiple viewports on the same screen, assiging TAB or some other key to switch between them?
2) Toggle between full screen data editing and graphing, again with a single key?

There are commands to help this along, VIEW PRINT, VIEW SCREEN, _DEST, _SOURCE, _DISPLAY, etc. 
With (2) the editing part can be a text screen for simplicity of programming with the graphing bit in
some high resolution mode to make pie charts look tasty.
It works better if you plug it in.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Open up another window?
« Reply #5 on: January 24, 2020, 06:17:43 pm »
Right!
Quote
Why not have your program:
1) Manage multiple viewports on the same screen, assiging TAB or some other key to switch between them?
2) Toggle between full screen data editing and graphing, again with a single key?
you can manage internally some windows in a fullscreen application.... at the time of Windows 3.1  this tecnique was called "Child Window" using windows into the Main window of the program.
Programming isn't difficult, only it's  consuming time and coffee

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Open up another window?
« Reply #6 on: January 24, 2020, 06:20:16 pm »
@ Richard Frost
Hey Richard  have you some example code to demonstrate these concepts?
I have no one, would it be necessary to build some application!
Programming isn't difficult, only it's  consuming time and coffee

Offline Richard Frost

  • Seasoned Forum Regular
  • Posts: 316
  • Needle nardle noo. - Peter Sellers
    • View Profile
Re: Open up another window?
« Reply #7 on: January 24, 2020, 11:02:34 pm »
No, I didn't have a simple example of such code, so I wrote this ugly thing quick.   It's a "spreadsheet" with two editable columns that shows a bar graph at all times, a pie chart in a new screen with TAB.   Esc saves changes and quits.  Most
of the coding time was spent looking up ASCII codes of the arrows and such minor stuff. 

I hope I didn't misunderstand the initial question!

Code: QB64: [Select]
  1. DEFINT A-Z
  2. DIM SHARED employee$(50), wage!(50), hours!(50), total!(50)
  3. employees$ = "employees.dat"
  4. IF NOT (_FILEEXISTS(employees$)) THEN
  5.     DO
  6.         READ t$
  7.         IF t$ = "end" THEN EXIT DO
  8.         n = n + 1
  9.         employee$(n) = t$
  10.     LOOP
  11.     FOR i = 1 TO n
  12.         CLS
  13.         PRINT "FILE EMPLOYEE.DAT DOES NOT EXIST - INITIAL ENTRY MODE"
  14.         PRINT
  15.         PRINT "Employee "; employee$(i)
  16.         PRINT
  17.         d = RND * 30 + 14: c = RND * 100
  18.         wage!(i) = d + c / 100 ' hey, it's a demo, just create random data
  19.         hours!(i) = 40 + INT(RND * 10)
  20.     NEXT i
  21.     GOSUB writefile
  22. OPEN employees$ FOR INPUT AS #1
  23. n = 0
  24.     n = n + 1
  25.     INPUT #1, employee$(n), wage!(n), hours!(n)
  26.     total!(n) = wage!(n) * hours!(n)
  27.  
  28. wpos = 30
  29. hpos = 40
  30. tpos = 50
  31. minrow = 5
  32. maxrow = minrow + n - 1
  33. mrow = minrow
  34. mcol = hpos
  35.  
  36.     GOSUB plotspread
  37.     DO
  38.         LOCATE mrow, mcol - 1: PRINT " ";
  39.         GOSUB scankey
  40.         IF LEN(i$) = 2 THEN
  41.             k = ASC(RIGHT$(i$, 1))
  42.             IF k = 80 THEN mrow = mrow + 1 '                        arrow down
  43.             IF k = 72 THEN mrow = mrow - 1 '                        arrow up
  44.             IF k = 77 THEN '                                        arrow right
  45.                 IF mcol = wpos THEN mcol = hpos ELSE mcol = wpos
  46.             END IF
  47.             IF k = 75 THEN '                                        arrow left
  48.                 IF mcol = hpos THEN mcol = wpos ELSE mcol = hpos
  49.             END IF
  50.             IF mrow < minrow THEN mrow = minrow
  51.             IF mrow > maxrow THEN mrow = maxrow
  52.         END IF
  53.         LOCATE mrow, mcol - 1: PRINT ">";
  54.         _DELAY .1
  55.         IF i$ = CHR$(13) THEN
  56.             t$ = ""
  57.             DO: _LIMIT 10
  58.                 GOSUB scankey
  59.                 IF LEN(i$) = 1 THEN
  60.                     t$ = t$ + i$
  61.                     LOCATE mrow, mcol: PRINT USING "###.##"; VAL(t$);
  62.                 END IF
  63.             LOOP UNTIL (LEN(t$) = 6) OR (i$ = CHR$(13))
  64.             z = mrow - minrow + 1
  65.             IF mcol = wpos THEN wage!(z) = VAL(t$)
  66.             IF mcol = hpos THEN hours!(z) = VAL(t$)
  67.             total!(z) = wage!(z) * hours!(z)
  68.             mrow = mrow + 1: IF mrow > maxrow THEN mrow = maxrow
  69.             EXIT DO
  70.         END IF
  71.         IF i$ = CHR$(9) THEN GOSUB pie: EXIT DO
  72.     LOOP
  73.  
  74. done:
  75. GOSUB writefile
  76. ' -----------------------------------------------------------------------------------------------
  77. writefile:
  78. OPEN employees$ FOR OUTPUT AS #1
  79. FOR i = 1 TO n
  80.     PRINT #1, employee$(i); ","; wage!(i); ","; hours!(i)
  81. ' -----------------------------------------------------------------------------------------------
  82. scankey:
  83. i$ = INKEY$
  84. IF i$ = CHR$(27) THEN GOSUB writefile: SYSTEM
  85. ' -----------------------------------------------------------------------------------------------
  86. pie:
  87. gtotal! = 0
  88. FOR z = 1 TO n
  89.     gtotal! = gtotal! + total!(z)
  90. a = 0
  91. FOR z = 1 TO n
  92.     q = total!(z) / gtotal! * 360
  93.     FOR j = 1 TO q
  94.         x = 320 + 200 * COS(_D2R(a))
  95.         y = 240 + 200 * SIN(_D2R(a))
  96.         LINE (320, 240)-(x, y), z
  97.         _DELAY .0001
  98.         a = a + 1
  99.     NEXT j
  100. LOCATE 29, 16: PRINT "Press spacebar to return to spreadsheet, Esc to exit";
  101.     GOSUB scankey
  102. LOOP UNTIL i$ = " "
  103. ' -----------------------------------------------------------------------------------------------
  104. plotspread:
  105. PRINT "                       WIDGETS COMPANY WEEKLY PAYROLL"
  106. PRINT "EMPLOYEE                       WAGE     HOURS         PAY"
  107. LOCATE 5, 1
  108. FOR i = 1 TO n
  109.     c = i MOD 16
  110.     COLOR c
  111.     PRINT employee$(i);
  112.     LOCATE CSRLIN, wpos: PRINT USING "###.##"; wage!(i);
  113.     LOCATE CSRLIN, hpos: PRINT USING "###.##"; hours!(i);
  114.     LOCATE CSRLIN, tpos: PRINT USING "#####.##"; total!(i)
  115.     COLOR 15
  116. LOCATE n + 7, 23: PRINT "Arrow keys to move, Enter to change value";
  117. LOCATE n + 9, 23: PRINT "   TAB for a bigger graph, ESC to exit";
  118.  
  119. gtotal! = 0
  120. maxt! = 0
  121. FOR z = 1 TO n
  122.     gtotal! = gtotal! + total!(z)
  123.     IF total!(z) > maxt! THEN maxt! = total!(z)
  124. x1 = 100: y1 = 370
  125. x2 = 550: y2 = 470
  126. LINE (x1, y1 - 10)-(x2, y2), 15, B
  127. FOR z = 1 TO n
  128.     tx1 = x1 + z * (x2 - x1) / (n + 1)
  129.     tx2 = tx1 + 10
  130.     ty1 = y2 - total!(z) / maxt! * 100
  131.     ty2 = y2
  132.     LINE (tx1, ty1)-(tx2, ty2), z, BF
  133. ' -----------------------------------------------------------------------------------------------
  134. ' -----------------------------------------------------------------------------------------------
  135. DATA Felicity Jones
  136. DATA Saorise Ronan
  137. DATA Brigitte Fonda
  138. DATA Kay Lenz
  139. DATA Linda Fiorentino
  140. DATA Ali McGraw
  141. DATA Susan Dey
  142. DATA Lee Remick
  143. DATA Jennifer Connelly
  144. DATA Lindsey Stirling
  145.  
  146.  
It works better if you plug it in.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Open up another window?
« Reply #8 on: January 25, 2020, 09:18:21 am »
Fine Richard!

But please do this:
OR  at line 168  DATA end
OR  at line 8     IF t$ = "END"   <--- I've made this  [ You are not allowed to view this attachment ]  
OR at line 8      IF LTRIM$(t$) = "end"
to avoid  line 7 OUT of DATA

Programming isn't difficult, only it's  consuming time and coffee

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Open up another window?
« Reply #9 on: January 25, 2020, 09:40:26 am »
moreover adding
Code: QB64: [Select]
  1.             COLOR 15, 0
  2.             LOCATE mrow, mcol: PRINT USING "###.##"; VAL(t$);
after line 61 IF i$ = CHR$(13) THEN 
I find more clear that I must input a data... I do this feedback only because your demonstration is very fine and I didn't like this neo on it.
« Last Edit: January 25, 2020, 02:33:56 pm by TempodiBasic »
Programming isn't difficult, only it's  consuming time and coffee

Offline lawsonm1

  • Newbie
  • Posts: 64
    • View Profile
Re: Open up another window?
« Reply #10 on: January 25, 2020, 03:08:02 pm »
Holy Moly; now my brain has been overloaded. For now, I'm probably going to stick to something reasonably simple; like SHELL. I don't mind additional windows open. But this has got me thinking about how to pass variables to the program I am SHELLing to. Maybe a string, or two, that I could use to set the window title to. I have always just used GWBASIC, so this new world of QB64 is really new. Thanks, Mike

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Open up another window?
« Reply #11 on: January 25, 2020, 07:52:36 pm »
I like to just use a file to pass variables. This was an old trick I used to run my office software, when QBasic was around. Just take all the variables that the SHELL program needs, and write them to a file before the SHELL call is made. Have the SHELL program open that file to load the variables. Redo the process in reverse, if the SHELL program will be making any changes to these variables, that the main program calling it would need updated.

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

Offline Richard Frost

  • Seasoned Forum Regular
  • Posts: 316
  • Needle nardle noo. - Peter Sellers
    • View Profile
Re: Open up another window?
« Reply #12 on: January 26, 2020, 12:48:13 am »
Here's a simpler and shorter example that actually restores the previous screen rather than regenerate it,
and the screens are different - one text and one graphics.

I couldn't get the F1 key trap to work with INPUT, so I grab one character at a time with INKEY$.  Not handling
backspace and whatnot isn't very nice, but hey, this is a demo for a specific purpose, and proper input ain't it.

Code: QB64: [Select]
  1. ON KEY(1) GOSUB GraphicsScreen
  2. KEY(1) ON
  3.  
  4. LOCATE 12, 27: PRINT "SCREEN 0 page, F1 for graphics";
  5.  
  6.     LOCATE 15, 30: PRINT SPACE$(30);
  7.     LOCATE 15, 30: PRINT "Enter name: ";
  8.     name$ = ""
  9.     DO: _LIMIT 10
  10.         i$ = INKEY$
  11.         IF i$ = CHR$(13) THEN EXIT DO
  12.         IF LEN(i$) = 1 THEN
  13.             PRINT i$;
  14.             name$ = name$ + i$
  15.         END IF
  16.     LOOP
  17.  
  18. GraphicsScreen:
  19. i& = _COPYIMAGE(0)
  20. SCREEN _NEWIMAGE(800, 600, 32)
  21. CIRCLE (400, 300), 200, _RGB32(255, 0, 0)
  22.  
It works better if you plug it in.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Open up another window?
« Reply #13 on: January 26, 2020, 10:53:52 am »
Hi lawsomn1

here you can see a demo of multiple windows into your main window program https://www.qb64.org/forum/index.php?topic=2124.msg113618#msg113618

this is an alternative answer to your question versus multiple static windows/Areas of the window of your program by Richard Frost.
Moreover you can merge the idea of multiple child windows with that of Richard Frost (navigation by TAB among the windows and keyboard input)

When I started to write code in Qbasic (in the old time of DOS) I was fascinated of the possibility to write different modules (programs) and to pass data among them... the way was  or COMMON variables or files with data.
Today with QB64 there is no matter to write different modules, because having no RAM limitation except that for  RAM being on the machine that runs the program, you can do very huge programs with little problems.
Moreover if your will is to build two programs that interact between them you can use as newer method TCP protocol.

Good luck with your project...
and write down it before as pseudocode!
I have done the mistake to not do so and in the empowerement from 1 child window to multiple child window I waste 4-6h because I have moved of 1 raw an instruction. (in the one child window it doesn't make difference, but in that with multiple child windows it make so difference!)
Programming isn't difficult, only it's  consuming time and coffee

Offline lawsonm1

  • Newbie
  • Posts: 64
    • View Profile
Re: Open up another window?
« Reply #14 on: January 29, 2020, 09:55:36 pm »
Well, as I was getting more involved in this program I'm writing, I came across something else I could use the "SHELL and passing data in a file" concept (thanks Pete); getting a list of the data files my program creates in order to be able to figure out which one to load for update. So I decided to SHELL out to get a directory re-directed to a data file, then INPUT the data file into strings, parse the strings for the dates, and then display them for eventual selection. Hey, it isn't the fanciest way I'm sure, but it works.

I guess the more things I want to do with this program, the more I dig around trying to find new things, and ways, to do them. For me that is hard if you don't have a goal in what you want to create, so you can best create it. Thanks all, Mike