Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Challenge: International version of PRINT USING
#11
Nathan,

What's are FSM's?

If you've never used PRINT USING, then the vast majority of our QB friends here probably haven't used it either. Oh well.....
*****
Reply
#12
Some of us use it. I just recently learned from another members code that you can format more than one data type within the same string. That makes it pretty flexible.
Code:
j% = 10
Sum# = 3.83105945587#
PRINT USING "####) ##.######"; j%; Sum#

Output:
  10)  3.831059
I've thought about writing my own version from time to time, to have it do things I want it to do, but now is not a good time for me. It would be nice to see someone take this on.
hrist Jesus came into the world to save sinners, of whom I am first.(I Timothy 1:15)

For God so loved the world, that He gave His only begotten Son,
that whoever believes in Him should not perish, but have eternal life.(John 3:16)
Reply
#13
Quote:What's are FSM's?

Finite State Machines.
Reply
#14
Quote:Nathan,

What's are FSM's?

Woah! Deja vu! Big Grin

http://forum.qbasicnews.com/viewtopic.ph...2&start=25

Wink

FSMs are very suited for interpreters. And many other things. I love them. They saved my life 2000 times.

A PRINT USING replacement would be extremely complex to code, so I have to admit it is a great idea for a challenge, 'cause I find it terribly challenging... If only I could put 20 minutes together...
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#15
Nathan,

Thanks for the flashback on the FSM issue.

To do a PRINT USING replacement is going to take you more than 20 minutes. There's too many tricky things like floating dollar sign, asterisk protection and negative sign on the right of the number.

The replacement routine of this challenge says to be able to specify (1) the decimal or comma delimeter (2) the comma or decimal separator for thousand (3) the currency symbol.

You don't need to write the entire PRINT USING logic to accomplish the above 3 steps. (This is a hint). The solution that I have in mind should take about 10 minutes to write and another 10 minutes to debug.
*****
*****
Reply
#16
I know it will take longer... But I currently can't put together even 20 minutes... imagine a longer period of time! Sad

Anyhow using a FSM it would be easier, at least the first interpretation part.
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#17
Here's my solution. It simply changes the required symbols in QB's internal routine. This works with PRINT USING, PRINT # USING and LPRINT USING.

Code:
'===============================================================
' SetUsing by Plasma
'---------------------------------------------------------------
' International support for PRINT USING, PRINT # USING and
' LPRINT USING. Created for Moneo's challenge.
'===============================================================

DECLARE SUB SetUsing (Currency$, Thousand$, Fractional$)

' Example...
CLS
' European (if you use cp858, you can use CHR$(213) for the real Euro)
SetUsing "E", ".", ","
PRINT USING "$$#.#######,##"; 1983745.34
' USA
SetUsing "$", ",", "."
PRINT USING "$$#,#######.##"; 1983745.34


DEFINT A-Z
SUB SetUsing (Currency$, Thousand$, Fractional$)

  '===============================================================
  ' SetUsing by Plasma
  '---------------------------------------------------------------
  ' International support for PRINT USING, PRINT # USING and
  ' LPRINT USING. Created for Moneo's challenge.
  '---------------------------------------------------------------
  ' Currency$ - New currency symbol, null to keep old symbol
  '             (default is "$")
  '
  ' Thousand$ - New separator character for thousands, null to
  '             keep old character (default is ",")
  '
  ' Fractional$ - New delimiter for fractional values, null to
  '               keep old delimiter (default is ".")
  '---------------------------------------------------------------
  ' * Compatible with:      QBasic 1.x
  '                     QuickBasic 4.x (IDE & compiled)
  '                         QB PDS 7.x (IDE & compiled)
  '                          VBDOS 1.0 (IDE & compiled)
  '
  '   Note: If you compile your program, it must be compiled as
  '         a stand-alone EXE!
  '===============================================================

  ' Due to Moneo's challenge rules, $ needs to be used in the
  ' format string no matter what you set the currency symbol
  ' to. If you would like to use your specified currency symbol
  ' in the format string, change the constant below to 1.
  CONST FormatCurrency = 0

  STATIC UsingSeg1&, UsingOff1
  STATIC UsingSeg2&, UsingOff2
  STATIC Version

  ' Find the segment and offset of the symbols in B$PUFOUT
  IF UsingSeg1& = 0 THEN
    UsingSeg1& = VARSEG(DefSeg$) - &H400
    DO WHILE UsingSeg1& > 0
      DEF SEG = UsingSeg1&
      FOR i = &H0 TO &H3FF4
        IF PEEK(i) = &HB0 AND PEEK(i + 2) = &HAA THEN
        IF PEEK(i + 3) = &H8A AND PEEK(i + 4) = &HCE THEN
        IF PEEK(i + 5) = &HF6 AND PEEK(i + 6) = &HDE THEN
        IF PEEK(i + 7) = &H7C AND PEEK(i + 8) = &H12 THEN
        IF PEEK(i + 9) = &HFE AND PEEK(i + 10) = &HCF THEN
        IF PEEK(i + 11) = &H75 THEN
          UsingOff1 = i
          EXIT DO
        END IF
        END IF
        END IF
        END IF
        END IF
        END IF
      NEXT
      UsingSeg1& = UsingSeg1& - &H3F0
    LOOP
    IF i = &H3FF5 THEN ERROR 5
  END IF

  ' Find the segment and offset of the symbols in PUSCAN
  IF UsingSeg2& = 0 THEN
    UsingSeg2& = UsingSeg1&
    DO WHILE UsingSeg2& > 0
      DEF SEG = UsingSeg2&
      FOR i = &H0 TO &H3FF4
        IF PEEK(i) = &H3C AND PEEK(i + 2) = &H74 THEN
          IF PEEK(i + 3) = &H45 THEN
            IF PEEK(i + 4) = &H3C AND PEEK(i + 5) = &H5F THEN
            IF PEEK(i + 6) = &H74 AND PEEK(i + 7) = &H94 THEN
            IF PEEK(i + 8) = &H3C AND PEEK(i + 9) = &H5C THEN
            IF PEEK(i + 10) = &H74 AND PEEK(i + 11) = &HB1 THEN
              UsingOff2 = i
              Version = 45
              EXIT DO
            END IF
            END IF
            END IF
            END IF
          ELSEIF PEEK(i + 3) = &H48 THEN
            IF PEEK(i + 4) = &H3C AND PEEK(i + 5) = &H5F THEN
            IF PEEK(i + 6) = &H74 AND PEEK(i + 7) = &H8C THEN
            IF PEEK(i + 8) = &H3C AND PEEK(i + 9) = &H5C THEN
            IF PEEK(i + 10) = &H74 AND PEEK(i + 11) = &HAC THEN
              UsingOff2 = i
              Version = 71
              EXIT DO
            END IF
            END IF
            END IF
            END IF
          END IF
        END IF
      NEXT
      UsingSeg2& = UsingSeg2& - &H3F0
    LOOP
    IF i = &H3FF5 THEN ERROR 5
  END IF

  ' Change the symbols in B$PUFOUT
  DEF SEG = UsingSeg1&
  IF Currency$ <> "" THEN POKE UsingOff1 + &H1, ASC(Currency$)
  IF Thousand$ <> "" THEN POKE UsingOff1 + &H17, ASC(Thousand$)
  IF Fractional$ <> "" THEN POKE UsingOff1 + &H2D, ASC(Fractional$)

  ' Change the symbols in PUSCAN
  DEF SEG = UsingSeg2&
  IF Version = 45 THEN
    IF FormatCurrency AND Currency$ <> "" THEN
      POKE UsingOff2 + &H11, ASC(Currency$)
      POKE UsingOff2 + &H24, ASC(Currency$)
    END IF
    IF Thousand$ <> "" THEN POKE UsingOff2 + &H41, ASC(Thousand$)
    IF Fractional$ <> "" THEN
      POKE UsingOff2 + &H1, ASC(Fractional$)
      POKE UsingOff2 + &H39, ASC(Fractional$)
      POKE UsingOff2 + &H4E, ASC(Fractional$)
    END IF
  ELSE
    IF FormatCurrency AND Currency$ <> "" THEN
      POKE UsingOff2 + &H12, ASC(Currency$)
      POKE UsingOff2 + &H26, ASC(Currency$)
    END IF
    IF Thousand$ <> "" THEN POKE UsingOff2 + &H44, ASC(Thousand$)
    IF Fractional$ <> "" THEN
      POKE UsingOff2 + &H1, ASC(Fractional$)
      POKE UsingOff2 + &H3C, ASC(Fractional$)
      POKE UsingOff2 + &H52, ASC(Fractional$)
    END IF
  END IF

  EXIT SUB
  PRINT USING ""; 0   ' Force the compiler to include PRINT USING

END SUB
Reply
#18
Plasma, utterly amazing! Except for the business of specifying the currency symbol which is a bit shaky, all the rest works just fine.

I can't figure out what you're doing because I've never used peek and poke. How do you figure out where the data is in memory in order to get in and modify it?

Unless we have a miracle entry at the last minute which performs better than yours, you will be the winner. At the end, I'll post my simplistic solution.

Thanks.
*****
Reply
#19
Hrmm...how is the currency symbol shaky? It'll use whatever character you pass to it. Neither codepage 437 nor 850 have a euro symbol, so there's not much I can do there.

About modifying the memory...well, it helps to have the source code to QBasic. Smile
Reply
#20
All 7 MB of it. :*(

Lucky you. :*)
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)