No announcement yet.

Superscript 4

  • Filter
  • Time
  • Show
Clear All
new posts

  • Superscript 4

    I would like to print out mm4 with the number 4 being the superscript, using superscript 4 unicode

    I tried using the following code but to no avail

    UnitSt = "mm" + CHR$(&hB4)
    PRINT #3, " Moment of inertia about the X-axis  Ixx : " Ixx , UnitSt
    but for superscript 2 , it works correctly

      UnitSt = "mm" + CHR$(&hB2)
      PRINT #3,  " Area : " ,SecArea , UnitSt
    How do I resolve this? TQ

  • #2
    chr$(&hB4) is acute accent

    the "2" in chr$(&hB2) is a coincidence that the character is superscipt 2

    mm4 uses tags to set "font style". I'd be very surprised if there is a specific character for superscript 4. (superscript 2 sees more comman use for "squared".)


    added - "attribute" might be a better word than "style" in above.


    • #3
      Where will the string be displayed/printed?

      HTML document?
      MS Word (XML I think.)?
      rich text?
      CSS span in HTML?

      Makes a difference as to how the "4" ((in this case)) gets marked as superscript.



      • #4
        Also see -

        Looks like (&h2074) will do what you want. (Though "markup" can make any character(s) superscript.)


        • #5
          I'm using rich text, and that CHR$(&h2074) did not work


          • #6
            Don't know why it doesn't work for you. Try again. Sticking a "&hB" in front of the number has always been the standard way to make Chr$() use superscript for any number.


            • #7
              Just &hB2 and &hB3 by linked page I gave before. But try it.
              (( "B" is part of the number. It is hex for 11 in base 10.))

              Try chr$$(&h2074) instead of chr$(&h2074)
              (that's two dollar signs instead of one)((see Help))


              • #8
                chr$$(&h2074) produces mm4 and not superscript 4

                chr$$(&hb4) produces mm´

                while chr$$(&hb3) produces mm³ which is superscript 3


                • #9
                  Okay, but this code produced mm with superscript 4 (at least chr$$() helped) -
                  #compile exe
                  #dim all
                  %ID_TextBx = 1001
                  %ID_ExitBtn = 1002
                  callback function DlgCB() as long
                    if cb.msg = %wm_command and cb.ctl = %ID_ExitBtn and _
                       cb.ctlmsg = %bn_clicked then
                      dialog end cb.hndl
                    end if
                  end function
                  function pbmain () as long
                    local hDlg as dword
                    local SomeTxt as wstring
                    dialog default font "Tahoma", 12, 0, 1
                    SomeTxt = "mm" + chr$$(&h2074)
                    dialog new 0, "Superscript",  , , 150, 50 to hDlg
                    control add textbox, hDlg, %ID_TextBx, SomeTxt, 5, 5, 140, 16
                    control add button, hDlg, %ID_ExitBtn, "Exit", 50, 26, 50, 20
                    dialog show modal hDlg call DlgCB
                  end function
                  And &hB4 produced accent like I said before and "cubed" is almost as popular as "squared".



                  • #10
                    If it is rich text then you may try UnitSt = "mm\super 4"


                    • #11
                      Thanks Pierre, though I couldn't get that to work here, so I didn't mention

                      or maybe put \U8308 after "mm" (8308 is decimal of H2074)


                      • #12

                        Since Anne used "PRINT #" in her post, I presumed she write directly to a rich text file.
                        Hence the escape "" and "super" for super script.
                        If writing to the screen, then my solution is of no value.


                        • #13
                          Yup, the program prints out directly to a rich text file. The UnitSt = "mm\super 4" did not work.
                          Neither did CHR$$(8308)

                          Thanks guys, anyway I'll just leave it as it is with mm4


                          • #14
                            Maybe it's the way you handle the string, it should work, here is an example...

                            Click image for larger version

Name:	mm4.png
Views:	1
Size:	13.0 KB
ID:	774331

                            #COMPILE EXE '#Win 9.07#
                            #INCLUDE ""
                            #INCLUDE ""
                            GLOBAL hDlg  AS DWORD
                            %RichEdit01  = 101
                            FUNCTION reRichEditFromStringCallBack(BYVAL pDwordArray AS DWORD POINTER, BYVAL pRichEditBuffer AS DWORD, _
                                                                  BYVAL cb AS LONG, BYREF pcb AS LONG) AS LONG
                             pcb = MIN(@pDwordArray[1], cb)
                             IF pcb > 0 THEN
                               CopyMemory(pRichEditBuffer, @pDwordArray[0], pcb)
                               @pDwordArray[0] = @pDwordArray[0] + pcb
                               @pDwordArray[1] = @pDwordArray[1] - pcb
                             END IF
                            END FUNCTION
                            FUNCTION reRichEditFromString(BYVAL hRichEdit AS DWORD, BYVAL sRtfText AS STRING) AS LONG
                             LOCAL EditStreamInfo AS EDITSTREAM
                             DIM dwArray(0 TO 1)  AS DWORD
                             dwArray(0)                 = STRPTR(sRtfText)
                             dwArray(1)                 = LEN(sRtfText)
                             EditStreamInfo.dwCookie    = VARPTR(dwArray(0))
                             EditStreamInfo.pfnCallback = CODEPTR(reRichEditFromStringCallBack)
                             FUNCTION = SendMessage(hRichEdit, %EM_STREAMIN, %SF_RTF, VARPTR(EditStreamInfo))
                            END FUNCTION
                            CALLBACK FUNCTION DlgProc()
                             STATIC hRichEdit01 AS DWORD
                             LOCAL  sRichText   AS STRING
                              SELECT CASE AS LONG CBMSG
                                CASE %WM_INITDIALOG
                                  hRichEdit01 = GetDlgItem(hDlg, %RichEdit01)
                                  PostMessage(hDlg, %WM_APP, 0, 0)
                                CASE %WM_APP
                                  sRichText = "{\rtf1\ansi\ansicpg1252\deff0\deflang3084{\fonttbl{\f0\fnil\fcharset0 Arial;}}" & $CRLF & _
                                              "{\*\generator Msftedit;}\viewkind4\uc1\pard\sl240\slmult1\lang9\fs20 mm\super 4\fs22\par}"
                                  reRichEditFromString(hRichEdit01, sRichText)
                              END SELECT
                            END FUNCTION
                            FUNCTION PBMAIN()
                             LOCAL hLib  AS DWORD
                             LOCAL hIcon AS DWORD
                             hLib = LoadLibrary("MSFTEDIT.DLL")
                             DIALOG FONT "Segoe UI", 9
                             DIALOG NEW %HWND_DESKTOP, "Rich edit", , , 240, 100, _
                             %WS_CAPTION OR %WS_MINIMIZEBOX OR %WS_SYSMENU, 0 TO hDlg
                             hIcon = ExtractIcon(GetModuleHandle(""), "%SystemRoot%\system32\PowrProf.dll", 1)
                             SetClassLong(hDlg, %GCL_HICONSM, hIcon)
                             SetClassLong(hDlg, %GCL_HICON, hIcon)
                             CONTROL ADD "RichEdit50W", hDlg, %RichEdit01, " ", 5, 5, 230, 90, _
                             DIALOG SHOW MODAL hDlg, CALL DlgProc
                            END FUNCTION


                            • #15
                              I didn't mean to try chr$$(8308), but it didn't hurt. The backslash U8308 is supposed to be rich text. (just different rich text than Pierre gave you)

                              If writting to file what program you reading with that does not show superscript?

                              Maybe I'll rework my code to save to file, then read back in and display. In meantime which program you using?

                              added - Are writting unicode endian header to file before the text?


                              • #16
                                Yup, the program prints out directly to a rich text file.
                                Thanks guys, anyway I'll just leave it as it is with mm4
                                Are you saving plain txt in the "rich text file" and then converting it to rtf to show in a RichEdit control?

                                If so you could use a generic "mm^4" in the text file and convert it prior to display with:
                                Replace "mm^4" With "{mm\super 4\nosupersub }" in TextFromFile

                                If you are using a RichEdit V.1 Control ( Library RichEdit32.DLL Class Name "RichEdit" ) you won't be able to display a wide / Unicode character as that was only supported in later versions. (In any case if the font in use doesn't have a glyph for u2074 the resulting substitution may be unattractive).

                                Code samples: 1. Create txt file. 2. Display in RichEdit control.
                                ' Create plain text file for display in a RichEdit Control
                                #Compile Exe
                                #Dim All
                                #Include ""
                                Function PBMain () As Long
                                 Local ValUnitSt As String
                                 Local Ixx As Long : Ixx = 123
                                  ValUnitSt = Using$("#mm^4", Ixx)
                                  Open "TestFile.rtf" For Output As #3
                                    Print #3, " Moment of inertia about the X-axis  Ixx : "+ValUnitSt
                                    Print #3, " Moment of inertia about the X-axis  Ixx : "+Format$(Ixx)+"{mm\super 4\nosupersub }"
                                  Close #3
                                 ? Error$,,"Save File"
                                End Function
                                ' Simple RichEdit text in with RE version 1
                                #Compile Exe
                                #Dim All
                                #Include "WIN32API.INC"
                                CallBack Function DlgProc()
                                  Select Case CbMsg
                                    Case %WM_InitDialog
                                     Local RTFHeader, TextFromFile, sTemp As String
                                        ' eg1. Read text from file into string.
                                        OPEN "testfile.rtf" FOR INPUT AS #1
                                        WHILE ISFALSE EOF(1)  ' check if at end of file
                                          LINE INPUT #1, sTemp
                                          TextFromFile += sTemp+$CRLF
                                        Close #1
                                 '        TextFromFile = "Moment of inertia about the X-axis  Ixx : 123mm^4."+$CrLf+ _   ' alt eg.
                                 '                       "Etc.."+$CrLf
                                        ' Assemble RTF using text from file.
                                        Replace $CrLf With "{\line}" In TextFromFile
                                        Replace "mm^4" With "{mm\super 4\nosupersub }" In TextFromFile
                                        ' RTF Header: rtfVer1, ansi charset, ansicodepage WindowsUS, Lang EnglishUS, default font'2'-Arial
                                        ' FontTable - defines 1. Times New Roman, 2. Arial  (0. = Default App font)
                                        RTFHeader = "{\rtf1\ansi\ansicpg1252\deflang1033\deff2" + $CrLf + _           ' change font eg \deff0
                                        "{\fonttbl{\f1\froman\fcharset0 Times New Roman;}{\f2\fswiss\fcharset0 Arial;}}"
                                        TextFromFile = RTFHeader + TextFromFile + "}"
                                      ' Load RTF into RichEdit control. NB> Streaming not mandatory for a V.1 RichEdit control.
                                      Control Set Text CbHndl, 1001, TextFromFile
                                  End Select
                                End Function
                                Function PBMain()
                                 Local hDlg As Dword
                                 LoadLibrary("RICHED32.DLL")                                        ' Use RichEdit V.1
                                  Dialog Default Font "Tahoma",11, 0, 1                                ' - Default (\f0) font
                                  Dialog New 0, "RichEdit Test", , , 240, 80, %WS_SysMenu To hDlg
                                    Control Add "RichEdit", hDlg, 1001, "Test2", 5, 5, 225, 60, %WS_Child Or %WS_Visible Or %ES_MultiLine
                                  Dialog Show Modal hDlg, Call DlgProc
                                End Function
                                Rgds, Dave


                                • #17
                                  Print Job.pdf

                                  This is what I use for subscript (easily modified to superscript:

                                  Printer data
                                          XPRINT ATTACH CHOOSE   'choose printer
                                          XPRINT SET ORIENTATION 1
                                          XPRINT GET MARGIN TO nLeft, nTop, nRight, nBottom 'get margins
                                          XPRINT GET CLIENT TO pageWidth, pageHeight 'get print area
                                          XPRINT GET PPI TO xppi, yppi
                                          IF nLeft <=0.25*xppi THEN nLeft=0.25*xppi:nRight=nLeft
                                          IF nTop <=0.25*yppi THEN nTop=0.25*yppi
                                          IF nBottom <=0.25*yppi THEN nBottom=0.25*yppi
                                          Prtmargin=nLeft 'set margin width
                                          PrintWidth=pageWidth-nLeft-nRight'set left & right margins to give pagewidth
                                          xppifactor=xppi/120:yppifactor=yppi/120  'work on 120 pix to the inch
                                  MACRO subscript1(centretxt)
                                          XPRINT SET POS (txtWidth+(Prtmargin*2),(y+(txtHeight*0.5))):x1=txtWidth+Prtmargin*2'(PrintWidth/2)
                                          XPRINT FONT "Arial",6,0:XPRINT centretxt;:XPRINT TEXT SIZE centretxt TO txtWidth,txtHeight:txtWidth=txtWidth+x1
                                          XPRINT FONT "Arial",10,0:XPRINT SET POS (txtWidth,y)
                                  END MACRO
                                  MACRO IndentText =XPRINT GET POS TO x,y:XPRINT SET POS (Prtmargin*2, y )
                                          IndentText:XPRINT "Calculated actual vapour pressure (e"+CHR$(186)+"[T";
                                              XPRINT GET POS TO x,y
                                              XPRINT TEXT SIZE "Calculated actual vapour pressure (e"+CHR$(186)+"[T" TO txtWidth,txtHeight
                                              XPRINT "]) ";:tab4:XPRINT "= "+FORMAT$(SVPmax,"#0.00")+" kPa"
                                              XPRINT GET POS TO x,y:y=y+LEADING:XPRINT SET POS (x,y)
                                  May be of some use?
                                  Last edited by Iain Johnstone; 15 Aug 2018, 05:23 AM. Reason: Added printout
                                  “None but those who have experienced them can conceive of the enticements of science” - Mary Shelley


                                  • #18
                                    Are you saving plain txt in the "rich text file" and then converting it to rtf to show in a RichEdit control?
                                    Thanks so much guys

                                    Ok, how do I create a rich text file using Powerbasic statements from the ground up?

                                    Currently, I'm using wordpad to create a precursor file
                                    filename.rtf after which I would write into it using the plain text code.


                                    • #19
                                      WordPad on my PC (admititly old) creates ANSI rich text files. (though what Pierre said should still work, except unpredictable results stuffing in unicode, then reopening in WordPad)

                                      code not shown, In PB are you OPENing FOR OUTPUT or APPEND? FOR OUTPUT will wipe the header info created by WordPad.



                                      • #20
                                        Thanks Dale

                                        I have use "Open for output" and hence this might explain why the rtf format is gone!

                                        What Powerbasic codes to use to create an rtf file from ground up ?