Page 1 of 1

Why can't I start Purebasic with RunProgram()?

Posted: Mon Sep 18, 2023 8:22 am
by Micoute
I used to be able to launch Purebasic by clicking on a button, but since version 6.03 this no longer works.
What should I do to get it working again?

Code: Select all

;Mes Applis Btn RBUTTON
;{ Fichiers inclus
XIncludeFile "D:\Programmation\Prg Perso\B\Boutons\RButton\RButton.pb"
XIncludeFile #PB_Compiler_FilePath + "Donnees mes applis.pb"
;}
;{ Enumérations
Enumeration Fenetre
  #Fenetre_principale
EndEnumeration

Enumeration Gadgets
  #Btn_0
EndEnumeration
;}
;{ Structure
Structure  Donnee
  Titre.s
  Adresse.s
  Icone.s
EndStructure 
;}
;{ Variables
Global.s Rep$ = GetPathPart(ProgramFilename()) : SetCurrentDirectory(Rep$)
Global.Donnee NewList Donnee()
Global.i X, Y, i, Quitter, Evenement, Couleur
Global.i LigBtns = 5, ColBtns = 24, HtBtn = 15*2, LgBtn = 150*2
Global.i Nb_par_Colonne = HtBtn * ColBtns, Lfen = LgBtn * LigBtns
Global NomPolice.s = "Calibri", TaillePolice = 10*1.4
;}
Procedure r(i, j)
  ProcedureReturn Random(i, j)
EndProcedure
Procedure ps(f, p)
  SetSoundFrequency(0, f)
  SoundPan(0, p)
  PlaySound(0)
