Help with using variables


Closed Thread
Results 1 to 3 of 3
  1. #1
    jessey's Avatar
    jessey Guest

    Default Help with using variables

    Hello,

    I was wondering if someone could review some code I wrote and make suggestions on any different approaches or more efficient ways of accomplishing this? I have these 2 segments of code that will be read in the mainloop. Of these 2 segments of code only one will be true so only one will be executed. When I first apply power to the circuit then one of these blocks of code is only executed once and also whenever I switch from operating the circuit on batteries to a 120 VAC transformer (or vise versa) then the other code segment will be true and will be executed again but only once while in the mainloop. The reason that I want to do this is that I have other If...Then statements that use this same variable to accomplish other tasks in the mainloop.

    Here are the two segments code:

    Circuit_Is_Powered_By VAR PORTC.5 'when the transformer is plugged in, a 1 is placed here.
    The_Transformer CON 1
    The_Batteries CON 0

    IF Circuit_Is_Powered_By = The_Batteries THEN
    U = 0
    ELSE
    U = U + 1
    ENDIF
    IF U >= 2 THEN U = 2 'prevents the var from rolling over & equaling 1 again


    '----------------------- First Segment Of Code -----------------------------'
    IF Circuit_Is_Powered_By = The_Transformer AND U = 1 THEN

    this is where I place the code that I want to be read only
    once whenever the transformer is powering the circuit.

    ENDIF


    ----------------------------------------------------------------------------------------------------------------


    IF Circuit_Is_Powered_By = The_Transformer THEN
    V = 0
    ELSE
    V = V + 1
    ENDIF
    IF V >= 2 THEN V = 2 'prevents the var from rolling over & equaling 1 again


    '---------------------- Second Segment Of Code -----------------------------'
    IF Circuit_Is_Powered_By = The_Batteries AND V = 1 THEN

    this is where I place the code that I want to be read only
    once whenever the batteries are powering the circuit

    ENDIF
    ----------------------------------------------------------------------------------------------------------------

    Any comments or suggestions will be gratefully accepted.

    Thanks jessey

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    you could also use SELECT CASE
    Code:
    select case MyVar
         case XYZ
              ' according stuff 
         case XYZ AND ABC
              ' according stuff
         end select
    but i've never try with the AND in a select case... but it should work.

    Case not
    Code:
    select case MyVar
         Case ABC
              If Myvar=XYZ then
                   'According stuff for Myvar = ABC AND =XYZ
         end select
    Last edited by mister_e; - 19th June 2005 at 08:53.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Oct 2004
    Location
    Hangover, Germany
    Posts
    289


    Did you find this post helpful? Yes | No

    Default

    Hello,

    it's hard for me to understand your problem.
    What does it matters with the headline ?

Similar Threads

  1. Max Variables
    By shawn in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 19th January 2008, 04:05
  2. Changing declared variables names on the fly
    By jessey in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 16th December 2006, 06:34
  3. Variables not appearing in Watch Window MPLabv7.3
    By jd76duke in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 16th June 2006, 14:36
  4. edit names of variables
    By mischl in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 13th January 2005, 21:00
  5. Problems with variables
    By egberttheone in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 15th December 2004, 18:37

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts