Announcement

Collapse
No announcement yet.

PB/DLL Help

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

  • PB/DLL Help

    I am trying to write a program to display names of subway stations to stop at or skip when I run my model train. At some stations, I press one of the command buttons to choose subway routes but the program is not working properly. Here is the code:

    #compile exe
    #register none
    #dim all
    #include "win32api.inc"
    global hdlg as long
    global buttonpressed as long
    global stationnumber as long
    global string01 as string
    global string02 as string
    global string03 as string
    global string04 as string
    global string05 as string
    global string06 as string
    global string07 as string
    global string08 as string
    global terminal as long
    callback function nextstation
    buttonpressed=1
    incr stationnumber
    call selectstation
    end function
    callback function route01
    buttonpressed=2
    call cleartextboxes
    call command01
    end function
    callback function route02
    buttonpressed=3
    call cleartextboxes
    call command01
    end function
    callback function route03
    buttonpressed=4
    call cleartextboxes
    call command01
    end function
    callback function route04
    buttonpressed=5
    call cleartextboxes
    call command01
    end function
    callback function route05
    buttonpressed=6
    call cleartextboxes
    call command01
    end function
    callback function route06
    buttonpressed=6
    call cleartextboxes
    call command01
    end function
    callback function newroute
    msgbox "New route"
    end function
    callback function expressstops
    msgbox "Express stops"
    end function
    callback function localstops
    msgbox "Local stops"
    end function
    callback function exitprogram
    dialog end hdlg,1
    end function
    sub selectstation
    select case stationnumber
    Case 1
    call textbox01("Stop at Beach 67th Street")
    Case 2
    call textbox01("Stop at Beach 60th Street")
    Case 3
    call textbox01("Stop at Beach 44th Street")
    Case 4
    call textbox01("Stop at Beach 36th Street")
    Case 5
    call textbox01("Stop at Beach 25th Street")
    Case 6
    call textbox01("Change Direction at Far Rockaway")
    Case 7
    call textbox01("Stop at Beach 25th Street")
    Case 8
    call textbox01("Stop at Beach 36th Street")
    Case 9
    call textbox01("Stop at Beach 44th Street")
    Case 10
    call textbox01("Stop at Beach 60th Street")
    Case 11
    call textbox01("Stop at Beach 67th Street")
    call textbox02("2 - To Broad Channel")
    call textbox03("3 - To Beach 90th Street")
    call command02
    If buttonpressed = 2 Then
    stationnumber = 18
    End If
    If buttonpressed = 3 Then
    stationnumber = 11
    End If
    Case 12
    call textbox01("Stop at Beach 90th Street")
    Case 13
    call textbox01("Stop at Beach 98th Street")
    Case 14
    call textbox01("Stop at Beach 105th Street")
    Case 15
    call textbox01("Change Direction at Rockaway Park")
    Case 16
    call textbox01("Stop at Beach 105th Street")
    Case 17
    call textbox01("Stop at Beach 98th Street")
    Case 18
    call textbox01("Stop at Beach 90th Street")
    call textbox02("2 - To Broad Channel")
    call textbox03("3 - To Beach 67th Street")
    call command02
    If buttonpressed = 2 Then
    stationnumber = 18
    End If
    If buttonpressed = 3 Then
    stationnumber = 0
    End If
    case 19
    call textbox01("Stop at Broad Channel")
    end select
    end sub
    sub command01
    control enable hdlg,101
    control disable hdlg,102
    control disable hdlg,103
    control disable hdlg,104
    control disable hdlg,105
    control disable hdlg,106
    control disable hdlg,107
    end sub
    sub command02
    control disable hdlg,101
    control enable hdlg,102
    control enable hdlg,103
    control disable hdlg,104
    control disable hdlg,105
    control disable hdlg,106
    control disable hdlg,107
    end sub
    sub command03
    control disable hdlg,101
    control enable hdlg,102
    control enable hdlg,103
    control enable hdlg,104
    control disable hdlg,105
    control disable hdlg,106
    control disable hdlg,107
    end sub
    sub command04
    control disable hdlg,101
    control enable hdlg,102
    control enable hdlg,103
    control enable hdlg,104
    control enable hdlg,105
    control disable hdlg,106
    control disable hdlg,107
    end sub
    sub command05
    control disable hdlg,101
    control enable hdlg,102
    control enable hdlg,103
    control enable hdlg,104
    control enable hdlg,105
    control enable hdlg,106
    control disable hdlg,107
    end sub
    sub command06
    control disable hdlg,101
    control enable hdlg,102
    control enable hdlg,103
    control enable hdlg,104
    control enable hdlg,105
    control enable hdlg,106
    control enable hdlg,107
    end sub
    sub textbox01(string01 as string)
    control set text hdlg,112,string01
    end sub
    sub textbox02(string02 as string)
    control set text hdlg,113,string02
    end sub
    sub textbox03(string03 as string)
    control set text hdlg,114,string03
    end sub
    sub textbox04(string04 as string)
    control set text hdlg,115,string04
    end sub
    sub textbox05(string05 as string)
    control set text hdlg,116,string05
    end sub
    sub textbox06(string06 as string)
    control set text hdlg,117,string06
    end sub
    sub textbox07(string07 as string)
    control set text hdlg,118,string07
    end sub
    sub cleartextboxes
    control set text hdlg,113,""
    control set text hdlg,114,""
    control set text hdlg,115,""
    control set text hdlg,116,""
    control set text hdlg,117,""
    control set text hdlg,118,""
    end sub
    function pbmain
    local hfont as long
    dialog new 0,"NYCTA Subway Program",0,0,500,100,%ws_sysmenu + %ws_maximize to hdlg
    control add button,hdlg,101,"Next Station",10,15,50,15, call nextstation
    control add button,hdlg,102,"Route 1",10,50,50,15,call route01
    control add button,hdlg,103,"Route 2",10,85,50,15,call route02
    control add button,hdlg,104,"Route 3",10,120,50,15,call route03
    control add button,hdlg,105,"Route 4",10,155,50,15,call route04
    control add button,hdlg,106,"Route 5",10,190,50,15,call route05
    control add button,hdlg,107,"Route 6",10,225,50,15,call route06
    control add button,hdlg,108,"New route",10,260,50,15,call newroute
    control add button,hdlg,109,"Express stops",75,260,50,15,call expressstops
    control add button,hdlg,110,"Local stops",140,260,50,15,call localstops
    control add button,hdlg,111,"Exit program",205,260,50,15,call exitprogram
    control add textbox,hdlg,112,"",75,10,440,25
    control add textbox,hdlg,113,"",75,45,440,25
    control add textbox,hdlg,114,"",75,80,440,25
    control add textbox,hdlg,115,"",75,115,440,25
    control add textbox,hdlg,116,"",75,150,440,25
    control add textbox,hdlg,117,"",75,185,440,25
    control add textbox,hdlg,118,"",75,220,440,25
    hfont=createfont(36,18,0,0,0,0,0,0,0,0,0,0,0,"arial")
    control send hdlg,112,%wm_setfont,hfont,%true
    control send hdlg,113,%wm_setfont,hfont,%true
    control send hdlg,114,%wm_setfont,hfont,%true
    control send hdlg, 115,%wm_setfont,hfont,%true
    control send hdlg, 116,%wm_setfont,hfont,%true
    control send hdlg, 117,%wm_setfont,hfont,%true
    control send hdlg, 118,%wm_setfont,hfont,%true
    stationnumber=6
    call selectstation
    dialog show modal hdlg
    deleteobject hfont
    end function

    The code doesn't work properly when I press "Route 1" and Route 2" buttons. Jeffrey.

  • #2
    I'm at home today so I can't really troubleshoot your code, but I have a couple of suggestions that will improve your chances of getting a response from somebody else…

    Use the [ code ] tag before your source code, and the [ /code ] tag after your source code, like this…

    [ code ]
    Code:
        This is source code
    [ /code ]

    (I added spaces to make the tags visible. Do not actually type the spaces.)

    Doing that will make your code much more readable, primarily because it will preserve indenting. The easier your code is to read, the more likely it is that people will help you. When I see a long, unformatted program like that I often skip over it because it is too difficult to read.

    By the way, you don't need to add a new message to fix the code. Just click the little pencil-and-paper icon at the very top of your message, and you can edit the existing message, and add the tags. And if the indenting has been lost by the BBS, please re-add it. Blank lines will also be lost, so you'll need to type a single space on any blank line that you want to be preserved.

    Second suggestion: Be more specific about the problem you're seeing. Just saying "The code doesn't work properly" is too vague to get most people's attention. It gives the impression -- correctly or incorrectly -- that you haven't tried to narrow down your problem, and most people here are more interested in specific technical questions.

    Also, be more specific. It looks like your program has at least 6 buttons, but you say "The code doesn't work properly when I press "Route 1" and Route 2" buttons". Does it work properly when you press the other buttons? That would be a major clue.

    Remember, this is a "peer support" forum, and people generally volunteer their time and expertise to answer questions. The easier you make it, and the more information you provide, the more likely you are to get a response!

    HTH.

    -- Eric


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



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

    Comment


    • #3
      Eric, I fixed the problem by adding "call selectstation" to the functions for command buttons and option buttons but I have one more problem. My program has two modal dialog boxes. One dialog box lets me choose subway routes and the other dialog box display names of subway stations to stop at or skip. The first time that I run the program, I choose a subway route and click on "Run Program" button and the dialog boxes change. When I choose "New Route" button, the program disappears and I have to call up the task list to terminate the program that stopped reponding. Here is the code:

      Code:
      #compile exe
      #register none
      #dim all
      #include "win32api.inc"
      global hdlg01 as long
      global hdlg02 as long
      global hfont as long
      global buttonpressed as long
      global stationnumber as long
      global number01 as long
      global number02 as long
      global number03 as long
      global string01 as string
      global string02 as string
      global string03 as string
      global string04 as string
      global string05 as string
      global string06 as string
      global string07 as string
      global string08 as string
      global terminal as long
      sub selectstation
        select case stationnumber
          case 1
            call textbox01("Stop at Beach 67th Street")
          case 2
            call textbox01("Stop at Beach 60th Street")
          case 3
            call textbox01("Stop at Beach 44th Street")
          case 4
            call textbox01("Stop at Beach 36th Street")
          case 5
            call textbox01("Stop at Beach 25th Street")
          case 6
            call textbox01("Change Direction at Far Rockaway")
          case 7
            call textbox01("Stop at Beach 25th Street")
          case 8
            call textbox01("Stop at Beach 36th Street")
          case 9
            call textbox01("Stop at Beach 44th Street")
          case 10
            call textbox01("Stop at Beach 60th Street")
          case 11
            call textbox01("Stop at Beach 67th Street")
            call textbox02("2 - To Broad Channel")
            call textbox03("3 - To Beach 90th Street")
            call command02
            if buttonpressed=2 then
              call cleartextboxes
              call command01
              stationnumber=18
            end if
            if buttonpressed=3 then
              call cleartextboxes
              call command01
              stationnumber=11
            end if
          case 12
            call textbox01("Stop at Beach 90th Street")
          case 13
            call textbox01("Stop at Beach 98th Street")
          case 14
            call textbox01("Stop at Beach 105th Street")
          case 15
            call textbox01("Change Direction at Rockaway Park")
          case 16
            call textbox01("Stop at Beach 105th Street")
          case 17
            call textbox01("Stop at Beach 98th Street")
          case 18
            call textbox01("Stop at Beach 90th Street")
            call textbox02("2 - To Broad Channel")
            call textbox03("3 - To Beach 67th Street")
            call command02
            if buttonpressed=2 then
              call cleartextboxes
              call command01
              stationnumber=18
            end if
            if buttonpressed=3 then
              call cleartextboxes
              call command01
              stationnumber=0
            end if
          case 19
            call textbox01("Broad Channel")
        end select
      end sub
      sub command01
        control enable hdlg02,101
        control disable hdlg02,102
        control disable hdlg02,103
        control disable hdlg02,104
        control disable hdlg02,105
        control disable hdlg02,106
        control disable hdlg02,107
      end sub
      sub command02
        control disable hdlg02,101
        control enable hdlg02,102
        control enable hdlg02,103
        control disable hdlg02,104
        control disable hdlg02,105
        control disable hdlg02,106
        control disable hdlg02,107
      end sub
      sub textbox01(string01 as string)
        control set text hdlg02,112,string01
      end sub
      sub textbox02(string02 as string)
        control set text hdlg02,113,string02
      end sub
      sub textbox03(string03 as string)
        control set text hdlg02,114,string03
      end sub
      sub cleartextboxes
        control set text hdlg02,113,""
        control set text hdlg02,114,""
      end sub
      callback function nextstation
        buttonpressed=1
        incr stationnumber
        call selectstation
      end function
      callback function route01
        buttonpressed=2
        call selectstation
      end function
      callback function route02
        buttonpressed=3
        call selectstation
      end function
      callback function newroute
        dialog end hdlg02,1
        dialog show modal hdlg01
      end function
      callback function expressstops
        string08="Skip "
      end function
      callback function localstops
        string08="Stop at "
      end function
      callback function exitprogram01
        deleteobject hfont
        dialog end hdlg01,1
      end function
      callback function exitprogram02
        deleteobject hfont
        dialog end hdlg02,1
      end function
      callback function runprogram
        dialog end hdlg01,1
        dialog show modal hdlg02
      end function
      callback function option01
        string08="Skip "
        stationnumber=6
        call selectstation
      end function
      callback function option02
        string08="Skip "
        stationnumber=31
        call selectstation
      end function
      function pbmain
        dialog new 0,"NYCTA Subway Program",0,0,500,100,%ws_sysmenu + %ws_maximize to hdlg01
        dialog new 0,"NYCTA Subway Program",0,0,500,100,%ws_sysmenu + %ws_maximize to hdlg02
        control add button,hdlg02,101,"Next Station",10,15,50,15, call nextstation
        control add button,hdlg02,102,"Route 1",10,50,50,15,call route01
        control add button,hdlg02,103,"Route 2",10,85,50,15,call route02
        control add button,hdlg02,104,"Route 3",10,120,50,15,call route03
        control add button,hdlg02,105,"Route 4",10,155,50,15,call route04
        control add button,hdlg02,106,"Route 5",10,190,50,15,call route05
        control add button,hdlg02,107,"Route 6",10,225,50,15,call route06
        control add button,hdlg02,108,"New route",10,260,50,15,call newroute
        control add button,hdlg02,109,"Express stops",75,260,50,15,call expressstops
        control add button,hdlg02,110,"Local stops",140,260,50,15,call localstops
        control add button,hdlg02,111,"Exit program",205,260,50,15,call exitprogram02
        control add textbox,hdlg02,112,"",75,10,440,25
        control add textbox,hdlg02,113,"",75,45,440,25
        control add textbox,hdlg02,114,"",75,80,440,25
        control add textbox,hdlg02,115,"",75,115,440,25
        control add textbox,hdlg02,116,"",75,150,440,25
        control add textbox,hdlg02,117,"",75,185,440,25
        control add textbox,hdlg02,118,"",75,220,440,25
        hfont=createfont(36,18,0,0,0,0,0,0,0,0,0,0,0,"arial")
        control send hdlg02,112,%wm_setfont,hfont,%true
        control send hdlg02,113,%wm_setfont,hfont,%true
        control send hdlg02,114,%wm_setfont,hfont,%true
        control send hdlg02, 115,%wm_setfont,hfont,%true
        control send hdlg02, 116,%wm_setfont,hfont,%true
        control send hdlg02, 117,%wm_setfont,hfont,%true
        control send hdlg02, 118,%wm_setfont,hfont,%true
        control add option,hdlg01,119,"A Route from Far Rockaway to 207th Street",10,10,150,15,call option01
        control add option,hdlg01,120,"A Route from 207th Street to Far Rockaway",10,25,150,15,call option02
        control add option,hdlg01,121,"A Route from Rockaway Park to 207th Street",10,40,150,15,call option03
        control add option,hdlg01,122,"A Route from 207th Street to Rockaway Park",10,55,150,15,call option04
        dialog show modal hdlg01
        deleteobject hfont
      end function
      I found out that PowerBASIC compilers don't have boolean variable type. When I create dialog boxes that are maximized, they cover the whole screen, including the Windows task bar. When I copy code from messages and paste code into text editor, the code is messed up because there are no CR/LF characters at end of lines. Jeffrey.

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

      Comment


      • #4
        Eric, I fixed the "disappearing program" bug by adding Dialog Show State hDlg,%SW_HIDE to the code. I tried to add the "&" character to front of a character in the string to be printed on command buttons so that I can press ALT-character but some ALT-numbers such as ALT-1 and ALT-2 don't work. How can I change the background color of option buttons? How can I write a function that is similar to Form_KeyPress in Visual BASIC so that I can press keys instead of using the mouse to run the program? Jeffrey.

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

        Comment

        Working...
        X