Displaying string data in Window

Just starting out? Need help? Post your questions and find answers here.
spreadz
User
User
Posts: 10
Joined: Sat Feb 11, 2012 1:13 pm
Location: Chesterfield UK
Contact:

Displaying string data in Window

Post by spreadz »

I'm using a routine that displays its output for me using the Debug feature. To speed things up I compiled it, but of course I lose Debug.
Tried using OpenConsole() but the small size makes it too difficult for my old eyes to read, so I've been trying to make use of OpenWindow, but I cant figure out why nothing displays, anyone help?

I copied the simple code below which works fine as a stand-alone, but if I paste my program in there (with prevous Debug or PrintN changed to AddGadgetItem) nothing shows in the editor gadget window. My program still runs as normal in compiled or non-compiled mode, I can even use Debug to monitor the output in non-compiled mode, but the editor gadget remains empty.

(My program simply loads and parses files, loops through calculations and outputs the results to a file, nothing special)

What will be happenning in my code to prevent the editor gadget displaying my text??

Code: Select all

gitem=0

If OpenWindow(0, 0, 0, 1322, 500, "Report")
  EditorGadget(0, 8, 8, 1000, 400)
  
  string$="Any old text"
  AddGadgetItem(0,gitem,string$)
  gitem=gitem+1
  
  string$="and some more text"
  AddGadgetItem(0,gitem,string$)
  gitem=gitem+1
  
  

  ;--- MY CODE INSERTED HERE ---
  
  

  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
  EndIf

End
User avatar
skywalk
Addict
Addict
Posts: 4211
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Displaying string data in Window

Post by skywalk »

Your event loop is not aware of any changes.
You need to post more of what your code intends.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
spreadz
User
User
Posts: 10
Joined: Sat Feb 11, 2012 1:13 pm
Location: Chesterfield UK
Contact:

Re: Displaying string data in Window

Post by spreadz »

No, sorry to be dim, but you've lost me ...
skywalk wrote:Your event loop is not aware of any changes.
You need to post more of what your code intends.
User avatar
TI-994A
Addict
Addict
Posts: 2702
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Displaying string data in Window

Post by TI-994A »

spreadz wrote:...the small size makes it too difficult for my old eyes to read ... nothing shows in the editor gadget window ... the editor gadget remains empty.
Hello, and welcome to the PureBasic forum.

For such monitoring, perhaps the list view might be better suited. Here's a simple example to demonstrate its output:

Code: Select all

Enumeration
  #MainWindow
  #ListView
  #AddDataButton
  #TestTimer
EndEnumeration

;large font to use for all gadgets
LoadFont(0, "Arial", 16)

