Page 1 of 1

Help need with program !

Posted: Wed Jun 25, 2003 11:59 am
by Large
Hi Guys,

I'm stressing again, using the code below I am trying to open a window and in the window it says 'you have recieved a private message' if you have a new message otherwise the window won't show.

If the user clicks inside the window it opens Internet Explorer and then closes the window, waits 5 mins and checks the database again.

This is for a company intranet I'm building, I need a way of notifying the end users that they have recieved a new message with out them having to have their browsers continually open, thats where PB and ODBC come in, the data base code is ok and works but repeat loop every 5 mins I need help with.

Code: Select all

Repeat

win = OpenWindow(0, ScreenWidth()-212, ScreenHeight()-170, 200, 100, #PB_Window_SystemMenu, "Database Test") 
CreateGadgetList(win) 
EditorGadget(1, 0, 0, 190, 90)

x = 0
report$ = "You have recieved a private message !"
 
If InitDatabase() 
If OpenDatabase(0, "database", "user", "password") 

UseDatabase(0) 

request$ = "select * from pm" 
result = DatabaseQuery(request$)

Repeat
result = NextDatabaseRow()
text$ = GetDatabaseString(6)

If text$ = "unread"
x = x + 1
EndIf 

Until result = 0
EndIf 

Else 
MessageRequester("Error","Can't initialize Database",#PB_MessageRequester_Ok) 
End 

EndIf 

If x > 0
HideWindow(0,0)
SetGadgetText(1,report$)
EndIf

Select WaitWindowEvent()
Case #PB_EventGadget; check for a pushed button
Case #WM_CLOSE ; #PB_EventCloseWindow
Quit = 1
EndSelect   
Until Quit = 1
Could someone alter my code for me, so that it works !

Please help me before I get totally stressed out ! :?

Kind regards

Andy

Posted: Wed Jun 25, 2003 2:31 pm
by GedB
There are two useful functions available.

First is delay(x), which can delay the program for x amount of milliseconds. This is a PB function.

Second is the API call SetTimer_(), which will create a timer which will send your window a #WM_TIMER at the intervals requested.

The following code shows both in use.

Code: Select all

Global Count.l 

hwnd = OpenWindow(0,100,100,100,100,#PB_Window_Invisible|#PB_Window_ScreenCentered , "")
If HWND = 0:End:EndIf

If CreateGadgetList(hwnd) = 0:End:EndIf
TextGadget(0,0, 0, 100, 100, "0", #PB_Text_Center )

Count = 0
ID.l = SetTimer_(hwnd, 0, 5000, 0)

Repeat
  evt = WaitWindowEvent()
 If evt = #WM_TIMER
    Count = Count + 1
    HideWindow(0, 0)
    SetGadgetText(0, Str(count))
    Delay(500)
    HideWindow(0, 1)
  EndIf 
Until Count > 5

KillTimer_(hwnd, 0)

Posted: Wed Jun 25, 2003 3:02 pm
by Large
Can someone apply one of these examples to my code, sorry to be dumb but I still can't make it work.

Kind regards

Andy

Re: Help need with program !

Posted: Wed Jun 25, 2003 5:26 pm
by ricardo
Maybe has some errors since i can't check it (no database here), but the idea should work ok.

Code: Select all

Procedure CheckDatabase()
  KillTimer_(WindowID(),0); Stop the timer
  x = 0
  report$ = "You have recieved a private message !"
  If InitDatabase()
    If OpenDatabase(0, "database", "user", "password")
      UseDatabase(0)
      Repeat
        Delay(10)
        request$ = "select * from pm"
        result = DatabaseQuery(request$)
        result = NextDatabaseRow()
        text$ = GetDatabaseString(6)
        If text$ = "unread"
          x = x + 1
        EndIf
      Until result = 0
      If x > 0
        HideWindow(0,0)
        SetGadgetText(1,report$)
      EndIf
    EndIf
  Else
    MessageRequester("Error","Can't initialize Database",#PB_MessageRequester_Ok)
    End
  EndIf
  SetTimer_(WindowID(),0,180000,@CheckDatabase());Set the timer again when the procedure is done
EndProcedure

If OpenWindow(0, ScreenWidth()-212, ScreenHeight()-170, 200, 100, #PB_Window_SystemMenu, "Database Test")
  CreateGadgetList(WindowID())
  EditorGadget(1, 0, 0, 190, 90)
  SetTimer_(WindowID(),0,180000,@CheckDatabase());Call it for first time when start
  Repeat
    Select WaitWindowEvent()
    Case #PB_EventGadget; check for a pushed button
    Case #WM_CLOSE ; #PB_EventCloseWindow
      Quit = 1
    EndSelect
  Until Quit = 1
EndIf
End
Ps. One suggestion, use Berikco's source indenter app (check the PB tools post in begginers area) to indent your code, its helpfull to make it more readable :D I use it all the time.

Re: Help need with program !

Posted: Wed Jun 25, 2003 7:16 pm
by TerryHough
Large wrote: If the user clicks inside the window it opens Internet Explorer and then closes the window, waits 5 mins and checks the database again.

This is for a company intranet I'm building, I need a way of notifying the end users that they have recieved a new message with out them having to have their browsers continually open,
I might just be able to help... Check your private message area.

Terry