• Welcome to PlanetSquires Forums.
 

message in command window

Started by raymw, August 07, 2019, 09:31:02 AM

Previous topic - Next topic

raymw

Anyway, now got back to where it was. Made a new project, designed the form (only needed a textbox and window) saved it and ran. Then pasted in the text from previous file, amended the few references to button and text to the new names on form, and back working again. But, it would be good if this didn't happen so frquently, and recovery more difficult with a complicated form. It may be useful to be able to generate a form from the commented code of the basic file.

raymw

cross posted, there, Paul. I'll probably find out if you've fixed it  ::)

raymw

I've got it fixed now, date conversion, removal of jitter etc. Just need to decide on drawing pictures. In the meantime, I've gone retro, back 50 years or so when i was programming an IBM 1130 in fortran g (or h) or was it e/f? Anyway, there was 16k of core memory, and a £40,000 chain line printer (no fancy lower case back then, no 'glass teletypes'), so we'd print graphs/diagrams in ascii art on the stripey green paper.
Here's part of the temperature data from the console.


raymw

#18
This has all been running well for a few weeks now, I leave the data collection program running 24/7. The program and its windows only showing in the task bar. However, I want it to send a pop up message box window on rare occasions e.g. when any of the batteries need changing. I can't find anything in fbe , fbx or api help referencing pop up messages, and can't find the examples/tutorials, I'm sure it exists however.
I think it was the 'forth' programming language, consisted of a line of symbols that could replace pages of fortran or cobol. The problem being, the next day, you couldn't understand what or how you wrote it. I'm feeling the same now about any program I've written, in any language.

Edit to add - I found an answer in the CWindows class (the help search does not cover all the topics, you have to be in the correct section.) I'm always looking for a simple answer...

raymw

#19
I don't think the standard VB message box will behave in the manner I want it to, in fact I don't think individual message boxes is the best solution for me. I think it would be better to popup a form, with a list of the errors in a text box therein. Once acted on I can close down the single form, instead of individually clicking buttons on individual message boxes. Also, in my experiments, it seems that the main program does not continue running unless the message box is closed/acted upon by the user, but I may not have found all the options.

Anyway, my idea is that the main program, (which is running in the task bar, reading from usb port every ten seconds, and writing to hdd,) when it finds an error value which is significant, e.g. flat battery in one of the transmitters, then I'd like it to  open a popup form with the error in a text box in the middle of the screen, and subsequent errors are written to that text box. However, in the brief trial I have made, with one form generating a counter that is displayed in the text box of the popup message form, if either of the forms are moved, then the counter stops, and the forms become unresponsive.

''  Remove the following Application.Run code if it used elsewhere in your application.
Application.Run(Form1)

  #include once"pup.bas"   

function showpup() as String
           
dim k as Integer
 
   for k=1 to 1000
   form2.text1.text=str(k )
   sleep 2000
    next
   
    return ""
end function


Function Form1_Button1_Click( ByRef sender As wfxButton, ByRef e As EventArgs ) As LRESULT
   showpup()
   Function = 0
End Function


(form2 is the form with text box in pup.bas)

