Deal or no deal ........

Discussion in 'Questions (Windows Mobile)' started by taximania, Sep 14, 2007.

  1. taximania

    taximania Well-Known Member Licensed User

    2 weeks now and no written reply from Endemol :sign0137:

    Question:
    If I don't add the red code on the desktop version, my laptop goes into 'fans on, 100% CPU usage'

    Code:
    Sub buttok
       button34.Visible=
    true
       
    Do Until butok = 1
       
    DoEvents
       [COLOR=
    "Red"]Sleep(50)[/COLOR]
       
    Loop
       butok=
    0
       button34.Visible=
    false
            label76.Text=
    ""
    End Sub
    Would this be a problem on the Device version ?? (the lack of the Sleep command) ?
    ie Max CPU usage.

    Is a statement like needed,

    If PPC=? then sleep????
    bla bla bla
    End if

    Just wondered :sign0085:
     
  2. Cableguy

    Cableguy Expert Licensed User

    I don't get it, why use Sleep after DoEvents?

    How many processes do you have running on your laptop for it to go turbo fan mode?
    Are you sure about spyware?

    The DoEvents enables your device to "pay attention" to others processes instead of "locking" to you app...so why Sleep?

    Have you tried the code in a device?
     
  3. agraham

    agraham Expert Licensed User

    I would expect this as you are effectively running an endless loop and so using 100% of the CPU, it's getting warm and the fans are quite correctly coming on. Both of these waste battery energy. There will also be the same problem on the device

    If you are having to do this then I am afraid that your program structure is not good. You really should be exitting Sub buttok and using whatever event triggers the variable butok to be set to 1 to take the next step.
     
  4. taximania

    taximania Well-Known Member Licensed User

    That's what I thought.

    Button34_Click sets butok to 1
    buttok halts the program till button34 is clicked.

    What other method is there to halt the program till a particular button is pressed, my heads puddled :)
     
  5. agraham

    agraham Expert Licensed User

    To effectively and efficiently code in Windows requires you to use event-based programming. In such programming you don't need to "halt" the program, you respond to an event occuring by running some code and then exiting from the Sub that the event invoked. Your code is then automatically "halted" by the Operating System until another event occurs for which you have written an event handler Sub.

    I am not entirely clear what you want but how about the following?

    Code:
    ' invoked by some event somewhere
    'make Button34 visible and exit so waiting for another event
    Sub buttok
        button34.Visible=
    true
    End Sub

    ' Button34 clicked so hide it
    Sub Button34_Click
        button34.Visible=
    false
        label76.Text=
    ""
        butok = 
    1
        
    ' do anything else needed here
    End Sub
     
  6. taximania

    taximania Well-Known Member Licensed User

    [​IMG]

    22 buttons (right side)
    When an offer is made, 'Yes' and 'No' buttons are made visible at the bottom of the playing area.

    It's instead of using a MsgBox which obscures the playing area but used to be my halt and return the values I needed.
    Come on, this is version 99 by now. It needed a little player friendly bits added :sign0060:

    If I don't disable all of the unused 22 buttons and wait for a 'Yes' or 'No' button_click, the user can still click any of the available 22 buttons, thus, ruining the game.

    Once a 'Yes' button has been clicked, (offer taken), an 'OK' button (34) is displayed at the bottom instead, and the value the offer would have been. Again, if I don't wait for the, 'OK' click 'and' disable the other buttons until i've had the button34_click the user can still click the unused 22 buttons and spoil the game.

    Sorry for rambling, it is saturday night, cheers agraham :sign0188:
    http://myweb.tiscali.co.uk/taximania/mygame/mygame.html
     
    Last edited: Sep 15, 2007
  7. RandomCoder

    RandomCoder Well-Known Member Licensed User

    You could set what I would refer to as a flag which if true allows play to continue.

    When either the 'yes', 'no' or 'OK' buttons are made visible the flag is made false. Following one of the buttons being clicked the flag is made true again if play is allowed to continue. Presumably each 'box' has its own click event which would first check if the flag was true else exit the sub.

    That's how I would approach the problem anyway.

    Regards,
    RandomCoder
     
  8. agraham

    agraham Expert Licensed User

    I'm glad you spotted this for yourself. I had thought of mentioning this in my previous post but decided not to to keep it short(ish).

    One downside of event-based programming is that you can't predict what events a user may cause so you have to be prepared for anything to happen. This can mean a lot of enabling or disabling or hiding controls, or may mean a lot of conditional testing within event Subs to see if an event should be ignored or not. As ever experience (and occasional (or frequent!) failure) are the best teachers to efficient program design together with (maybe) a bit of help from the elders of the tribe. I can count on over 42 years of coding and I'm still learning (more slowly each year regrettably as the faculties dim!)

    Off for a drink or two myself 'cos there's bog all on the telly tonight (maybe that's what's doing in the faculties (the drink not the telly - but maybe ...)).

    Don't you just love all these nested parentheses.

    Cheers!
     
  9. taximania

    taximania Well-Known Member Licensed User

    You mean like
    Code:
    do until flag = 1
    doevents
    loop
    ;)

    Code:
    Sub buttok
       button34.Visible=
    true
       
    Do Until butok = 1
       
    DoEvents
       Sleep(
    50)
       
    Loop
       butok=
    0
       button34.Visible=
    false
            label76.Text=
    ""
    End Sub
    The subs to enable/disable the unused 22 buttons is already in place.

    Code:
    Sub enbuts
    For a = 1 To 22
    If box(a).used = 1 Then
       
    Control("Button" & a).Enabled = true
    End If
    Next a
    End Sub

    Sub dibuts
    For a = 1 To 22
    If box(a).used = 1 Then
       
    Control("Button" & a).Enabled = false
    End If
    Next a
    End Sub
    Question: Is there another other method , (not an endless loop), to halt the program till a particular button (or action) has taken place :sign0163:
     
  10. agraham

    agraham Expert Licensed User

    I think that you have missed the point of my earlier reply. There is no need to ever halt your program yourself, it is halted automatically when you have finished processing an event until the next event occurs. Just let the event Sub exit and your program is halted. When the button you are waiting for is pressed then its' event sub will be called and you can do what is necessary then.

    A problem that you might have is that other buttons may be pressed or other events occur that that you might want to ignore. You have to allow for this by either disabling other controls or including appropriate code in their event procedures.
     
    Last edited: Sep 16, 2007
  11. taximania

    taximania Well-Known Member Licensed User

    'By jove I think he's got it' :sign0060: (That means me)

    I've split the, '6 rounds', subs in half, and created 1 new sub to do the repetative stuff what the other 6's 2nd halves did. (still with me)

    Then I transfered the bits of code from the 6 subs 2nd halves into a series of If's in the actual 'Yes', 'No', and 'Ok' button clicks. (asleep yet)

    I've done away with the buttok sub all together.

    Works a treat :sign0098: no loops, sleeps or fan blasting at all.

    Many thanks agraham, It finally clicked in my head what you were trying to explain to me and how to do it :sign0188:

    I'm thinking of letting full paid registered members of basic4ppc have a full free evaluation copy of the game. Purely for beta testing whilst I am waiting for Endemol to reply to me. It would be a personal compiled version with the members name in the 'About' screen. That way If it crept it's way onto the net I'd know who leaked it.

    What do you think :sign0163:

    agraham, pm me, you deserve a copy for your help.
     
  12. Cableguy

    Cableguy Expert Licensed User

    I like that apoach to a "beta test user" control...
    Nice thinking...
     
  13. taximania

    taximania Well-Known Member Licensed User

    PM me mate :sign0060:
     
  14. Stellaferox

    Stellaferox Active Member Licensed User

    Having played around with your program and generally speaking I also like the idea of beta-testing for full members.
    Marc
     
  15. taximania

    taximania Well-Known Member Licensed User

    I need time to redo my Hiscores tables now. :sign0137:
    They don't work any more.

    Give me time to have a ('thunk', (A Boza/Derbyshire phrase)), about this one :confused:
     
  16. taximania

    taximania Well-Known Member Licensed User

    Er, just checked the forum member list. 717 members. I don't know how many are fully paid members.

    I might change this offer to, 'Let a few of the more, 'regular', posters who I have regular replies/posts with', have a copy.
    Personal versions for all will take to much of my time.
    'Tis' my decision at the end of the day.

    The programs all sorted now :sign0098:

    If you think you fit the category and want a copy, PM me your email.
    Don't be disappointed if you don't get a copy.

    I am intending to try and sell the game or the code after all.
     
Loading...