Announcement

Collapse
No announcement yet.

New to PB/DLL

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • New to PB/DLL

    The PB/DLL6 reference guide is fair, but I need a little help on a couple of questions:

    1. How does one go about displaying on the CRT the results of calculations?

    2. Are the PBDOS statements "FIELD" and "MAP" supported in PB/DLL?
    Walt Decker

  • #2
    For your first program in PB DLL use the MSGBOX "" statement to have a simple message pop up as in:

    MSGBOX "Hello, A = " & STR$(A)

    Now to write a program with a user interface you are going to have to use Dialogs. DDT makes that easy. Take a look at the program HELLODDT.BAS in your samples directory and then read up on DDT and play with it until you get a handle on it.

    The MAP and FIELD are not in PBDLL.

    Instead of using FIELD you can open a RANDOM access file and use LEN = to set the size of the record that you want to access.

    One of the best methods to use instead of a FIELD or MAP is a UDT (Type / End Type) Use UDT to read the data in and out of the file.

    Instead of MAP you can use a large string to read and write the data to a file. PB DLL supports very large strings. You can use pointers and UDTs to access the data in the string.

    MAP and FIELD are sort of outdated.

    Tim


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

    Comment


    • #3
      Hi,

      I have a difficult start with PBdll6 in the beginning,
      But after I modify the Hello program and do some simple calculation and I go on.... I am quite comfort with the
      DDT,I think if PB can improve the DDT, I can almost forget
      about the VB!
      The example ship with the PB is not enough(I feel)for example,
      the DDT section only have two example Hello and the Address book,
      this is the big jump, they don't put more program example for
      you to walk thru'!
      So the only way I do(the hard way)is search thru' the whole forum
      and cut/paste those useful example by those PB old hand.

      This is the first PB program I make for Cylinder thrust force calculation, may be too simple to make people laugh but when
      first time I do this I almost throw the PBDll out of my PC and
      say "Bill, I still love VB"
      Finally the true Basic still Power!(Switch on the Turbo!)

      Code:
      '==============================================================================
      '
      ' Simple Dialog Example for PB/DLL 6.0
      ' Written by KT Lai, 27 April 2000
      '
      ' Simple example of an application that has a dialog and
      ' do some calculation requires absolutely no API calls
      '
      '==============================================================================
      ' Set ID for all the dialog control items
      
      #COMPILE EXE
      
      %IDCalculate       = 1
      %IDExit            = 2
      %IDBORE            = 3
      %IDBAR             = 4
      %IDFORCE           = 5
      %BS_DEFAULT        = 1      'Set the button appearance
      
      '------------------------------------------------------------------------------
      ' Global variable to recieve the user input and variable
      
      GLOBAL BoreSize AS STRING
      GLOBAL Presure AS STRING
      GLOBAL D AS SINGLE
      GLOBAL P AS SINGLE
      GLOBAL F AS SINGLE
      
      '------------------------------------------------------------------------------
      
      CALLBACK FUNCTION Calculate()
      
        CONTROL GET TEXT CBHNDL, %IDBORE TO BoreSize
        CONTROL GET TEXT CBHNDL, %IDBAR TO Presure
        D=VAL(BoreSize)
        P=VAL(Presure)
        F=(D/20)*(D/20)*3.1416*9.8*P
      
      ' Put the calculated answer at text box
        CONTROL SET TEXT CBHNDL,%IDFORCE, STR$(F!)
      
        END FUNCTION
      '--------------------------------------------------------
      
      CALLBACK FUNCTION Exit_prog()
      
        DIALOG END CBHNDL, 0
      
      END FUNCTION
      
      '------------------------------------------------------------------------------
      
      FUNCTION PBMAIN () AS LONG
      
        $REGISTER NONE
      
        LOCAL hDlg   AS LONG
      
      ' ** Create a new dialog template
        DIALOG NEW 0, "Calculation of Cylinder Thrust", ,, 200, 100, 0, 0 TO hDlg
      
      ' ** Add controls to it
      '--------------------------------------------------------------------------
      CONTROL ADD LABEL, _
      hDlg, _
      -1, _
      "Bore Size (mm) ", _
      30, _
      10, _
      70, _
      8, _
      
      
      '--------------------------------------------------------------------------
      CONTROL ADD LABEL, _
      hDlg, _
      -1, _
      "Presure in Bar ", _
      30, _
      30, _
      90, _
      10, _
      
      '--------------------------------------------------------------------------
      CONTROL ADD LABEL, _
      hDlg, _
      -1, _
      "Thrust Force in Newton =", _
      30, _
      50, _
      90, _
      10, _
      
      '--------------------------------------------------------------------------
      CONTROL ADD TEXTBOX, _
      hDlg, _
      %IDBORE, _
      "", _
      120, _
      10, _
      50, _
      12, _
      '--------------------------------------------------------------------------
      CONTROL ADD TEXTBOX, _
      hDlg, _
      %IDBAR, _
      "", _
      120, _
      30, _
      50, _
      12, _
      
      '--------------------------------------------------------------------------
      CONTROL ADD TEXTBOX, _
      hDlg, _
      %IDFORCE, _
      "", _
      120, _
      50, _
      50, _
      12, _
      
      '--------------------------------------------------------------------------
      
      CONTROL ADD BUTTON, hDlg, %IDCalculate, "Calculate", 50, 75, 40, 14, %BS_DEFAULT CALL Calculate
      
      CONTROL ADD BUTTON, hDlg, %IDEXIT, "Exit", 110, 75, 40, 14, 0 CALL exit_prog
      
      '--------------------------------------------------------------------------
      
      ' ** Display the dialog
        DIALOG SHOW MODAL hDlg
      
      END FUNCTION


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

      Comment


      • #4
        Thank you. The 1st answer wasn't quite what I was looking for and is not really the best. Seun Yu' s example appears to be a better one. I'll give it a try.

        Does PB/CC support FIELD and MAP?

        ------------------
        Walt Decker

        Comment


        • #5
          FIELD and MAP are not supported by PB/DLL or PB/CC.

          But you can accomplish exactly the same thing (more efficiently) by creating a user-defined TYPE structure that matches the FIELD structure that you used to use.

          -- Eric

          ------------------
          Perfect Sync: Perfect Sync Development Tools
          Email: mailto:[email protected][email protected]</A>



          [This message has been edited by Eric Pearson (edited May 30, 2000).]
          "Not my circus, not my monkeys."

          Comment


          • #6

            Walt,

            >>Does PB/CC support FIELD and MAP?

            No, but if text output is your primary concern, PB/CC might
            suit your purposes better.

            Also, you might want to check out www.PerfectSync.com.

            Andy
            [email protected]

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

            Comment


            • #7
              Text output is always a concern. Without it data contained in a computer or the result of calculations is usless. But, the reason I wish to use FIELD and MAP is that they are more flexible than UDTs.

              ------------------
              Walt Decker

              Comment


              • #8
                Walt --

                > the reason I wish to use FIELD and MAP is
                > that they are more flexible than UDTs

                Not in my experience! If you use a UDT with a random-access file you can GET a record in almost exactly the same way as with FIELD, and instead of doing this...

                FIELD #1, 16 AS FirstName, 32 AS LastName, (etc)

                Code:
                FirstName = "John"
                LastName  = "Doe"
                ...you would access the fields like this...

                Code:
                TYPE MyRecord
                    FirstName AS STRING * 16
                    LastName  AS STRING * 32
                    (etc)
                END TYPE
                
                MyRecord.FirstName= "Jane"
                MyRecord.LastName = "Doh!"
                Some of the advantages of using a UDT are 1) you are not confined to using strings, you can use any data type and the file's contents can be converted automatically, 2) you can manipulate the entire record as a single "object" so you can do things like passing an entire record to a SUB or FUNCTION, 3) you can "nest" TYPE structures and manipulate "sub-blocks" of data, 4) you can "overlay" structures using UNIONs, so that the same field can be accessed in different ways.

                True, you can accomplish some of those things with FIELD and MAP, but they are 100% restricted to string variables. It seems to me that UDTs are much more flexible, unless I'm missing something.

                HTH.

                -- Eric


                ------------------
                Perfect Sync: Perfect Sync Development Tools
                Email: mailto:[email protected][email protected]</A>



                [This message has been edited by Eric Pearson (edited May 31, 2000).]
                "Not my circus, not my monkeys."

                Comment


                • #9
                  To be clear, Andy was referring to the pure text mode offered by the Console Compiler. If you just want to get some calculation results on the screen, then a DDT app will work just as well as a console app - there is just a bit more work to get the dialog initially working.

                  Try the following simple DDT app...
                  Code:
                  #COMPILE EXE
                  #DIM ALL
                  #INCLUDE "ddt.inc"
                  %ID_TEXT1 = 101
                  %ID_TEXT2 = 102
                  %ID_BUTTON1 = %IDOK
                  %ID_BUTTON2 = %IDCANCEL
                   
                  FUNCTION DoTheCalculation AS STRING
                      FUNCTION = FORMAT$((SIN(1) + COS(1)) / TAN(.3333#))
                  END FUNCTION
                   
                  CALLBACK FUNCTION DialogCallback
                      DIM a$
                      SELECT CASE CBMSG
                          CASE %WM_COMMAND
                              IF CBCTL = %ID_BUTTON1 THEN
                                  a$ = DoTheCalculation()
                                  CONTROL SET TEXT CBHNDL, %ID_TEXT1, "The result is: " & a$
                                  CONTROL SET TEXT CBHNDL, %ID_TEXT2, a$ & $CRLF & a$
                              ELSE
                                  DIALOG END CBHNDL, 0
                              END IF
                          CASE ELSE
                      END SELECT
                  END FUNCTION
                   
                  FUNCTION PBMAIN
                      DIM hDlg AS LONG
                      DIALOG NEW %HWND_DESKTOP, "Calculate your heart out!",,, 200, 110, _
                          %DS_CENTER OR %WS_CAPTION OR %WS_SYSMENU OR %WS_MINIMIZEBOX TO hDlg
                      CONTROL ADD TEXTBOX, hDlg, %ID_TEXT1, "Result #1", 5, 5, 190, 35, %ES_AUTOVSCROLL OR _
                          %WS_CHILD OR %ES_MULTILINE OR %ES_READONLY, %WS_EX_CLIENTEDGE
                      CONTROL ADD LABEL, hDlg, %ID_TEXT2, "Result #2", 5, 45, 190, 35, %SS_LEFT, %WS_EX_CLIENTEDGE
                      CONTROL ADD BUTTON, hDlg, %ID_BUTTON1, "&Calculate", 110, 85, 40, 20, %BS_DEFAULT OR %WS_TABSTOP
                      CONTROL ADD BUTTON, hDlg, %ID_BUTTON2, "&Quit", 155, 85, 40, 20
                      DIALOG SHOW MODAL hDlg CALL DialogCallback
                  END FUNCTION

                  ------------------
                  Lance
                  PowerBASIC Support
                  mailto:[email protected][email protected]</A>
                  Lance
                  mailto:[email protected]

                  Comment


                  • #10
                    Lance, thank you for the snippet. That works well and answered one of several other questions I had in mind.

                    Eric, thank you for your input.

                    I am a geologist, not a programmer (although I'm not a stranger to programming). My data needs are dynamic, not static. A UDT (which is not end-user defined) is about as dynamic as an equate. Each project in which I engage has different data requirements. There are some requirements that can be predefined, but most cannot. It is a waste of my time to use UDTs and UNIONs when other structures will work better. FIELD and MAP are dynamic and, therefore, meet my data needs better. If I use PB/DLL or PB/CC, I'll have to come up with a way to create dynamic structures.

                    ------------------
                    Walt Decker

                    Comment


                    • #11
                      Walt --

                      That's very interesting! I worked with PB/DOS every day for years and I never knew that FIELD and MAP were runtime functions. Or if I did, I've forgotten it. I'd have sworn that they were fixed at compile time, just like UDTs.

                      You could do it very efficiently with pointers but it would be tricky to write.

                      Hmmm... An interesing problem to ponder...

                      -- Eric

                      ------------------
                      Perfect Sync: Perfect Sync Development Tools
                      Email: mailto:[email protected][email protected]</A>



                      [This message has been edited by Eric Pearson (edited June 01, 2000).]
                      "Not my circus, not my monkeys."

                      Comment


                      • #12
                        Yes, Eric, they are dynamic.

                        I = 8
                        J = 10
                        FileHandle = FREEFILE
                        OPEN DataFile$ FOR RANDOM AS FileHandle LEN = _ Something
                        FIELD FileHandle, I AS SomeData$, J AS MoreData$

                        works just as well as:

                        FIELD FileHandle, 8 AS SomeData$, 10 AS MoreData$

                        OR

                        FOR I = 1 TO UBOUND(FieldLen)

                        FIELD FileHandle, FieldLen(I) AS SomeData$

                        NEXT I

                        Throw in a data-type specifer string for each field and you have a user-defined, dynamic data base.

                        ------------------
                        Walt Decker

                        Comment


                        • #13
                          Walt --

                          I'm sure I didn't know that! I hardly every used RANDOM, almost always BINARY. Learn something new every day!

                          I'm guessing that you meant that last block to use an array like this...

                          Code:
                          FOR I = 1 TO UBOUND(FieldLen)
                              FIELD FileHandle, FieldLen(I) AS SomeData$[b](I)[/b]
                          NEXT I
                          Otherwise you'd be assigning several fields to the same string variable. (Or am I still not understanding? Bear with me, I've been having a rough week. )

                          Pretty clearly, a UDT would not be an appropriate replacement for something like that.

                          But it would be relatively easy to OPEN the file FOR BINARY, get a whole record as a single string, and write a function called SomeData$() (or whatever) that used MID$ to return the appropriate values, based on global FieldLen() and FieldType() arrays. You could use SomeData$(1), SomeData$(2), etc. just as if they were the elements of a string array or FIELDed variables.

                          I'm just tossing out ideas... Hope you don't mind. Believe me, being able to move from PB/DOS to PB/DLL or PB/CC would be well worth the trouble. Properly done (replacing a string array with a string function of the same name) it seems like it would be a relatively simple conversion.

                          [added a few minutes later]

                          One disadvantage of this system would be that it would require a second function if you need to change the values. Something like GetSomeData$() and PutSomeData$(). I can see where that would be less convenient that using a FIELDed variable, but since FIELD is not supported by PowerBASIC for Windows...

                          Anybody else have any other ideas?

                          -- Eric

                          ------------------
                          Perfect Sync: Perfect Sync Development Tools
                          Email: mailto:[email protected][email protected]</A>



                          [This message has been edited by Eric Pearson (edited June 01, 2000).]
                          "Not my circus, not my monkeys."

                          Comment


                          • #14
                            Yes, Ian, I did neglect to put an element specifier at the end. However, I do have a function that does something similar. For example, if I wanted to read a specific portion of the file, the function would add the fields together to produce a dummy field up to the portion I wanted to read, then extract the portion I wanted to read.

                            If there is another version of PB/DLL in the works, it would be very handy to include FIELD and MAP support for folks like me who require the use of dynamic data storage and retrieval.

                            On an upscale note, I've found that I can read in the entire record and use VARPTR to find the address, and PEEK$ to extract the various portions.

                            ------------------
                            Walt Decker

                            Comment


                            • #15
                              > I've found that I can read in the entire
                              > record and use VARPTR to find the address,
                              > and PEEK$ to extract the various portions.

                              That seems like a lot of work... Why not just read the entire record as a string and use MID$? Just curious...

                              -- Eric


                              ------------------
                              Perfect Sync: Perfect Sync Development Tools
                              Email: mailto:[email protected][email protected]</A>

                              "Not my circus, not my monkeys."

                              Comment


                              • #16
                                Eric, I made the assumption, perhaps erroneously, that

                                @address2 = CVI(PEEK$, @address1, FieldLen(I))
                                INCR address1, FieldLen(I)
                                INCR address2, 3

                                would be faster than

                                SomeVarb% = CVI(MID$(SomeData$(I), FieldStart(I), FieldLen(I))

                                because I can pass 2 addresses BYVAL and FieldLen() BYREF or make FieldLen() global.


                                ------------------
                                Walt Decker

                                Comment

                                Working...
                                X