Jump to content

Ohm's Law Calculator


The Buzzard

Recommended Posts

My guess is c$plex function need to remain as a separate function within my code. I would also think instead of an alert I would have to call the function from within my calculation statements for square roots.

 

Not sure how to do this exactly. If I am on the right track would you please let me know.

 

Looking at your code, the easiest way to do it would be to check whether the product (or quotient) within the sqrt function is positive or negative, then use a variable set to a string which would either be an empty string "" (for +ve), or "i" (for -ve). Then just concatenate this string variable to the answer before printing it to the dialog. :)

Link to comment
Share on other sites

  • Replies 104
  • Created
  • Last Reply

Top Posters In This Topic

  • The Buzzard

    56

  • Lee Mac

    29

  • CAB

    11

  • SEANT

    3

Top Posters In This Topic

Posted Images

For example:

 

(defun OLC_CAI ()
 (setq [color=Red][b]c$plex ""[/b][/color] SFN (nth SFN SFN_list))

 (cond ((or (and (member SFN '("1" "4" "6"))
                 (zerop KV4))
            (and (= SFN "5")
                 (zerop KV3))
            (and (member SFN '("8" "10" "12"))
                 (zerop KV2))
            (and (= SFN "11")
                 (zerop KV1)))
        (OLC_DBZ))
       ((= "1" SFN)
        (setq E KV3 R KV4 I (/ E R) P (/ (* E E) R)))
       ((= "2" SFN)
        (setq I KV2 R KV4 E (* R I) P (* I I R)))
       ((= "3" SFN)
        (setq E KV3 I KV2 R (/ E I) P (* E I)))
       ((= "4" SFN)
[color=Red][b]         (and (minusp (* P R)) (setq c$plex "i"))[/b][/color]
        (setq P KV1 R KV4 E (sqrt (* P R)) I (sqrt (/ P R))))
       ((= "5" SFN)
        (setq P KV1 E KV3 R (/ (* E E) P) I (/ P E)))
       ((= "6" SFN)
        (setq E KV3 R KV4 P (/ (* E E) R) I (/ E R)))
       ((= "7" SFN)
        (setq I KV2 R KV4 P (* I I R) E (* R I)))
       ((= "8" SFN)
        (setq P KV1 I KV2 R (/ P (* I I)) E (/ P I)))
       ((= "9" SFN)         
[b][color=Red]         (and (minusp (* P R)) (setq c$plex "i"))[/color][/b]
        (setq P KV1 R KV4 I (sqrt (/ P R)) E (sqrt (* P R))))
       ((= "10" SFN)
        (setq E KV3 I KV2 P (* E I) R (/ E I)))
       ((= "11" SFN)
        (setq P KV1 E KV3 I (/ P E) R (/ (* E E) P)))
       ((= "12" SFN)
        (setq P KV1 I KV2 E (/ P I) R (/ P (* I I)))))
 (OLC_DCO))

Then just use strcat to concatenate the answer with the variabel c$plex before printing the answer to the dialog. :)

Link to comment
Share on other sites

For example:

 

(defun OLC_CAI ()
 (setq [color=red][b]c$plex ""[/b][/color] SFN (nth SFN SFN_list))

 (cond ((or (and (member SFN '("1" "4" "6"))
                 (zerop KV4))
            (and (= SFN "5")
                 (zerop KV3))
            (and (member SFN '("8" "10" "12"))
                 (zerop KV2))
            (and (= SFN "11")
                 (zerop KV1)))
        (OLC_DBZ))
       ((= "1" SFN)
        (setq E KV3 R KV4 I (/ E R) P (/ (* E E) R)))
       ((= "2" SFN)
        (setq I KV2 R KV4 E (* R I) P (* I I R)))
       ((= "3" SFN)
        (setq E KV3 I KV2 R (/ E I) P (* E I)))
       ((= "4" SFN)
[color=red][b]     (and (minusp (* P R)) (setq c$plex "i"))[/b][/color]
        (setq P KV1 R KV4 E (sqrt (* P R)) I (sqrt (/ P R))))
       ((= "5" SFN)
        (setq P KV1 E KV3 R (/ (* E E) P) I (/ P E)))
       ((= "6" SFN)
        (setq E KV3 R KV4 P (/ (* E E) R) I (/ E R)))
       ((= "7" SFN)
        (setq I KV2 R KV4 P (* I I R) E (* R I)))
       ((= "8" SFN)
        (setq P KV1 I KV2 R (/ P (* I I)) E (/ P I)))
       ((= "9" SFN)         
[b][color=red]     (and (minusp (* P R)) (setq c$plex "i"))[/color][/b]
        (setq P KV1 R KV4 I (sqrt (/ P R)) E (sqrt (* P R))))
       ((= "10" SFN)
        (setq E KV3 I KV2 P (* E I) R (/ E I)))
       ((= "11" SFN)
        (setq P KV1 E KV3 I (/ P E) R (/ (* E E) P)))
       ((= "12" SFN)
        (setq P KV1 I KV2 E (/ P I) R (/ P (* I I)))))
 (OLC_DCO))

Then just use strcat to concatenate the answer with the variabel c$plex before printing the answer to the dialog. :)

 

 

OK Lee,

 

I think I did what you showed me and got bad augument type error.

 

Here is the calculation function with the output function.

;;; F03 - Calculate Function - Calculate All Inputs.                           ;Describe function
(defun OLC_CAI ()                                                              ;Define function
 (setq [color=red]c$plex ""[/color] SFN (nth SFN SFN_list))                                      ;Return the nth element of the list 
 (cond                                                                        ;If one of the following conditions apply
   ((or                                                                       ;Return the logical OR of a list of expressions
      (and                                                                    ;Return the logical AND of the supplied arguments
        (member SFN '("1" "4" "6"))                                           ;Search list for an occurrence of an expression 
        (zerop KV4)                                                           ;Verify that a number evaluates to zero 
      )                                                                       ;End and
      (and                                                                    ;Return the logical AND of the supplied arguments
        (= SFN "5")                                                           ;SFN ~ (Select Formula No.) = 5
        (zerop KV3)                                                           ;Verify that a number evaluates to zero 
      )                                                                       ;End and
      (and                                                                    ;Return the logical AND of the supplied arguments
        (member SFN '("8" "10" "12"))                                         ;Search list for an occurrence of an expression 
        (zerop KV2)                                                           ;Verify that a number evaluates to zero 
      )                                                                       ;End and
      (and                                                                    ;Return the logical AND of the supplied arguments
        (= SFN "11")                                                          ;SFN ~ (Select Formula No.) = 11
        (zerop KV1)                                                           ;Verify that a number evaluates to zero 
      )                                                                       ;End and
    )                                                                         ;End or
    (OLC_DBZ))                                                                ;Goto OLC_DBZ Error Function
   ((= "1" SFN)                                                               ;SFN ~ (Select Formula No.) = 1
    (setq E KV3 R KV4 I (/ E R) P (/ (* E E) R)))                             ;Calculate I ~ (Current) & P ~ (Power)
   ((= "2" SFN)                                                               ;SFN ~ (Select Formula No.) = 2
    (setq I KV2 R KV4 E (* R I) P (* I I R)))                                 ;Calculate E ~ (Voltage) & P ~ (Power)
   ((= "3" SFN)                                                               ;SFN ~ (Select Formula No.) = 3
    (setq E KV3 I KV2 R (/ E I) P (* E I)))                                   ;Calculate R ~ (Resistance) & P ~ (Power)
   ((= "4" SFN)                                                               ;SFN ~ (Select Formula No.) = 4
    [color=red](and (minusp (* P R)) (setq c$plex "i"))[/color]
    (setq P KV1 R KV4 E (sqrt (* P R)) I (sqrt (/ P R))))                     ;Calculate E ~ (Voltage) & I ~ (Current)
   ((= "5" SFN)                                                               ;SFN ~ (Select Formula No.) = 5
    (setq P KV1 E KV3 R (/ (* E E) P) I (/ P E)))                             ;Calculate R ~ (Resistance) & I ~ (Current)
   ((= "6" SFN)                                                               ;SFN ~ (Select Formula No.) = 6
    (setq E KV3 R KV4 P (/ (* E E) R) I (/ E R)))                             ;Calculate P ~ (Power) & I ~ (Current)
   ((= "7" SFN)                                                               ;SFN ~ (Select Formula No.) = 7
    (setq I KV2 R KV4 P (* I I R) E (* R I)))                                 ;Calculate P ~ (Power) & E ~ (Voltage)
   ((= "8" SFN)                                                               ;SFN ~ (Select Formula No.) = 8
    (setq P KV1 I KV2 R (/ P (* I I)) E (/ P I)))                             ;Calculate R ~ (Resistance) & E ~ (Voltage)
   ((= "9" SFN)                                                               ;SFN ~ (Select Formula No.) = 9
    [color=red](and (minusp (* P R)) (setq c$plex "i"))[/color]
    (setq P KV1 R KV4 I (sqrt (/ P R)) E (sqrt (* P R))))                     ;Calculate I ~ (Current) & E ~ (Voltage)
   ((= "10" SFN)                                                              ;SFN ~ (Select Formula No.) = 10
    (setq E KV3 I KV2 P (* E I) R (/ E I)))                                   ;Calculate P ~ (Power) & R ~ (Resistance)
   ((= "11" SFN)                                                              ;SFN ~ (Select Formula No.) = 11
    (setq P KV1 E KV3 I (/ P E) R (/ (* E E) P)))                             ;Calculate I ~ (Current) & R ~ (Resistance)
   ((= "12" SFN)                                                              ;SFN ~ (Select Formula No.) = 12
    (setq P KV1 I KV2 E (/ P I) R (/ P (* I I))))                             ;Calculate E ~ (Voltage) & R ~ (Resistance)
 )                                                                            ;End cond
 (OLC_DCO)                                                                    ;Go to OLC_DCO Output Function
)                                                                              ;End define function
;;;////////////////////////////////////////////////////////////////////////////
;;; F04 - Reset Function - Reset All Calculations.                             ;Describe function
(defun OLC_RAC ()                                                              ;Define function
 (set_tile "kV1" "")                                                          ;Set tile kV1 to blank
 (set_tile "kV2" "")                                                          ;Set tile kV2 to blank
 (set_tile "kV3" "")                                                          ;Set tile kV3 to blank
 (set_tile "kV4" "")                                                          ;Set tile kV4 to blank
)                                                                              ;End define function
;;;////////////////////////////////////////////////////////////////////////////
;;; F05 - Output Function - Display Calculated Output.                         ;Describe function
(defun OLC_DCO ()                                                              ;Define function
 (cond                                                                        ;If one of the following conditions apply
   ((member SFN '("1" "6"))                                                   ;Search list for an occurrence of an expression 
    (setq P (RTOS P 2 1))                                                     ;Set P ~ (Power), Return to string, Decimal, 1 zero
    (set_tile "kV1" P)                                                        ;Set tile kV1 to value of P
    (setq I (RTOS I 2 1))                                                     ;Set I ~ (Current), Return to string, Decimal, 1 zero
    (set_tile "kV2" I))                                                       ;Set tile kV2 to value of I
   ((member SFN '("2" "7"))                                                   ;Search list for an occurrence of an expression 
    (setq P (RTOS P 2 1))                                                     ;Set P ~ (Power), Return to string, Decimal, 1 zero
    (set_tile "kV1" P)                                                        ;Set tile kV1 to value of P
    (setq E (RTOS E 2 1))                                                     ;Set E ~ (Voltage), Return to string, Decimal, 1 zero
    (set_tile "kV3" E))                                                       ;Set tile kV3 to value of E
   ((member SFN '("3" "10"))                                                  ;Search list for an occurrence of an expression 
    (setq P (RTOS P 2 1))                                                     ;Set P ~ (Power), Return to string, Decimal, 1 zero
    (set_tile "kV1" P)                                                        ;Set tile kV1 to value of P
    (setq R (RTOS R 2 1))                                                     ;Set R ~ (Resistance), Return to string, Decimal, 1 zero
    (set_tile "kV4" R))                                                       ;Set tile kV4 to value of R
   ((member SFN '("4" "9"))                                                   ;Search list for an occurrence of an expression 
    (setq I (RTOS I 2 1))                                                     ;Set I ~ (Current), Return to string, Decimal, 1 zero
    [color=red](set_tile "kV2" (strcat "(eval I)""(eval c$plex)"))[/color]                       ;Set tile kV2, Concatenate string evaluate I & c$plex
    (setq E (RTOS E 2 1))                                                     ;Set E ~ (Voltage), Return to string, Decimal, 1 zero
    [color=red](set_tile "kV3" (strcat "(eval E)""(eval c$plex)")))[/color]                      ;Set tile kV3, Concatenate string evaluate I & c$plex
   ((member SFN '("5" "11"))                                                  ;Search list for an occurrence of an expression 
    (setq I (RTOS I 2 1))                                                     ;Set I ~ (Current), Return to string, Decimal, 1 zero
    (set_tile "kV2" I)                                                        ;Set tile kV2 to value of I
    (setq R (RTOS R 2 1))                                                     ;Set R ~ (Resistance), Return to string, Decimal, 1 zero
    (set_tile "kV4" R))                                                       ;Set tile kV4 to value of R
   ((member SFN '("8" "12"))                                                  ;Search list for an occurrence of an expression 
    (setq E (RTOS E 2 1))                                                     ;Set E ~ (Volatge), Return to string, Decimal, 1 zero
    (set_tile "kV3" E)                                                        ;Set tile kV3 to value of E
    (setq R (RTOS R 2 1))                                                     ;Set R ~ (Resistance), Return to string, Decimal, 1 zero
    (set_tile "kV4" R))                                                       ;Set tile kV4 to value of R
 )                                                                            ;End cond
)                                                                              ;End define function
;;;////////////////////////////////////////////////////////////////////////////

 

 

Did I miss something?

Link to comment
Share on other sites

No need for eval as the variable is a string!

Change this

(strcat "(eval I)""(eval c$plex)") 

to this

(strcat I c$plex)

 

 

Unless I is a number at that point, that is confusing me and what I referred to earlier.

 

You should use number I and string I$ or number I# to avoid confusion.

 

Obviously if I is a number at that point you need to convert it to a string.

Link to comment
Share on other sites

No need for eval as the variable is a string!

Change this

(strcat "(eval I)""(eval c$plex)") 

to this

(strcat I c$plex)

 

 

Unless I is a number at that point, that is confusing me and what I referred to earlier.

 

You should use number I and string I$ or number I# to avoid confusion.

 

Obviously if I is a number at that point you need to convert it to a string.

 

Thanks CAB,

 

I am still asleep. I made the fix, But still get a bad argument error anyway. Something is missing.

 

 

;;; F03 - Calculate Function - Calculate All Inputs.                           ;Describe function
(defun OLC_CAI ()                                                              ;Define function
 (setq [color=red]c$plex ""[/color] SFN (nth SFN SFN_list))                                      ;Return the nth element of the list 
 (cond                                                                        ;If one of the following conditions apply
   ((or                                                                       ;Return the logical OR of a list of expressions
      (and                                                                    ;Return the logical AND of the supplied arguments
        (member SFN '("1" "4" "6"))                                           ;Search list for an occurrence of an expression 
        (zerop KV4)                                                           ;Verify that a number evaluates to zero 
      )                                                                       ;End and
      (and                                                                    ;Return the logical AND of the supplied arguments
        (= SFN "5")                                                           ;SFN ~ (Select Formula No.) = 5
        (zerop KV3)                                                           ;Verify that a number evaluates to zero 
      )                                                                       ;End and
      (and                                                                    ;Return the logical AND of the supplied arguments
        (member SFN '("8" "10" "12"))                                         ;Search list for an occurrence of an expression 
        (zerop KV2)                                                           ;Verify that a number evaluates to zero 
      )                                                                       ;End and
      (and                                                                    ;Return the logical AND of the supplied arguments
        (= SFN "11")                                                          ;SFN ~ (Select Formula No.) = 11
        (zerop KV1)                                                           ;Verify that a number evaluates to zero 
      )                                                                       ;End and
    )                                                                         ;End or
    (OLC_DBZ))                                                                ;Goto OLC_DBZ Error Function
   ((= "1" SFN)                                                               ;SFN ~ (Select Formula No.) = 1
    (setq E KV3 R KV4 I (/ E R) P (/ (* E E) R)))                             ;Calculate I ~ (Current) & P ~ (Power)
   ((= "2" SFN)                                                               ;SFN ~ (Select Formula No.) = 2
    (setq I KV2 R KV4 E (* R I) P (* I I R)))                                 ;Calculate E ~ (Voltage) & P ~ (Power)
   ((= "3" SFN)                                                               ;SFN ~ (Select Formula No.) = 3
    (setq E KV3 I KV2 R (/ E I) P (* E I)))                                   ;Calculate R ~ (Resistance) & P ~ (Power)
   ((= "4" SFN)                                                               ;SFN ~ (Select Formula No.) = 4
    [color=red](and (minusp (* P R)) (setq c$plex "i"))[/color]
    (setq P KV1 R KV4 E (sqrt (* P R)) I (sqrt (/ P R))))                     ;Calculate E ~ (Voltage) & I ~ (Current)
   ((= "5" SFN)                                                               ;SFN ~ (Select Formula No.) = 5
    (setq P KV1 E KV3 R (/ (* E E) P) I (/ P E)))                             ;Calculate R ~ (Resistance) & I ~ (Current)
   ((= "6" SFN)                                                               ;SFN ~ (Select Formula No.) = 6
    (setq E KV3 R KV4 P (/ (* E E) R) I (/ E R)))                             ;Calculate P ~ (Power) & I ~ (Current)
   ((= "7" SFN)                                                               ;SFN ~ (Select Formula No.) = 7
    (setq I KV2 R KV4 P (* I I R) E (* R I)))                                 ;Calculate P ~ (Power) & E ~ (Voltage)
   ((= "8" SFN)                                                               ;SFN ~ (Select Formula No.) = 8
    (setq P KV1 I KV2 R (/ P (* I I)) E (/ P I)))                             ;Calculate R ~ (Resistance) & E ~ (Voltage)
   ((= "9" SFN)                                                               ;SFN ~ (Select Formula No.) = 9
    [color=red](and (minusp (* P R)) (setq c$plex "i"))[/color]
    (setq P KV1 R KV4 I (sqrt (/ P R)) E (sqrt (* P R))))                     ;Calculate I ~ (Current) & E ~ (Voltage)
   ((= "10" SFN)                                                              ;SFN ~ (Select Formula No.) = 10
    (setq E KV3 I KV2 P (* E I) R (/ E I)))                                   ;Calculate P ~ (Power) & R ~ (Resistance)
   ((= "11" SFN)                                                              ;SFN ~ (Select Formula No.) = 11
    (setq P KV1 E KV3 I (/ P E) R (/ (* E E) P)))                             ;Calculate I ~ (Current) & R ~ (Resistance)
   ((= "12" SFN)                                                              ;SFN ~ (Select Formula No.) = 12
    (setq P KV1 I KV2 E (/ P I) R (/ P (* I I))))                             ;Calculate E ~ (Voltage) & R ~ (Resistance)
 )                                                                            ;End cond
 (OLC_DCO)                                                                    ;Go to OLC_DCO Output Function
)                                                                              ;End define function
;;;////////////////////////////////////////////////////////////////////////////
;;; F04 - Reset Function - Reset All Calculations.                             ;Describe function
(defun OLC_RAC ()                                                              ;Define function
 (set_tile "kV1" "")                                                          ;Set tile kV1 to blank
 (set_tile "kV2" "")                                                          ;Set tile kV2 to blank
 (set_tile "kV3" "")                                                          ;Set tile kV3 to blank
 (set_tile "kV4" "")                                                          ;Set tile kV4 to blank
)                                                                              ;End define function
;;;////////////////////////////////////////////////////////////////////////////
;;; F05 - Output Function - Display Calculated Output.                         ;Describe function
(defun OLC_DCO ()                                                              ;Define function
 (cond                                                                        ;If one of the following conditions apply
   ((member SFN '("1" "6"))                                                   ;Search list for an occurrence of an expression 
    (setq P (RTOS P 2 1))                                                     ;Set P ~ (Power), Return to string, Decimal, 1 zero
    (set_tile "kV1" P)                                                        ;Set tile kV1 to value of P
    (setq I (RTOS I 2 1))                                                     ;Set I ~ (Current), Return to string, Decimal, 1 zero
    (set_tile "kV2" I))                                                       ;Set tile kV2 to value of I
   ((member SFN '("2" "7"))                                                   ;Search list for an occurrence of an expression 
    (setq P (RTOS P 2 1))                                                     ;Set P ~ (Power), Return to string, Decimal, 1 zero
    (set_tile "kV1" P)                                                        ;Set tile kV1 to value of P
    (setq E (RTOS E 2 1))                                                     ;Set E ~ (Voltage), Return to string, Decimal, 1 zero
    (set_tile "kV3" E))                                                       ;Set tile kV3 to value of E
   ((member SFN '("3" "10"))                                                  ;Search list for an occurrence of an expression 
    (setq P (RTOS P 2 1))                                                     ;Set P ~ (Power), Return to string, Decimal, 1 zero
    (set_tile "kV1" P)                                                        ;Set tile kV1 to value of P
    (setq R (RTOS R 2 1))                                                     ;Set R ~ (Resistance), Return to string, Decimal, 1 zero
    (set_tile "kV4" R))                                                       ;Set tile kV4 to value of R
   ((member SFN '("4" "9"))                                                   ;Search list for an occurrence of an expression 
    (setq I (RTOS I 2 1))                                                     ;Set I ~ (Current), Return to string, Decimal, 1 zero
    [color=red](set_tile "kV2" (strcat I c$plex))[/color]                                        ;Set tile kV2, Concatenate string I & c$plex
    (setq E (RTOS E 2 1))                                                     ;Set E ~ (Voltage), Return to string, Decimal, 1 zero
    [color=red](set_tile "kV3" (strcat E c$plex)))[/color]                                       ;Set tile kV3, Concatenate string E & c$plex
   ((member SFN '("5" "11"))                                                  ;Search list for an occurrence of an expression 
    (setq I (RTOS I 2 1))                                                     ;Set I ~ (Current), Return to string, Decimal, 1 zero
    (set_tile "kV2" I)                                                        ;Set tile kV2 to value of I
    (setq R (RTOS R 2 1))                                                     ;Set R ~ (Resistance), Return to string, Decimal, 1 zero
    (set_tile "kV4" R))                                                       ;Set tile kV4 to value of R
   ((member SFN '("8" "12"))                                                  ;Search list for an occurrence of an expression 
    (setq E (RTOS E 2 1))                                                     ;Set E ~ (Volatge), Return to string, Decimal, 1 zero
    (set_tile "kV3" E)                                                        ;Set tile kV3 to value of E
    (setq R (RTOS R 2 1))                                                     ;Set R ~ (Resistance), Return to string, Decimal, 1 zero
    (set_tile "kV4" R))                                                       ;Set tile kV4 to value of R
 )                                                                            ;End cond
)                                                                              ;End define function
;;;////////////////////////////////////////////////////////////////////////////

Link to comment
Share on other sites

If I is a number use this:

(strcat (vl-princ-to-string i) c$plex)

 

Sorry,

 

I have to walk away from this one for a while. I am exhausted.

Link to comment
Share on other sites

Buzzard, sorry, I had them in the wrong order:

 

;;; F03 - Calculate Function - Calculate All Inputs.                           ;Describe function
(defun OLC_CAI ()                                                              ;Define function
 (setq c$plex "" SFN (nth SFN SFN_list))                                      ;Return the nth element of the list 
 (cond                                                                        ;If one of the following conditions apply
   ((or                                                                       ;Return the logical OR of a list of expressions
      (and                                                                    ;Return the logical AND of the supplied arguments
        (member SFN '("1" "4" "6"))                                           ;Search list for an occurrence of an expression 
        (zerop KV4)                                                           ;Verify that a number evaluates to zero 
      )                                                                       ;End and
      (and                                                                    ;Return the logical AND of the supplied arguments
        (= SFN "5")                                                           ;SFN ~ (Select Formula No.) = 5
        (zerop KV3)                                                           ;Verify that a number evaluates to zero 
      )                                                                       ;End and
      (and                                                                    ;Return the logical AND of the supplied arguments
        (member SFN '("8" "10" "12"))                                         ;Search list for an occurrence of an expression 
        (zerop KV2)                                                           ;Verify that a number evaluates to zero 
      )                                                                       ;End and
      (and                                                                    ;Return the logical AND of the supplied arguments
        (= SFN "11")                                                          ;SFN ~ (Select Formula No.) = 11
        (zerop KV1)                                                           ;Verify that a number evaluates to zero 
      )                                                                       ;End and
    )                                                                         ;End or
    (OLC_DBZ))                                                                ;Goto OLC_DBZ Error Function
   ((= "1" SFN)                                                               ;SFN ~ (Select Formula No.) = 1
    (setq E KV3 R KV4 I (/ E R) P (/ (* E E) R)))                             ;Calculate I ~ (Current) & P ~ (Power)
   ((= "2" SFN)                                                               ;SFN ~ (Select Formula No.) = 2
    (setq I KV2 R KV4 E (* R I) P (* I I R)))                                 ;Calculate E ~ (Voltage) & P ~ (Power)
   ((= "3" SFN)                                                               ;SFN ~ (Select Formula No.) = 3
    (setq E KV3 I KV2 R (/ E I) P (* E I)))                                   ;Calculate R ~ (Resistance) & P ~ (Power)
   ((= "4" SFN)                                                               ;SFN ~ (Select Formula No.) = 4     
    (setq P KV1 R KV4 E (sqrt (* P R)) I (sqrt [b][color=Red](abs[/color][/b] (/ P R)))))                     ;Calculate E ~ (Voltage) & I ~ (Current)
    [color=Red][b](and (minusp (* P R)) (setq c$plex "i"))[/b][/color]
   ((= "5" SFN)                                                               ;SFN ~ (Select Formula No.) = 5
    (setq P KV1 E KV3 R (/ (* E E) P) I (/ P E)))                             ;Calculate R ~ (Resistance) & I ~ (Current)
   ((= "6" SFN)                                                               ;SFN ~ (Select Formula No.) = 6
    (setq E KV3 R KV4 P (/ (* E E) R) I (/ E R)))                             ;Calculate P ~ (Power) & I ~ (Current)
   ((= "7" SFN)                                                               ;SFN ~ (Select Formula No.) = 7
    (setq I KV2 R KV4 P (* I I R) E (* R I)))                                 ;Calculate P ~ (Power) & E ~ (Voltage)
   ((= "8" SFN)                                                               ;SFN ~ (Select Formula No.) = 8
    (setq P KV1 I KV2 R (/ P (* I I)) E (/ P I)))                             ;Calculate R ~ (Resistance) & E ~ (Voltage)
   ((= "9" SFN)                                                               ;SFN ~ (Select Formula No.) = 9     
    (setq P KV1 R KV4 I (sqrt (/ P R)) E (sqrt [color=Red][b](abs [/b][/color](* P R)))))                     ;Calculate I ~ (Current) & E ~ (Voltage)
    [b][color=Red](and (minusp (* P R)) (setq c$plex "i"))[/color][/b]
   ((= "10" SFN)                                                              ;SFN ~ (Select Formula No.) = 10
    (setq E KV3 I KV2 P (* E I) R (/ E I)))                                   ;Calculate P ~ (Power) & R ~ (Resistance)
   ((= "11" SFN)                                                              ;SFN ~ (Select Formula No.) = 11
    (setq P KV1 E KV3 I (/ P E) R (/ (* E E) P)))                             ;Calculate I ~ (Current) & R ~ (Resistance)
   ((= "12" SFN)                                                              ;SFN ~ (Select Formula No.) = 12
    (setq P KV1 I KV2 E (/ P I) R (/ P (* I I))))                             ;Calculate E ~ (Voltage) & R ~ (Resistance)
 )                                                                            ;End cond
 (OLC_DCO)                                                                    ;Go to OLC_DCO Output Function
)                                                                              ;End define function
;;;////////////////////////////////////////////////////////////////////////////
;;; F04 - Reset Function - Reset All Calculations.                             ;Describe function
(defun OLC_RAC ()                                                              ;Define function
 (set_tile "kV1" "")                                                          ;Set tile kV1 to blank
 (set_tile "kV2" "")                                                          ;Set tile kV2 to blank
 (set_tile "kV3" "")                                                          ;Set tile kV3 to blank
 (set_tile "kV4" "")                                                          ;Set tile kV4 to blank
)                                                                              ;End define function
;;;////////////////////////////////////////////////////////////////////////////
;;; F05 - Output Function - Display Calculated Output.                         ;Describe function
(defun OLC_DCO ()                                                              ;Define function
 (cond                                                                        ;If one of the following conditions apply
   ((member SFN '("1" "6"))                                                   ;Search list for an occurrence of an expression 
    (setq P (RTOS P 2 1))                                                     ;Set P ~ (Power), Return to string, Decimal, 1 zero
    (set_tile "kV1" P)                                                        ;Set tile kV1 to value of P
    (setq I (RTOS I 2 1))                                                     ;Set I ~ (Current), Return to string, Decimal, 1 zero
    (set_tile "kV2" I))                                                       ;Set tile kV2 to value of I
   ((member SFN '("2" "7"))                                                   ;Search list for an occurrence of an expression 
    (setq P (RTOS P 2 1))                                                     ;Set P ~ (Power), Return to string, Decimal, 1 zero
    (set_tile "kV1" P)                                                        ;Set tile kV1 to value of P
    (setq E (RTOS E 2 1))                                                     ;Set E ~ (Voltage), Return to string, Decimal, 1 zero
    (set_tile "kV3" E))                                                       ;Set tile kV3 to value of E
   ((member SFN '("3" "10"))                                                  ;Search list for an occurrence of an expression 
    (setq P (RTOS P 2 1))                                                     ;Set P ~ (Power), Return to string, Decimal, 1 zero
    (set_tile "kV1" P)                                                        ;Set tile kV1 to value of P
    (setq R (RTOS R 2 1))                                                     ;Set R ~ (Resistance), Return to string, Decimal, 1 zero
    (set_tile "kV4" R))                                                       ;Set tile kV4 to value of R
   ((member SFN '("4" "9"))                                                   ;Search list for an occurrence of an expression 
    (setq I (RTOS I 2 1))                                                     ;Set I ~ (Current), Return to string, Decimal, 1 zero
    (set_tile "kV2" (strcat I c$plex))                                        ;Set tile kV2, Concatenate string I & c$plex
    (setq E (RTOS E 2 1))                                                     ;Set E ~ (Voltage), Return to string, Decimal, 1 zero
    (set_tile "kV3" (strcat E c$plex)))                                       ;Set tile kV3, Concatenate string E & c$plex
   ((member SFN '("5" "11"))                                                  ;Search list for an occurrence of an expression 
    (setq I (RTOS I 2 1))                                                     ;Set I ~ (Current), Return to string, Decimal, 1 zero
    (set_tile "kV2" I)                                                        ;Set tile kV2 to value of I
    (setq R (RTOS R 2 1))                                                     ;Set R ~ (Resistance), Return to string, Decimal, 1 zero
    (set_tile "kV4" R))                                                       ;Set tile kV4 to value of R
   ((member SFN '("8" "12"))                                                  ;Search list for an occurrence of an expression 
    (setq E (RTOS E 2 1))                                                     ;Set E ~ (Volatge), Return to string, Decimal, 1 zero
    (set_tile "kV3" E)                                                        ;Set tile kV3 to value of E
    (setq R (RTOS R 2 1))                                                     ;Set R ~ (Resistance), Return to string, Decimal, 1 zero
    (set_tile "kV4" R))                                                       ;Set tile kV4 to value of R
 )                                                                            ;End cond
)                                                                              ;End define function
;;;////////////////////////////////////////////////////////////////////////////

The test needed to be after the variables were set - sorry, I only added it quickly

Link to comment
Share on other sites

Buzzard, sorry, I had them in the wrong order:

 

;;; F03 - Calculate Function - Calculate All Inputs.                           ;Describe function
(defun OLC_CAI ()                                                              ;Define function
 (setq c$plex "" SFN (nth SFN SFN_list))                                      ;Return the nth element of the list 
 (cond                                                                        ;If one of the following conditions apply
   ((or                                                                       ;Return the logical OR of a list of expressions
      (and                                                                    ;Return the logical AND of the supplied arguments
        (member SFN '("1" "4" "6"))                                           ;Search list for an occurrence of an expression 
        (zerop KV4)                                                           ;Verify that a number evaluates to zero 
      )                                                                       ;End and
      (and                                                                    ;Return the logical AND of the supplied arguments
        (= SFN "5")                                                           ;SFN ~ (Select Formula No.) = 5
        (zerop KV3)                                                           ;Verify that a number evaluates to zero 
      )                                                                       ;End and
      (and                                                                    ;Return the logical AND of the supplied arguments
        (member SFN '("8" "10" "12"))                                         ;Search list for an occurrence of an expression 
        (zerop KV2)                                                           ;Verify that a number evaluates to zero 
      )                                                                       ;End and
      (and                                                                    ;Return the logical AND of the supplied arguments
        (= SFN "11")                                                          ;SFN ~ (Select Formula No.) = 11
        (zerop KV1)                                                           ;Verify that a number evaluates to zero 
      )                                                                       ;End and
    )                                                                         ;End or
    (OLC_DBZ))                                                                ;Goto OLC_DBZ Error Function
   ((= "1" SFN)                                                               ;SFN ~ (Select Formula No.) = 1
    (setq E KV3 R KV4 I (/ E R) P (/ (* E E) R)))                             ;Calculate I ~ (Current) & P ~ (Power)
   ((= "2" SFN)                                                               ;SFN ~ (Select Formula No.) = 2
    (setq I KV2 R KV4 E (* R I) P (* I I R)))                                 ;Calculate E ~ (Voltage) & P ~ (Power)
   ((= "3" SFN)                                                               ;SFN ~ (Select Formula No.) = 3
    (setq E KV3 I KV2 R (/ E I) P (* E I)))                                   ;Calculate R ~ (Resistance) & P ~ (Power)
   ((= "4" SFN)                                                               ;SFN ~ (Select Formula No.) = 4     
    (setq P KV1 R KV4 E (sqrt (* P R)) I (sqrt [b][color=red](abs[/color][/b] (/ P R)))))                     ;Calculate E ~ (Voltage) & I ~ (Current)
    [color=red][b](and (minusp (* P R)) (setq c$plex "i"))[/b][/color]
   ((= "5" SFN)                                                               ;SFN ~ (Select Formula No.) = 5
    (setq P KV1 E KV3 R (/ (* E E) P) I (/ P E)))                             ;Calculate R ~ (Resistance) & I ~ (Current)
   ((= "6" SFN)                                                               ;SFN ~ (Select Formula No.) = 6
    (setq E KV3 R KV4 P (/ (* E E) R) I (/ E R)))                             ;Calculate P ~ (Power) & I ~ (Current)
   ((= "7" SFN)                                                               ;SFN ~ (Select Formula No.) = 7
    (setq I KV2 R KV4 P (* I I R) E (* R I)))                                 ;Calculate P ~ (Power) & E ~ (Voltage)
   ((= "8" SFN)                                                               ;SFN ~ (Select Formula No.) = 8
    (setq P KV1 I KV2 R (/ P (* I I)) E (/ P I)))                             ;Calculate R ~ (Resistance) & E ~ (Voltage)
   ((= "9" SFN)                                                               ;SFN ~ (Select Formula No.) = 9     
    (setq P KV1 R KV4 I (sqrt (/ P R)) E (sqrt [color=red][b](abs [/b][/color](* P R)))))                     ;Calculate I ~ (Current) & E ~ (Voltage)
    [b][color=red](and (minusp (* P R)) (setq c$plex "i"))[/color][/b]
   ((= "10" SFN)                                                              ;SFN ~ (Select Formula No.) = 10
    (setq E KV3 I KV2 P (* E I) R (/ E I)))                                   ;Calculate P ~ (Power) & R ~ (Resistance)
   ((= "11" SFN)                                                              ;SFN ~ (Select Formula No.) = 11
    (setq P KV1 E KV3 I (/ P E) R (/ (* E E) P)))                             ;Calculate I ~ (Current) & R ~ (Resistance)
   ((= "12" SFN)                                                              ;SFN ~ (Select Formula No.) = 12
    (setq P KV1 I KV2 E (/ P I) R (/ P (* I I))))                             ;Calculate E ~ (Voltage) & R ~ (Resistance)
 )                                                                            ;End cond
 (OLC_DCO)                                                                    ;Go to OLC_DCO Output Function
)                                                                              ;End define function
;;;////////////////////////////////////////////////////////////////////////////
;;; F04 - Reset Function - Reset All Calculations.                             ;Describe function
(defun OLC_RAC ()                                                              ;Define function
 (set_tile "kV1" "")                                                          ;Set tile kV1 to blank
 (set_tile "kV2" "")                                                          ;Set tile kV2 to blank
 (set_tile "kV3" "")                                                          ;Set tile kV3 to blank
 (set_tile "kV4" "")                                                          ;Set tile kV4 to blank
)                                                                              ;End define function
;;;////////////////////////////////////////////////////////////////////////////
;;; F05 - Output Function - Display Calculated Output.                         ;Describe function
(defun OLC_DCO ()                                                              ;Define function
 (cond                                                                        ;If one of the following conditions apply
   ((member SFN '("1" "6"))                                                   ;Search list for an occurrence of an expression 
    (setq P (RTOS P 2 1))                                                     ;Set P ~ (Power), Return to string, Decimal, 1 zero
    (set_tile "kV1" P)                                                        ;Set tile kV1 to value of P
    (setq I (RTOS I 2 1))                                                     ;Set I ~ (Current), Return to string, Decimal, 1 zero
    (set_tile "kV2" I))                                                       ;Set tile kV2 to value of I
   ((member SFN '("2" "7"))                                                   ;Search list for an occurrence of an expression 
    (setq P (RTOS P 2 1))                                                     ;Set P ~ (Power), Return to string, Decimal, 1 zero
    (set_tile "kV1" P)                                                        ;Set tile kV1 to value of P
    (setq E (RTOS E 2 1))                                                     ;Set E ~ (Voltage), Return to string, Decimal, 1 zero
    (set_tile "kV3" E))                                                       ;Set tile kV3 to value of E
   ((member SFN '("3" "10"))                                                  ;Search list for an occurrence of an expression 
    (setq P (RTOS P 2 1))                                                     ;Set P ~ (Power), Return to string, Decimal, 1 zero
    (set_tile "kV1" P)                                                        ;Set tile kV1 to value of P
    (setq R (RTOS R 2 1))                                                     ;Set R ~ (Resistance), Return to string, Decimal, 1 zero
    (set_tile "kV4" R))                                                       ;Set tile kV4 to value of R
   ((member SFN '("4" "9"))                                                   ;Search list for an occurrence of an expression 
    (setq I (RTOS I 2 1))                                                     ;Set I ~ (Current), Return to string, Decimal, 1 zero
    (set_tile "kV2" (strcat I c$plex))                                        ;Set tile kV2, Concatenate string I & c$plex
    (setq E (RTOS E 2 1))                                                     ;Set E ~ (Voltage), Return to string, Decimal, 1 zero
    (set_tile "kV3" (strcat E c$plex)))                                       ;Set tile kV3, Concatenate string E & c$plex
   ((member SFN '("5" "11"))                                                  ;Search list for an occurrence of an expression 
    (setq I (RTOS I 2 1))                                                     ;Set I ~ (Current), Return to string, Decimal, 1 zero
    (set_tile "kV2" I)                                                        ;Set tile kV2 to value of I
    (setq R (RTOS R 2 1))                                                     ;Set R ~ (Resistance), Return to string, Decimal, 1 zero
    (set_tile "kV4" R))                                                       ;Set tile kV4 to value of R
   ((member SFN '("8" "12"))                                                  ;Search list for an occurrence of an expression 
    (setq E (RTOS E 2 1))                                                     ;Set E ~ (Volatge), Return to string, Decimal, 1 zero
    (set_tile "kV3" E)                                                        ;Set tile kV3 to value of E
    (setq R (RTOS R 2 1))                                                     ;Set R ~ (Resistance), Return to string, Decimal, 1 zero
    (set_tile "kV4" R))                                                       ;Set tile kV4 to value of R
 )                                                                            ;End cond
)                                                                              ;End define function
;;;////////////////////////////////////////////////////////////////////////////

The test needed to be after the variables were set - sorry, I only added it quickly

 

 

 

Lee, I get this error - C ; error: bad argument type: numberp: nil

Link to comment
Share on other sites

Lee, I get this error - C ; error: bad argument type: numberp: nil

 

 

Lee, I also got a divide by zero error on formula 3. I can understand why, But not sure what to do about it since the code was made shorter.

 

    ((= "3" SFN)                                                               ;SFN ~ (Select Formula No.) = 3
    (setq E KV3 I KV2 R (/ E I) P (* E I)))                                   ;Calculate R ~ (Resistance) & P ~ (Power)

Link to comment
Share on other sites

Formula 3 wasn't included in our zero check, which is why it returned an error.

 

As for the other error - I will never edit code in this reply box ever again, just a simple bracket mix up:

 

;;; F03 - Calculate Function - Calculate All Inputs.                           ;Describe function
(defun OLC_CAI ()                                                              ;Define function
 (setq c$plex "" SFN (nth SFN SFN_list))                                      ;Return the nth element of the list 
 (cond                                                                        ;If one of the following conditions apply
   ((or                                                                       ;Return the logical OR of a list of expressions
      (and                                                                    ;Return the logical AND of the supplied arguments
        (member SFN '("1" "4" "6"))                                           ;Search list for an occurrence of an expression 
        (zerop KV4)                                                           ;Verify that a number evaluates to zero 
      )                                                                       ;End and
      (and                                                                    ;Return the logical AND of the supplied arguments
        (= SFN "5")                                                           ;SFN ~ (Select Formula No.) = 5
        (zerop KV3)                                                           ;Verify that a number evaluates to zero 
      )                                                                       ;End and
      (and                                                                    ;Return the logical AND of the supplied arguments
        (member SFN '("3" "8" "10" "12"))                                     ;Search list for an occurrence of an expression 
        (zerop KV2)                                                           ;Verify that a number evaluates to zero 
      )                                                                       ;End and
      (and                                                                    ;Return the logical AND of the supplied arguments
        (= SFN "11")                                                          ;SFN ~ (Select Formula No.) = 11
        (zerop KV1)                                                           ;Verify that a number evaluates to zero 
      )                                                                       ;End and
    )                                                                         ;End or
    (OLC_DBZ))                                                                ;Goto OLC_DBZ Error Function
   ((= "1" SFN)                                                               ;SFN ~ (Select Formula No.) = 1
    (setq E KV3 R KV4 I (/ E R) P (/ (* E E) R)))                             ;Calculate I ~ (Current) & P ~ (Power)
   ((= "2" SFN)                                                               ;SFN ~ (Select Formula No.) = 2
    (setq I KV2 R KV4 E (* R I) P (* I I R)))                                 ;Calculate E ~ (Voltage) & P ~ (Power)
   ((= "3" SFN)                                                               ;SFN ~ (Select Formula No.) = 3
    (setq E KV3 I KV2 R (/ E I) P (* E I)))                                   ;Calculate R ~ (Resistance) & P ~ (Power)
   ((= "4" SFN)                                                               ;SFN ~ (Select Formula No.) = 4     
    (setq P KV1 R KV4 E (sqrt (* P R)) I (sqrt (abs (/ P R))))                ;Calculate E ~ (Voltage) & I ~ (Current)
    (and (minusp (* P R)) (setq c$plex "i")))
   ((= "5" SFN)                                                               ;SFN ~ (Select Formula No.) = 5
    (setq P KV1 E KV3 R (/ (* E E) P) I (/ P E)))                             ;Calculate R ~ (Resistance) & I ~ (Current)
   ((= "6" SFN)                                                               ;SFN ~ (Select Formula No.) = 6
    (setq E KV3 R KV4 P (/ (* E E) R) I (/ E R)))                             ;Calculate P ~ (Power) & I ~ (Current)
   ((= "7" SFN)                                                               ;SFN ~ (Select Formula No.) = 7
    (setq I KV2 R KV4 P (* I I R) E (* R I)))                                 ;Calculate P ~ (Power) & E ~ (Voltage)
   ((= "8" SFN)                                                               ;SFN ~ (Select Formula No.) = 8
    (setq P KV1 I KV2 R (/ P (* I I)) E (/ P I)))                             ;Calculate R ~ (Resistance) & E ~ (Voltage)
   ((= "9" SFN)                                                               ;SFN ~ (Select Formula No.) = 9     
    (setq P KV1 R KV4 I (sqrt (/ P R)) E (sqrt (abs (* P R))))                ;Calculate I ~ (Current) & E ~ (Voltage)
    (and (minusp (* P R)) (setq c$plex "i"))) 
   ((= "10" SFN)                                                              ;SFN ~ (Select Formula No.) = 10
    (setq E KV3 I KV2 P (* E I) R (/ E I)))                                   ;Calculate P ~ (Power) & R ~ (Resistance)
   ((= "11" SFN)                                                              ;SFN ~ (Select Formula No.) = 11
    (setq P KV1 E KV3 I (/ P E) R (/ (* E E) P)))                             ;Calculate I ~ (Current) & R ~ (Resistance)
   ((= "12" SFN)                                                              ;SFN ~ (Select Formula No.) = 12
    (setq P KV1 I KV2 E (/ P I) R (/ P (* I I))))                             ;Calculate E ~ (Voltage) & R ~ (Resistance)
 )                                                                            ;End cond
 (OLC_DCO)                                                                    ;Go to OLC_DCO Output Function
)                                                                              ;End define function
;;;////////////////////////////////////////////////////////////////////////////
;;; F04 - Reset Function - Reset All Calculations.                             ;Describe function
(defun OLC_RAC ()                                                              ;Define function
 (set_tile "kV1" "")                                                          ;Set tile kV1 to blank
 (set_tile "kV2" "")                                                          ;Set tile kV2 to blank
 (set_tile "kV3" "")                                                          ;Set tile kV3 to blank
 (set_tile "kV4" "")                                                          ;Set tile kV4 to blank
)                                                                              ;End define function
;;;////////////////////////////////////////////////////////////////////////////
;;; F05 - Output Function - Display Calculated Output.                         ;Describe function
(defun OLC_DCO ()                                                              ;Define function
 (cond                                                                        ;If one of the following conditions apply
   ((member SFN '("1" "6"))                                                   ;Search list for an occurrence of an expression 
    (setq P (RTOS P 2 1))                                                     ;Set P ~ (Power), Return to string, Decimal, 1 zero
    (set_tile "kV1" P)                                                        ;Set tile kV1 to value of P
    (setq I (RTOS I 2 1))                                                     ;Set I ~ (Current), Return to string, Decimal, 1 zero
    (set_tile "kV2" I))                                                       ;Set tile kV2 to value of I
   ((member SFN '("2" "7"))                                                   ;Search list for an occurrence of an expression 
    (setq P (RTOS P 2 1))                                                     ;Set P ~ (Power), Return to string, Decimal, 1 zero
    (set_tile "kV1" P)                                                        ;Set tile kV1 to value of P
    (setq E (RTOS E 2 1))                                                     ;Set E ~ (Voltage), Return to string, Decimal, 1 zero
    (set_tile "kV3" E))                                                       ;Set tile kV3 to value of E
   ((member SFN '("3" "10"))                                                  ;Search list for an occurrence of an expression 
    (setq P (RTOS P 2 1))                                                     ;Set P ~ (Power), Return to string, Decimal, 1 zero
    (set_tile "kV1" P)                                                        ;Set tile kV1 to value of P
    (setq R (RTOS R 2 1))                                                     ;Set R ~ (Resistance), Return to string, Decimal, 1 zero
    (set_tile "kV4" R))                                                       ;Set tile kV4 to value of R
   ((member SFN '("4" "9"))                                                   ;Search list for an occurrence of an expression 
    (setq I (RTOS I 2 1))                                                     ;Set I ~ (Current), Return to string, Decimal, 1 zero
    (set_tile "kV2" (strcat I c$plex))                                        ;Set tile kV2, Concatenate string I & c$plex
    (setq E (RTOS E 2 1))                                                     ;Set E ~ (Voltage), Return to string, Decimal, 1 zero
    (set_tile "kV3" (strcat E c$plex)))                                       ;Set tile kV3, Concatenate string E & c$plex
   ((member SFN '("5" "11"))                                                  ;Search list for an occurrence of an expression 
    (setq I (RTOS I 2 1))                                                     ;Set I ~ (Current), Return to string, Decimal, 1 zero
    (set_tile "kV2" I)                                                        ;Set tile kV2 to value of I
    (setq R (RTOS R 2 1))                                                     ;Set R ~ (Resistance), Return to string, Decimal, 1 zero
    (set_tile "kV4" R))                                                       ;Set tile kV4 to value of R
   ((member SFN '("8" "12"))                                                  ;Search list for an occurrence of an expression 
    (setq E (RTOS E 2 1))                                                     ;Set E ~ (Volatge), Return to string, Decimal, 1 zero
    (set_tile "kV3" E)                                                        ;Set tile kV3 to value of E
    (setq R (RTOS R 2 1))                                                     ;Set R ~ (Resistance), Return to string, Decimal, 1 zero
    (set_tile "kV4" R))                                                       ;Set tile kV4 to value of R
 )                                                                            ;End cond
)                                                                              ;End define function
;;;////////////////////////////////////////////////////////////////////////////

Link to comment
Share on other sites

Formula 3 wasn't included in our zero check, which is why it returned an error.

 

As for the other error - I will never edit code in this reply box ever again, just a simple bracket mix up:

 

;;; F03 - Calculate Function - Calculate All Inputs.                           ;Describe function
(defun OLC_CAI ()                                                              ;Define function
 (setq c$plex "" SFN (nth SFN SFN_list))                                      ;Return the nth element of the list 
 (cond                                                                        ;If one of the following conditions apply
   ((or                                                                       ;Return the logical OR of a list of expressions
      (and                                                                    ;Return the logical AND of the supplied arguments
        (member SFN '("1" "4" "6"))                                           ;Search list for an occurrence of an expression 
        (zerop KV4)                                                           ;Verify that a number evaluates to zero 
      )                                                                       ;End and
      (and                                                                    ;Return the logical AND of the supplied arguments
        (= SFN "5")                                                           ;SFN ~ (Select Formula No.) = 5
        (zerop KV3)                                                           ;Verify that a number evaluates to zero 
      )                                                                       ;End and
      (and                                                                    ;Return the logical AND of the supplied arguments
        (member SFN '("3" "8" "10" "12"))                                     ;Search list for an occurrence of an expression 
        (zerop KV2)                                                           ;Verify that a number evaluates to zero 
      )                                                                       ;End and
      (and                                                                    ;Return the logical AND of the supplied arguments
        (= SFN "11")                                                          ;SFN ~ (Select Formula No.) = 11
        (zerop KV1)                                                           ;Verify that a number evaluates to zero 
      )                                                                       ;End and
    )                                                                         ;End or
    (OLC_DBZ))                                                                ;Goto OLC_DBZ Error Function
   ((= "1" SFN)                                                               ;SFN ~ (Select Formula No.) = 1
    (setq E KV3 R KV4 I (/ E R) P (/ (* E E) R)))                             ;Calculate I ~ (Current) & P ~ (Power)
   ((= "2" SFN)                                                               ;SFN ~ (Select Formula No.) = 2
    (setq I KV2 R KV4 E (* R I) P (* I I R)))                                 ;Calculate E ~ (Voltage) & P ~ (Power)
   ((= "3" SFN)                                                               ;SFN ~ (Select Formula No.) = 3
    (setq E KV3 I KV2 R (/ E I) P (* E I)))                                   ;Calculate R ~ (Resistance) & P ~ (Power)
   ((= "4" SFN)                                                               ;SFN ~ (Select Formula No.) = 4     
    (setq P KV1 R KV4 E (sqrt (* P R)) I (sqrt (abs (/ P R))))                ;Calculate E ~ (Voltage) & I ~ (Current)
    (and (minusp (* P R)) (setq c$plex "i")))
   ((= "5" SFN)                                                               ;SFN ~ (Select Formula No.) = 5
    (setq P KV1 E KV3 R (/ (* E E) P) I (/ P E)))                             ;Calculate R ~ (Resistance) & I ~ (Current)
   ((= "6" SFN)                                                               ;SFN ~ (Select Formula No.) = 6
    (setq E KV3 R KV4 P (/ (* E E) R) I (/ E R)))                             ;Calculate P ~ (Power) & I ~ (Current)
   ((= "7" SFN)                                                               ;SFN ~ (Select Formula No.) = 7
    (setq I KV2 R KV4 P (* I I R) E (* R I)))                                 ;Calculate P ~ (Power) & E ~ (Voltage)
   ((= "8" SFN)                                                               ;SFN ~ (Select Formula No.) = 8
    (setq P KV1 I KV2 R (/ P (* I I)) E (/ P I)))                             ;Calculate R ~ (Resistance) & E ~ (Voltage)
   ((= "9" SFN)                                                               ;SFN ~ (Select Formula No.) = 9     
    (setq P KV1 R KV4 I (sqrt (/ P R)) E (sqrt (abs (* P R))))                ;Calculate I ~ (Current) & E ~ (Voltage)
    (and (minusp (* P R)) (setq c$plex "i"))) 
   ((= "10" SFN)                                                              ;SFN ~ (Select Formula No.) = 10
    (setq E KV3 I KV2 P (* E I) R (/ E I)))                                   ;Calculate P ~ (Power) & R ~ (Resistance)
   ((= "11" SFN)                                                              ;SFN ~ (Select Formula No.) = 11
    (setq P KV1 E KV3 I (/ P E) R (/ (* E E) P)))                             ;Calculate I ~ (Current) & R ~ (Resistance)
   ((= "12" SFN)                                                              ;SFN ~ (Select Formula No.) = 12
    (setq P KV1 I KV2 E (/ P I) R (/ P (* I I))))                             ;Calculate E ~ (Voltage) & R ~ (Resistance)
 )                                                                            ;End cond
 (OLC_DCO)                                                                    ;Go to OLC_DCO Output Function
)                                                                              ;End define function
;;;////////////////////////////////////////////////////////////////////////////
;;; F04 - Reset Function - Reset All Calculations.                             ;Describe function
(defun OLC_RAC ()                                                              ;Define function
 (set_tile "kV1" "")                                                          ;Set tile kV1 to blank
 (set_tile "kV2" "")                                                          ;Set tile kV2 to blank
 (set_tile "kV3" "")                                                          ;Set tile kV3 to blank
 (set_tile "kV4" "")                                                          ;Set tile kV4 to blank
)                                                                              ;End define function
;;;////////////////////////////////////////////////////////////////////////////
;;; F05 - Output Function - Display Calculated Output.                         ;Describe function
(defun OLC_DCO ()                                                              ;Define function
 (cond                                                                        ;If one of the following conditions apply
   ((member SFN '("1" "6"))                                                   ;Search list for an occurrence of an expression 
    (setq P (RTOS P 2 1))                                                     ;Set P ~ (Power), Return to string, Decimal, 1 zero
    (set_tile "kV1" P)                                                        ;Set tile kV1 to value of P
    (setq I (RTOS I 2 1))                                                     ;Set I ~ (Current), Return to string, Decimal, 1 zero
    (set_tile "kV2" I))                                                       ;Set tile kV2 to value of I
   ((member SFN '("2" "7"))                                                   ;Search list for an occurrence of an expression 
    (setq P (RTOS P 2 1))                                                     ;Set P ~ (Power), Return to string, Decimal, 1 zero
    (set_tile "kV1" P)                                                        ;Set tile kV1 to value of P
    (setq E (RTOS E 2 1))                                                     ;Set E ~ (Voltage), Return to string, Decimal, 1 zero
    (set_tile "kV3" E))                                                       ;Set tile kV3 to value of E
   ((member SFN '("3" "10"))                                                  ;Search list for an occurrence of an expression 
    (setq P (RTOS P 2 1))                                                     ;Set P ~ (Power), Return to string, Decimal, 1 zero
    (set_tile "kV1" P)                                                        ;Set tile kV1 to value of P
    (setq R (RTOS R 2 1))                                                     ;Set R ~ (Resistance), Return to string, Decimal, 1 zero
    (set_tile "kV4" R))                                                       ;Set tile kV4 to value of R
   ((member SFN '("4" "9"))                                                   ;Search list for an occurrence of an expression 
    (setq I (RTOS I 2 1))                                                     ;Set I ~ (Current), Return to string, Decimal, 1 zero
    (set_tile "kV2" (strcat I c$plex))                                        ;Set tile kV2, Concatenate string I & c$plex
    (setq E (RTOS E 2 1))                                                     ;Set E ~ (Voltage), Return to string, Decimal, 1 zero
    (set_tile "kV3" (strcat E c$plex)))                                       ;Set tile kV3, Concatenate string E & c$plex
   ((member SFN '("5" "11"))                                                  ;Search list for an occurrence of an expression 
    (setq I (RTOS I 2 1))                                                     ;Set I ~ (Current), Return to string, Decimal, 1 zero
    (set_tile "kV2" I)                                                        ;Set tile kV2 to value of I
    (setq R (RTOS R 2 1))                                                     ;Set R ~ (Resistance), Return to string, Decimal, 1 zero
    (set_tile "kV4" R))                                                       ;Set tile kV4 to value of R
   ((member SFN '("8" "12"))                                                  ;Search list for an occurrence of an expression 
    (setq E (RTOS E 2 1))                                                     ;Set E ~ (Volatge), Return to string, Decimal, 1 zero
    (set_tile "kV3" E)                                                        ;Set tile kV3 to value of E
    (setq R (RTOS R 2 1))                                                     ;Set R ~ (Resistance), Return to string, Decimal, 1 zero
    (set_tile "kV4" R))                                                       ;Set tile kV4 to value of R
 )                                                                            ;End cond
)                                                                              ;End define function
;;;////////////////////////////////////////////////////////////////////////////

 

I understand formula 3 was not included, But it is multiplication.

Link to comment
Share on other sites

Formula 3 wasn't included in our zero check, which is why it returned an error.

 

As for the other error - I will never edit code in this reply box ever again, just a simple bracket mix up:

 

;;; F03 - Calculate Function - Calculate All Inputs.                           ;Describe function
(defun OLC_CAI ()                                                              ;Define function
 (setq c$plex "" SFN (nth SFN SFN_list))                                      ;Return the nth element of the list 
 (cond                                                                        ;If one of the following conditions apply
   ((or                                                                       ;Return the logical OR of a list of expressions
      (and                                                                    ;Return the logical AND of the supplied arguments
        (member SFN '("1" "4" "6"))                                           ;Search list for an occurrence of an expression 
        (zerop KV4)                                                           ;Verify that a number evaluates to zero 
      )                                                                       ;End and
      (and                                                                    ;Return the logical AND of the supplied arguments
        (= SFN "5")                                                           ;SFN ~ (Select Formula No.) = 5
        (zerop KV3)                                                           ;Verify that a number evaluates to zero 
      )                                                                       ;End and
      (and                                                                    ;Return the logical AND of the supplied arguments
        (member SFN '("3" "8" "10" "12"))                                     ;Search list for an occurrence of an expression 
        (zerop KV2)                                                           ;Verify that a number evaluates to zero 
      )                                                                       ;End and
      (and                                                                    ;Return the logical AND of the supplied arguments
        (= SFN "11")                                                          ;SFN ~ (Select Formula No.) = 11
        (zerop KV1)                                                           ;Verify that a number evaluates to zero 
      )                                                                       ;End and
    )                                                                         ;End or
    (OLC_DBZ))                                                                ;Goto OLC_DBZ Error Function
   ((= "1" SFN)                                                               ;SFN ~ (Select Formula No.) = 1
    (setq E KV3 R KV4 I (/ E R) P (/ (* E E) R)))                             ;Calculate I ~ (Current) & P ~ (Power)
   ((= "2" SFN)                                                               ;SFN ~ (Select Formula No.) = 2
    (setq I KV2 R KV4 E (* R I) P (* I I R)))                                 ;Calculate E ~ (Voltage) & P ~ (Power)
   ((= "3" SFN)                                                               ;SFN ~ (Select Formula No.) = 3
    (setq E KV3 I KV2 R (/ E I) P (* E I)))                                   ;Calculate R ~ (Resistance) & P ~ (Power)
   ((= "4" SFN)                                                               ;SFN ~ (Select Formula No.) = 4     
    (setq P KV1 R KV4 E (sqrt (* P R)) I (sqrt (abs (/ P R))))                ;Calculate E ~ (Voltage) & I ~ (Current)
    (and (minusp (* P R)) (setq c$plex "i")))
   ((= "5" SFN)                                                               ;SFN ~ (Select Formula No.) = 5
    (setq P KV1 E KV3 R (/ (* E E) P) I (/ P E)))                             ;Calculate R ~ (Resistance) & I ~ (Current)
   ((= "6" SFN)                                                               ;SFN ~ (Select Formula No.) = 6
    (setq E KV3 R KV4 P (/ (* E E) R) I (/ E R)))                             ;Calculate P ~ (Power) & I ~ (Current)
   ((= "7" SFN)                                                               ;SFN ~ (Select Formula No.) = 7
    (setq I KV2 R KV4 P (* I I R) E (* R I)))                                 ;Calculate P ~ (Power) & E ~ (Voltage)
   ((= "8" SFN)                                                               ;SFN ~ (Select Formula No.) = 8
    (setq P KV1 I KV2 R (/ P (* I I)) E (/ P I)))                             ;Calculate R ~ (Resistance) & E ~ (Voltage)
   ((= "9" SFN)                                                               ;SFN ~ (Select Formula No.) = 9     
    (setq P KV1 R KV4 I (sqrt (/ P R)) E (sqrt (abs (* P R))))                ;Calculate I ~ (Current) & E ~ (Voltage)
    (and (minusp (* P R)) (setq c$plex "i"))) 
   ((= "10" SFN)                                                              ;SFN ~ (Select Formula No.) = 10
    (setq E KV3 I KV2 P (* E I) R (/ E I)))                                   ;Calculate P ~ (Power) & R ~ (Resistance)
   ((= "11" SFN)                                                              ;SFN ~ (Select Formula No.) = 11
    (setq P KV1 E KV3 I (/ P E) R (/ (* E E) P)))                             ;Calculate I ~ (Current) & R ~ (Resistance)
   ((= "12" SFN)                                                              ;SFN ~ (Select Formula No.) = 12
    (setq P KV1 I KV2 E (/ P I) R (/ P (* I I))))                             ;Calculate E ~ (Voltage) & R ~ (Resistance)
 )                                                                            ;End cond
 (OLC_DCO)                                                                    ;Go to OLC_DCO Output Function
)                                                                              ;End define function
;;;////////////////////////////////////////////////////////////////////////////
;;; F04 - Reset Function - Reset All Calculations.                             ;Describe function
(defun OLC_RAC ()                                                              ;Define function
 (set_tile "kV1" "")                                                          ;Set tile kV1 to blank
 (set_tile "kV2" "")                                                          ;Set tile kV2 to blank
 (set_tile "kV3" "")                                                          ;Set tile kV3 to blank
 (set_tile "kV4" "")                                                          ;Set tile kV4 to blank
)                                                                              ;End define function
;;;////////////////////////////////////////////////////////////////////////////
;;; F05 - Output Function - Display Calculated Output.                         ;Describe function
(defun OLC_DCO ()                                                              ;Define function
 (cond                                                                        ;If one of the following conditions apply
   ((member SFN '("1" "6"))                                                   ;Search list for an occurrence of an expression 
    (setq P (RTOS P 2 1))                                                     ;Set P ~ (Power), Return to string, Decimal, 1 zero
    (set_tile "kV1" P)                                                        ;Set tile kV1 to value of P
    (setq I (RTOS I 2 1))                                                     ;Set I ~ (Current), Return to string, Decimal, 1 zero
    (set_tile "kV2" I))                                                       ;Set tile kV2 to value of I
   ((member SFN '("2" "7"))                                                   ;Search list for an occurrence of an expression 
    (setq P (RTOS P 2 1))                                                     ;Set P ~ (Power), Return to string, Decimal, 1 zero
    (set_tile "kV1" P)                                                        ;Set tile kV1 to value of P
    (setq E (RTOS E 2 1))                                                     ;Set E ~ (Voltage), Return to string, Decimal, 1 zero
    (set_tile "kV3" E))                                                       ;Set tile kV3 to value of E
   ((member SFN '("3" "10"))                                                  ;Search list for an occurrence of an expression 
    (setq P (RTOS P 2 1))                                                     ;Set P ~ (Power), Return to string, Decimal, 1 zero
    (set_tile "kV1" P)                                                        ;Set tile kV1 to value of P
    (setq R (RTOS R 2 1))                                                     ;Set R ~ (Resistance), Return to string, Decimal, 1 zero
    (set_tile "kV4" R))                                                       ;Set tile kV4 to value of R
   ((member SFN '("4" "9"))                                                   ;Search list for an occurrence of an expression 
    (setq I (RTOS I 2 1))                                                     ;Set I ~ (Current), Return to string, Decimal, 1 zero
    (set_tile "kV2" (strcat I c$plex))                                        ;Set tile kV2, Concatenate string I & c$plex
    (setq E (RTOS E 2 1))                                                     ;Set E ~ (Voltage), Return to string, Decimal, 1 zero
    (set_tile "kV3" (strcat E c$plex)))                                       ;Set tile kV3, Concatenate string E & c$plex
   ((member SFN '("5" "11"))                                                  ;Search list for an occurrence of an expression 
    (setq I (RTOS I 2 1))                                                     ;Set I ~ (Current), Return to string, Decimal, 1 zero
    (set_tile "kV2" I)                                                        ;Set tile kV2 to value of I
    (setq R (RTOS R 2 1))                                                     ;Set R ~ (Resistance), Return to string, Decimal, 1 zero
    (set_tile "kV4" R))                                                       ;Set tile kV4 to value of R
   ((member SFN '("8" "12"))                                                  ;Search list for an occurrence of an expression 
    (setq E (RTOS E 2 1))                                                     ;Set E ~ (Volatge), Return to string, Decimal, 1 zero
    (set_tile "kV3" E)                                                        ;Set tile kV3 to value of E
    (setq R (RTOS R 2 1))                                                     ;Set R ~ (Resistance), Return to string, Decimal, 1 zero
    (set_tile "kV4" R))                                                       ;Set tile kV4 to value of R
 )                                                                            ;End cond
)                                                                              ;End define function
;;;////////////////////////////////////////////////////////////////////////////

 

Where is the bracket mix-up? I can not find it.

Link to comment
Share on other sites

    ((= "3" SFN)                                                               ;SFN ~ (Select Formula No.) = 3
    (setq E KV3 I KV2 R (/ E I) P (* E I)))  

 

You are setting "R" to (/ E I)

 

I copied what you had.

Link to comment
Share on other sites

I copied what you had.

 

I am speaking of formula 3 on the wheel which is multiplication.

We are also filling in R in addition to this. So I guess this still needs to be in the error check even if the formula selected shows multiplication?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...