(edit to say, this thread may be better in another section, I don't think it is solely a winfbe feature.)

SeaVipe

Ray, can the counter run in a different thread?
Clive Richey

raymw

It could, but this was only to test if a program could run in the background, and send messages to a form on the desktop. I know nothing about running different threads.

raymw

added what I think is a separate thread. Makes little difference.
''  Remove the following Application.Run code if it used elsewhere in your application.
Application.Run(Form1)

  #include once"pup.bas"   

sub showpup(param as any ptr)
 
dim k as Integer
    form2.show
       for k=1 to 1000
       form2.text1.text=str(k )
        sleep 2000
   next
       
end sub


Function Form1_Button1_Click( ByRef sender As wfxButton, ByRef e As EventArgs ) As LRESULT
   Dim As Any Ptr thread = ThreadCreate(@showpup, 0)
   for k as integer =1 to 50
      form1.button1.Text = str(k)
      sleep(1000)
   next
       threadwait(thread)
   Function = 0
End Function

Any attempt to move eithr form, causes it to fail (not responding) once button1 is clicked.

SeaVipe


In loops with sleep, I have found that  application.DoEvents at the top of the loop solves "most" of my locking up issues.

Clive Richey

raymw

Thanks, I forget that more than I remember. I don't think I'll need the threading for this application. But, I've learnt something, but generally these days, 'it's in one ear, and gone tomorrow'

raymw

Hi Clive,
latest test below, getting to what i want wrt test. Pup.bas is the code for form2, it only has a textbox on it that is used

''  Remove the following Application.Run code if it used elsewhere in your application.
Application.Run(Form1)

  #include once"pup.bas"   

''
''
Function Form1_Load( ByRef sender As wfxForm, ByRef e As EventArgs ) As LRESULT
     
   ' do some stuff  to give time to put form1 on taskbar
             dim k as integer
      for k  =1 to 5
            form1.button1.Text = str(k)
            application.doevents
            Sleep 1000
      next
     
   ' open message form2
         form2.left =250
         form2.top =150
         form2.show
       
      'do some stuff on form2 and form1   
      for k=1 to 20
            form2.text1.text= form2.text1.text+"Message Number "+ str(k) + chr(13)+chr(10)
      '' do something on form2
        form1.button1.Text = str(k) +" something"
          application.doevents
          sleep 1000
      Next
   
   Function = 0
End Function

''
''
Function Form1_Button1_Click( ByRef sender As wfxButton, ByRef e As EventArgs ) As LRESULT
   ' nothing to see here...
   Function = 0
End Function


So, I run form1, and after five seconds it shows form2 and updates the textbox in form2, and carries on doing it's own thing. So far, so good. The major problem, is moving form1 down to task bar, before the initial 5 seconds is up, then form2 doesn't show on the screen (the loops keep running, however). I want form2 to appear, and stay as the top window, until I close it. It needs to appear, in fact whenever text is sent to its text box. The other problem, most likely threads will help that, is moving a form e.g. mouse over title bar, and mouse button down, then the program pauses, lops stop counting, whatever. I've tried the various window types, etc, in the form2 designer gui, but they do not seems to add anything along the lines that i need. Hopefully there is another magic couplet, like application.doevents, that'll get it working.

Paul Squires

For this type of application you definitely need to use a worker thread because the mouse moves will interrupt the UI thread. Check out my code below that will allow you to move Form2 while not blocking the the printing of the text to your textbox. Also, notice that I removed a DoEvents and also added Form1 as the parent to your Form2.show( Form1) call.



#include once "pup.bas"   

dim shared As Any Ptr gThread


'  Remove the following Application.Run code if it used elsewhere in your application.
Application.Run(Form1)

Sub WorkerThread( ByVal userdata As Any Ptr )
   'do some stuff on Form2 and form1   
   for k as long = 1 to 20
      Form2.text1.text = Form2.text1.text + "Message Number "+ str(k) + chr(13)+chr(10)
      '' do something on Form2
      form1.button1.Text = str(k) +" something"
      sleep 1000
   Next
End Sub


''
''
Function Form1_Load( ByRef sender As wfxForm, ByRef e As EventArgs ) As LRESULT
   ' do some stuff  to give time to put form1 on taskbar
   for k as long = 1 to 5
      form1.button1.Text = str(k)
      application.doevents
      Sleep 1000
   next
 
   ' open message Form2
   Form2.left = 250
   Form2.top  = 150
   Form2.show( Form1 )
   
   ' Launch another thread
   gThread = ThreadCreate( @WorkerThread )

   Function = 0
End Function

''
''
Function Form1_FormClosed( ByRef sender As wfxForm, ByRef e As EventArgs ) As LRESULT
   ThreadWait( gThread )
   Function = 0
End Function


Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

SeaVipe

Hi Paul, I had Ray's code working with DoEvents but yours is much more elegant plus it works properly!
Moving the forms was causing a slight hesitation in the counter which I'm assuming is caused by the mouse movements interrupting the UI thread you mentioned in your post.
Clive Richey

raymw

Thanks, I'll try it out. I'd got to the stage, moving things around into different threads, that it would work with care. A note for Paul playing with the gui, It appeared that the borderr styles for forms apearred listed under borders for text boxes. I got an error message that the borderstyle did not exist. Not sure that I can repeat.

raymw

I think it comes up with fixed 3d