Announcement

Collapse

New Sub-Forum

In an effort to help make sure there are appropriate categories for topics of discussion that are happening, there is now a sub-forum for databases and database programming under Special Interest groups. Please direct questions, etc., about this topic to that sub-forum moving forward. Thank you.
See more
See less

Starting PBCC4

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

  • Starting PBCC4

    I have just purchased PBCC4 and wrote my first program from the Help menu, "Hello World" example under the heading of 'Writing Programs in PBCC".

    I followed the instructions exactly, saved it as 'Hello.bas' and clicked on the 'running man' icon to run the program, expecting that the screen would say "Hello World", but it didn't.

    Instead the screen blinked and put me back exactly where I started.

    What have I missed doing ????.

    Warren
    Warren Sugden

  • #2
    Hi Warren,

    I too am a beginner. Someone will probably post a better (or correct) way to do this but I have had good luck with WAITKEY$.

    HTH,
    Darrell

    Comment


    • #3
      Yea. Without WAITKEY$, your program will just blow back to where you were after it finishes. Try this:
      Code:
      Function PBmain()
          cls
          print;"Hello World!"
          waitkey$                   ' This will still the program until you press a key.
          end function
      Also, do not be afraid to ask questions on this board. If you have a question, you can take it to the bank that somebody else will have the same question, or something similar, but won't ask for whatever reason.
      There are no atheists in a fox hole or the morning of a math test.
      If my flag offends you, I'll help you pack.

      Comment


      • #4
        When you run the compiled example from the IDE it is going to open a console run the hello example and close - such as you are seeing.

        This snippet will open the console and wait for a key press.

        Code:
         
        FUNCTION PBMAIN () AS LONG
            STDOUT "Hello, World!"
            WAITKEY$
        END FUNCTION


        The help example you put together - you need to open a console window and run the hello.exe from the command line. To see it.

        lol you beat me mel
        Last edited by Michael Mayerhoffer; 21 Dec 2007, 07:56 PM. Reason: lol you beat me mel
        A dozen what.

        Comment


        • #5
          Congradulations on getting the Console Compiler Warren. Personally, I love it! You will probably be surprised to learn that you can compile and run any of those Sdk style Windows programs you were looking at a few days back. The only thing you might need to change are the CreateWindow() calls To CreateWindowEx() calls. I really shouldn't even use CreateWindow() anymore, but I forget. If you want to try that here is the CreateWindowEx() call you need...

          hWnd=CreateWindowEx(0,szAppName,"Pretty Basic Sdk Stuff",%WS_OVERLAPPEDWINDOW,200,100,325,300,0,0,hIns,ByVal 0)

          A console will come up too, but that can be turned off with Console Off. Actually though, the console could be used for debugging GUI programs. You could PRINT the variables right to the console from the GUI program. Just a thought.
          Fred
          "fharris"+Chr$(64)+"evenlink"+Chr$(46)+"com"

          Comment


          • #6
            starting PBCC

            Thank you all.

            I guessed there should have been a command to stop the program before it closed.

            In particular, thank you Fred Harris.

            I've made a note of your comments.

            Warren
            Warren Sugden

            Comment


            • #7
              starting PBCC

              Fred Harris

              I loaded 'HelloWin' out of the PBWIN8 folder and changed the line as you suggested above. I presume 'WS_OVERLAPPEDWINDOW,.......,hI ns,......) is a typo and should be .....,hInstance,....... and correcvted that.

              When I run it in PBCC4 I get an error message that 'MSGBOX is not declared'. I searched around and cannot find any instance in other programs of the syntax of the declaration.

              Can you (or anyone else) help me ????
              Warren Sugden

              Comment


              • #8
                Hi Warren,

                MsgBox won't work with PB Console Compiler becasue it is a reserver word, that is, function with the PB Windows compilers. So, if you remove all msgbox references, the program should compile with the console compiler. I'll get back with you later on this if you are having problems. Right now my wife is yellin at me cuz we gotta go somewhere. Hint! There is aWin Api MessageBox function one can use!

                Fred
                Fred
                "fharris"+Chr$(64)+"evenlink"+Chr$(46)+"com"

                Comment


                • #9
                  MSGBOX is a wrapper included in pbdll/pbwin but not pbcc.
                  It basically calls the win32api function below.

                  DECLARE FUNCTION MessageBox LIB "USER32.DLL" ALIAS "MessageBoxA" (BYVAL hwnd AS LONG, lpText AS ASCIIZ, lpCaption AS ASCIIZ, BYVAL wType AS LONG) AS LONG

                  Code:
                  #COMPILE EXE
                  '#DIM ALL
                  DECLARE FUNCTION MessageBox LIB "USER32.DLL" ALIAS "MessageBoxA" (BYVAL hwnd AS LONG, lpText AS ASCIIZ, lpCaption AS ASCIIZ, BYVAL wType AS LONG) AS LONG
                  
                  DECLARE SUB msgbox(st$)
                  FUNCTION PBMAIN () AS LONG
                  
                      msgbox "hello world"
                  
                  END FUNCTION
                  SUB msgbox(st$)
                    LOCAL xst AS ASCIIZ * 255,lcap AS ASCIIZ * 255
                    xst=st$
                    
                    lResult&=messagebox(0,xst,lcap,0)
                  END SUB
                  Last edited by Fred Buffington; 22 Dec 2007, 04:17 PM.
                  Client Writeup for the CPA

                  buffs.proboards2.com

                  Links Page

                  Comment


                  • #10
                    Freds are helpful knowledgable people!...
                    Code:
                    '-------------------------------------------------------------------------------
                    '
                    '  HELLO.BAS example for PowerBASIC for Windows
                    '  Copyright (c) 1997-2005 PowerBASIC, Inc.
                    '  All Rights Reserved.
                    '
                    '-------------------------------------------------------------------------------
                    
                    #COMPILE EXE
                    #Include "Win32Api.inc"
                    
                    ' The resource file gives the EXE program the "hello" icon in Explorer,
                    ' and provides it with Windows version information.
                    #RESOURCE "Hello.pbr"
                    
                    FUNCTION PBMAIN () AS LONG
                    
                        MessageBox(0,"Hello, World!","Api Fn",%MB_OK)
                    
                    END FUNCTION
                    Fred
                    "fharris"+Chr$(64)+"evenlink"+Chr$(46)+"com"

                    Comment


                    • #11
                      starting PBCC

                      Fred Harris

                      I removed all reference to msgbox and the program worked, except I also had to also remove the line #RESOURCE "Hello.pbr".

                      I also was able to run the program in your last post, EXCEPT again I had to remove the same line #RESOURCE "Hello.pbr.

                      Am I missing something else that wont allow to show the icon.
                      Warren Sugden

                      Comment


                      • #12
                        starting PBCC

                        Fred Eddington

                        Thanks for your contribution, but I not able to translate that into my code in post 7, where msgbox returns a message "Can't create Window" when HWD = 0.

                        I'm getting 'Cannot Compile' and the message that there is an error in line 'lresult& = msgbox(0,xst,lcap,0).

                        Can you suggest anything ????
                        Warren Sugden

                        Comment


                        • #13
                          Keep It Simple, S...

                          Why not try print statements:

                          FUNCTION PBMAIN () AS LONG
                          PRINT "Hello World!"
                          PRINT: PRINT "Hit ENTER key to exit program."
                          LINE INPUT q$
                          END FUNCTION

                          Comment


                          • #14
                            Strangely enough, the hello.bas file shipped with the compiler DOES include the "WAITKEY$" line and the provided executable hello.exe - not surprisingly - waits for key so you can actually see "Hello World" on the screen.

                            Too bad the help file version..
                            Code:
                            FUNCTION PBMAIN
                              PRINT "Hello, World!"
                            END FUNCTION
                            .. is burdened with the shameless marketing pitch which precedes it:
                            In PB/CC, only three lines of code are necessary:
                            I guess you can't include the eminently usable and sensible WAITKEY$ line if you want to say "only three lines of code", can you?

                            Yo, Help File Writers! By the time someone is reading the help file, they have already purchased a license and you can trade in the hype for some help!

                            MCM
                            Michael Mattias
                            Tal Systems Inc. (retired)
                            Racine WI USA
                            [email protected]
                            http://www.talsystems.com

                            Comment


                            • #15
                              Am I missing something else that wont allow to show the icon.
                              In the \Samples\Hello directory of PBWin 8 where that Hello.bas file is located are a bunch of other files necessary to the ultimate production of a .pbr PowerBASIC resource file, which file is then 'compiled' into the exe. So, if you want the icon to show up in a console window created with the console compiler compiling this PBWin 8 Hello sample, (which sample has a #Resource Hello.pbr metastatement), then you have to make sure that Hello.pbr file is in the same directory as your file you are compiling. Either that or fix the path to wherever you are compiling the file. Me, I just overwrote everything in the PBWin80\Samples\Hello directory when I compiled it with the Console Compiler. Now I'm 'out' the original program.
                              Fred
                              "fharris"+Chr$(64)+"evenlink"+Chr$(46)+"com"

                              Comment


                              • #16
                                starting PBCC

                                Fred Harris

                                I have deleted all reference to the resource file and the program runs fine.

                                However, in the 'CreateWindow' routine where in your post 5 you had
                                CreateWindow (.................200,100,325,300,0,0........)
                                I had CreateWindow (................%CW_UseDefault,%CW_UseDefault,%CW_UseDefault,%CW_UseDefault,%NUL,%Null,...........) which was working for me. (in my code each variable is on its own line ie. '%CW_UseDefault _')

                                I have now replaced my settings with your numerical settings and expected that it work but with a different size and location of the window, but i am finding that it fails to compile and has an error on line '200,'.

                                I then returned to the original settings and now I am still not able to compile and getting an error 'looking for an '=' sign.

                                Can you help me ????
                                Warren Sugden

                                Comment


                                • #17
                                  Im sure most people here is nice enough and knows enough to help you besides Fred.

                                  If its code from the examples im sure there will be no problem if you post the code
                                  that triggers the error, so we can help you without having to guess what can be wrong.

                                  Comment


                                  • #18
                                    Sounds like some little syntax problem has crept into your line of text Warren. Like Elias said, if you can't find the problem, post the code line at least and someone will surely catch it.
                                    Fred
                                    "fharris"+Chr$(64)+"evenlink"+Chr$(46)+"com"

                                    Comment

                                    Working...
                                    X