;change #PB_Default to a valid gadget number to
;set the font only for that gadget - for such cases
;the gadget must be initialised before setting the font
SetGadgetFont(#PB_Default, FontID(0))

wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
OpenWindow(#MainWindow, #PB_Any, #PB_Any, 400, 600, "Displaying Output", wFlags)

;list view to act as the output display
ListViewGadget(#ListView, 10, 10, 380, 530)

;a button to trigger some manually added dummy-data to the list view
ButtonGadget(#AddDataButton, 10, 550, 380, 40, "ADD DATA TO LIST VIEW")

;timer to automatically add some dummy-data
;to the list view at five-second intervals
AddWindowTimer(#MainWindow, #TestTimer, 5000)

Repeat
  Select WaitWindowEvent()
      
    Case #PB_Event_CloseWindow
      ;breaks the Repeat-Until loop when the
      ;close button is pressed to end the program
      appQuit = 1
      
    Case #PB_Event_Timer
      ;dummy-data added every 5-seconds
      AddGadgetItem(#ListView, -1, 
                    "5-second timestamp (" + 
                    FormatDate("%hh:%ii:%ss", Date()) + ")")
      
    Case #PB_Event_Gadget
      Select EventGadget()
        Case #AddDataButton
          ;dummy-data added when button pressed
          AddGadgetItem(#ListView, -1, 
                        "Adding some data at " + 
                        FormatDate("%hh:%ii:%ss", Date()))
      EndSelect
  EndSelect
Until appQuit = 1
Hope it helps. :wink:
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
spreadz
User
User
Posts: 10
Joined: Sat Feb 11, 2012 1:13 pm
Location: Chesterfield UK
Contact:

Re: Displaying string data in Window

Post by spreadz »

TI-994A wrote: Hope it helps. :wink:
Thanks for that, but it seems extremely complex, probably because I can't understand what's happenning.
I can't follow the program 'flow'.

e.g. if I add ...

Code: Select all

For n=1 To 10
    AddGadgetItem(0,n,Str(n))
Next n

... into where "My code inserted here" is above - all the loop numbers are printed in order.

So why, when I try to insert my original working code, which is merely a mix of For/Next & While/Wend and some file reading and writing I get nothing?

__________________________________________________
Code tags added
13.02.2016
RSBasic
Julian
Enthusiast
Enthusiast
Posts: 276
Joined: Tue May 24, 2011 1:36 pm

Re: Displaying string data in Window

Post by Julian »

I have added a few comments to show you what happens where:

Code: Select all

gitem=0

If OpenWindow(0, 0, 0, 1322, 500, "Report")
  EditorGadget(0, 8, 8, 1000, 400)
  
  string$="Any old text"
  AddGadgetItem(0,gitem,string$)
  gitem=gitem+1
  
  string$="and some more text"
  AddGadgetItem(0,gitem,string$)
  gitem=gitem+1
  
    
  For n=1 To 10
    AddGadgetItem(0,n,Str(n))
    ;*****
    ;if you change this loop to 1000000000 it will take a long time to finish, but your gadget wont update/redraw (see comment below)
    ;*****
  Next n
  

  Repeat
    ;*****
    ; This is where important things happen, like redrawing gadgets that have been updated
    ;*****
  Until WaitWindowEvent() = #PB_Event_CloseWindow
  EndIf

End
As you can see, your loop is running fine, but you dont give the program any time to update/redraw the UI.
User avatar
TI-994A
Addict
Addict
Posts: 2702
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Displaying string data in Window

Post by TI-994A »

spreadz wrote:... when I try to insert my original working code, which is merely a mix of For/Next & While/Wend and some file reading and writing I get nothing?
Perhaps if you could post a small sampling of your code, we might be able to determine the problem. Since it's file-related, please include a short description of the input file type and contents, and we'll try to recreate it.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
User avatar
blueb
Addict
Addict
Posts: 1111
Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico

Re: Displaying string data in Window

Post by blueb »

spreadz wrote:...Tried using OpenConsole() but the small size makes it too difficult for my old eyes to read...
For Microsoft Windows..

When you have an Active Console Window displayed...

1 - Left-Click on the small icon at the top left of the console display.
2 - Left-Click on the 'Defaults' word from the menu displayed.
3 - Select the font and font-size you wish to use.

Windows will remember your choices.

You can also change cursor shapes, etc.

HTH
- It was too lonely at the top.

System : PB 6.21(x64) and Win 11 Pro (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
spreadz
User
User
Posts: 10
Joined: Sat Feb 11, 2012 1:13 pm
Location: Chesterfield UK
Contact:

Re: Displaying string data in Window

Post by spreadz »

blueb wrote: For Microsoft Windows..

When you have an Active Console Window displayed...

1 - Left-Click on the small icon at the top left of the console display.
2 - Left-Click on the 'Defaults' word from the menu displayed.
3 - Select the font and font-size you wish to use.

Windows will remember your choices.
That's spot on! thanks blueb, I only program for my own use and have no need of professional looking windows GUIs

Thanks for the advice of others too, but Console is perfect for my personal use.
User avatar
blueb
Addict
Addict
Posts: 1111
Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico

Re: Displaying string data in Window

Post by blueb »

Your welcome spreadz.

Search... there's plenty of great code to improve consoles.
- It was too lonely at the top.

System : PB 6.21(x64) and Win 11 Pro (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
Post Reply