QB / QB64 Discussion Forum      Other Subforums, Links and Downloads

Respond to this messageReturn to Index
Original Message
  • My Solution
    • qbguy (no login)
      Posted May 21, 2011 6:31 PM

      'Note: Overwrites "!doomed!.bas" in the current folder.
      'name this file "linear.bas"
      ' public domain
      ' modified from code by michael calkins

      CONST doomed = "!doomed!.bas" 'this file will be overwritten!
      CONST me = "linear.bas"

      COMMON c AS INTEGER
      DIM n AS INTEGER
      DIM a AS INTEGER
      DIM v AS INTEGER
      DIM e AS INTEGER
      DIM s AS STRING
      DIM sb AS STRING
      DIM q AS STRING * 1

      's = "4p+p-5.5 = 10+2p/3-1/3"

      IF c THEN SYSTEM
      PRINT
      PRINT
      q = CHR$(&H22)
      IF LEN(s) = 0 THEN
      PRINT "enter a linear equation using one variable, a single letter."
      LINE INPUT s
      END IF
      s = LCASE$(s)
      i = 1
      DO WHILE i <= LEN(s)
      n = ASC(MID$(s, i, 1))
      SELECT CASE n
      CASE &H61 TO &H7A
      v = n
      MID$(s, i, 1) = "p"
      IF i >= 2 THEN
      a = ASC(MID$(s, i - 1, 1))
      IF ((a >= &H30) AND (a <= &H39)) OR (a = &H29) THEN
      s = LEFT$(s, i - 1) + "*" + MID$(s, i)
      i = i + 1
      END IF
      END IF
      IF i < LEN(s) THEN
      a = ASC(MID$(s, i + 1, 1))
      IF ((a >= &H30) AND (a <= &H39)) OR (a = &H28) OR (a = &H2E) THEN
      s = LEFT$(s, i) + "*" + MID$(s, i + 1)
      END IF
      END IF
      CASE &H3D
      e = i
      END SELECT
      i = i + 1
      LOOP
      sb = MID$(s, e + 1)
      s = LEFT$(s, e - 1)
      'PRINT s
      'PRINT sb
      OPEN "!doomed!.bas" FOR OUTPUT AS 1
      PRINT #1, "dim p as double"
      PRINT #1, "dim a as double"
      PRINT #1, "dim b as double"
      PRINT #1, "common c as integer"
      PRINT #1, "p=0"
      PRINT #1, "b=(" + s + ")-(" + sb + ")"
      PRINT #1, "p=1"
      PRINT #1, "a=(" + s + ")-(" + sb + ")-b"
      PRINT #1, "print " + q + CHR$(v) + "=" + q + "ltrim$(str$(- b/a))"
      PRINT #1, "chain " + q + me + q
      CLOSE
      c = -1
      CHAIN doomed
    Login Status
  • You are not logged in
    • Login
      Password
       

      Optional
      Provides additional benefits such as notifications, signatures, and user authentication.


      Create Account
    Your Name
    Message Title
    Message Text
    Options
          


     Copyright © 1999-2014 Network54. All rights reserved.   Terms of Use   Privacy Statement