EndProcedure
InitSound()
CatchSound(0, ?Son)
SoundVolume(0, 30)
Procedure Initialisation()
  Protected.s Titre, Adresse, Icone
  Restore Donnees
  i = 0
  While Titre <> "999" And Adresse <> "999"
    Read.s Titre
    Read.s Adresse
    Read.s Icone
    AddElement(Donnee())
    Donnee()\Titre = Titre
    Donnee()\Adresse = Adresse
    i + 1
  Wend
  DeleteElement(Donnee())
  SortStructuredList(Donnee(), #PB_Sort_Ascending, OffsetOf(Donnee\Titre),#PB_String)
  
  i - 1
  Debug i
  
  Global.i NbBtn =  ListSize(Donnee()) - 1
  Global Dim Tableau.s(1, NbBtn)
  
  i = 0
  ForEach Donnee()
    If Left(Donnee()\Titre, 1) = "0" Or Left(Donnee()\Titre, 1) = "1"
      Donnee()\Titre = Right(Donnee()\Titre, Len(Donnee()\Titre) - 3)
    EndIf
    Tableau(0,i) = Donnee()\Titre
    Tableau(1,i) = Donnee()\Adresse
    i+1
  Next
EndProcedure 
Procedure Programme_principal()
  
  If OpenWindow(#Fenetre_principale, 0, 0, Lfen + 20, Nb_par_Colonne + 20, 
                "Mes Applications © Micoute 15/08/2022", 
                #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_TitleBar)
    SetWindowColor(#Fenetre_principale, $DECFF2)
    SetWindowLong_(WindowID(#Fenetre_principale), #GWL_EXSTYLE, GetWindowLong_(WindowID(#Fenetre_principale), #GWL_EXSTYLE) | $00080000) ; #WS_EX_LAYERED = $00080000
    SetLayeredWindowAttributes_(WindowID(#Fenetre_principale), 0, 250, 2) 
    
    Police = LoadFont(#PB_Any, NomPolice, TaillePolice, #PB_Font_Bold)
    SetGadgetFont(#PB_Default, FontID(Police)) ;Affecter la Police à tous les gadgets
    
    ;Créons nos boutons
    For i = 0 To NbBtn
      Couleur = RGB(Random(255,127),Random(255,127),Random(255,127)) ;Création de la couleur du bouton i
      Y = Mod(i * HtBtn, Nb_par_Colonne)                             ;Position de la ligne du bouton i
      X = (i * HtBtn) / (Nb_par_Colonne)                             ;Position de la colonne du bouton i
      RBUTTON(i, Tableau(0, i), 10+X*LgBtn, 10+Y, LgBtn, HtBtn, FontID(Police), 0, Couleur, HtBtn/2)
    Next    
  EndIf
EndProcedure
Initialisation()
Programme_principal()
;{- Boucle d'évènements
Quitter.i = #False

Repeat
  Evenement = WaitWindowEvent()
  
  If Evenement = #PB_Event_Gadget
    For i = 0 To ListSize(Donnee())
      If EventType() = #PB_EventType_LeftClick
        If EventGadget() = i
          PlaySound(0)
          RunProgram(Tableau(1, i))      
        EndIf
      EndIf
    Next
  EndIf
  
Until Quitter = #True
End
;}
;{ Données
DataSection
  son:
  IncludeBinary "D:\Programmation\Prg Perso\S\Sons\Bruits\Clic.wav"
  FinSon:
EndDataSection
;}

Re: Why can't I start Purebasic with RunProgram()?

Posted: Mon Sep 18, 2023 8:58 am
by NicTheQuick
What button?

Re: Why can't I start Purebasic with RunProgram()?

Posted: Mon Sep 18, 2023 9:36 am
by BarryG
Maybe he means to start compiling? Not sure.

Re: Why can't I start Purebasic with RunProgram()?

Posted: Mon Sep 18, 2023 9:57 am
by Kiffi
Micoute wrote: Mon Sep 18, 2023 8:22 amWhat should I do to get it working again?
The very first thing you should do is post your code, because we don't all have a crystal ball.

Re: Why can't I start Purebasic with RunProgram()?

Posted: Mon Sep 18, 2023 11:43 am
by juergenkulow

Code: Select all

/VERSION
PureBasic IDE 6.03 beta 8 LTS [devel; 8faab0468c56; 14-09-2023] - (c) 2023 Fantaisie Software
H:\OldPB\PureBasic\603Beta8x86\PureBasic.exe Runtime:44 ms

Re: Why can't I start Purebasic with RunProgram()?

Posted: Mon Sep 18, 2023 12:01 pm
by Micoute
Code sent to first post

Re: Why can't I start Purebasic with RunProgram()?

Posted: Mon Sep 18, 2023 12:17 pm
by Kiffi

Code: Select all

[...]
        If EventGadget() = i
          PlaySound(0)
          RunProgram(Tableau(1, i))      
        EndIf
[...]

Code: Select all

[...]
        If EventGadget() = i
          PlaySound(0)
          Debug Tableau(1, i) ; <--
          RunProgram(Tableau(1, i))      
        EndIf
[...]
can you post what the debugger prints here?

Re: Why can't I start Purebasic with RunProgram()?

Posted: Mon Sep 18, 2023 5:52 pm
by Demivec
I don't know if this is the source of your error but if it isn't it should still be corrected.

Code: Select all

Procedure Initialisation()
  Protected.s Titre, Adresse, Icone
  Restore Donnees 
  ;----snipped code
EndProcedure 

;--- snipped code

;{ Données
DataSection
  son:
  IncludeBinary "D:\Programmation\Prg Perso\S\Sons\Bruits\Clic.wav"
  FinSon:
EndDataSection
;}
You use Restore Donnees but don't have a label Donnees in your program. It should be placed inside the DataSection before your data.

Re: Why can't I start Purebasic with RunProgram()?

Posted: Tue Sep 19, 2023 8:17 am
by Olli
Hello micoute !

I hope you are fine !
For your 50 years of coding, I add this suggestion :

I think also you should let between 500 and 1000 ms to the client program in RunProgram() with a Delay().

Code: Select all

RunProgram(myProg$)
Delay(500)
I said the world << also >> because no other advice cannot be excluded.

Here, you request to run a complex program (which opens a piped sub-client program, allocates good part of memory, uses preferences files, etc... ) which need not to be executed 100 times per second, so, you should let a wait duration.

Hoping there is not a collision between the preferences files.