Error msg: "default target" has no main source file .

Just starting out? Need help? Post your questions and find answers here.
vmars316
Enthusiast
Enthusiast
Posts: 474
Joined: Fri Jun 29, 2012 12:24 am
Contact:

Error msg: "default target" has no main source file .

Post by vmars316 »

Hello & Thanks ,
So far I have 2 files , vm-02-Proj.pbf and Gadgets_Events.pb

Code: Select all

; vm-02-Proj.pbf
Global Window_0
Global Image_0, Button_0, ListView_0, ListView_1, ListView_2, ListView_3, Text_0, Text_1, Text_2, Text_3

Declare Gadgets_Events.pb(Event, Window)

Procedure OpenWindow_0(x = 0, y = 0, width = 800, height = 490)
  Window_0 = OpenWindow(#PB_Any, x, y, width, height, "Rainbow Sequence", #PB_Window_SystemMenu)
  Image_0 = ImageGadget(#PB_Any, 20, 20, 150, 50, 0)
  Button_0 = ButtonGadget(#PB_Any, 20, 100, 150, 24, "START")
  ListView_0 = ListViewGadget(#PB_Any, 260, 50, 100, 420)
  ListView_1 = ListViewGadget(#PB_Any, 390, 50, 100, 420)
  ListView_2 = ListViewGadget(#PB_Any, 520, 50, 100, 420)
  ListView_3 = ListViewGadget(#PB_Any, 650, 50, 120, 420)
  Text_0 = TextGadget(#PB_Any, 270, 10, 80, 30, "  Pixel POS")
  Text_1 = TextGadget(#PB_Any, 400, 10, 80, 30, " Pixel HEX")
  Text_2 = TextGadget(#PB_Any, 530, 10, 90, 30, " Html HEX")
  Text_3 = TextGadget(#PB_Any, 660, 10, 100, 30, "Html Name")
EndProcedure

Procedure Window_0_Events(event)
  Select event
    Case #PB_Event_CloseWindow
      ProcedureReturn #False

    Case #PB_Event_Menu
      Select EventMenu()
      EndSelect

    Case #PB_Event_Gadget
      Select EventGadget()
      EndSelect
    Default
      Gadgets_Events.pb(event,Window_0)
  EndSelect
  ProcedureReturn #True
EndProcedure
AND

Code: Select all

; Gadgets_Events.pb
; UsePNGImageDecoder() 
; If OpenWindow(0, 100, 100, 400, 400, "ImageGadget", #PB_Window_SystemMenu))
;  ButtonGadget(10, 10, 150, 50, 20, "START")

  If LoadImage(0, "RainbowBar.png")    ; change 2nd parameter to the path/filename of your image
      ImageGadget(10,  120, 150, 50, 83, ImageID(0))                      ; imagegadget standard
;    Result = ImageGadget(#Gadget, x, y, Width, Height, ImageID [, Flags])  
    EndIf
  
    Repeat  
    Until WaitWindowEvent() = #PB_Event_CloseWindow
  EndIf
I don't understand what compiler means .
Should i rename something to main.pb ?
I was thinking that *.pbf was the main file ?
Please educate me .
Maybe a tiny example of three files , Ex01-form.pbf , Ex01-main.pb , Ex01-inc.pb
Thanks
vmars.us Win11 x64 , Martin Guitar 000-16 (1995)
"All things in moderation , except for love and forgiveness."
User avatar
Vera
Addict
Addict
Posts: 858
Joined: Tue Aug 11, 2009 1:56 pm
Location: Essen (Germany)

Re: Error msg: "default target" has no main source file .

Post by Vera »

Hi vmars,
I have no experience with the form designer yet, but saved some helpful links recently that I'd like to share:

- How to attach a main form to a project, with code?
- Really dumb question
- on youtube: The PureBasic 5.0 Form Designer - A Quick Tutorial

greets ~ Vera
User avatar
kenmo
Addict
Addict
Posts: 2033
Joined: Tue Dec 23, 2003 3:54 am

Re: Error msg: "default target" has no main source file .

Post by kenmo »

Assuming you have created a Project (otherwise you shouldn't get this error):

Compiler > Compiler Options > Input Source File
Browse for the "main" file of your project [Gadget_Events.pb] which will be passed to the compiler.

It is slightly confusing since they are labeled differently ("input source file" vs. "main source file").
vmars316
Enthusiast
Enthusiast
Posts: 474
Joined: Fri Jun 29, 2012 12:24 am
Contact:

Re: Error msg: "default target" has no main source file .

Post by vmars316 »

Vera wrote: I have no experience with the form designer yet, but saved some helpful links recently that I'd like to share:
- How to attach a main form to a project, with code?
Greets Vera
This link is especially great , Thanks .
I love this FormDesigner , a real time saver . And fun to design visually .
Cool avatar you have...Vern

BTW: What is rsBasic ?
vmars.us Win11 x64 , Martin Guitar 000-16 (1995)
"All things in moderation , except for love and forgiveness."
User avatar
Vera
Addict
Addict
Posts: 858
Joined: Tue Aug 11, 2009 1:56 pm
Location: Essen (Germany)

Re: Error msg: "default target" has no main source file .

Post by Vera »

Thanks Vern,

one day I'll give it a try and then I'll follow your recommendation :)
But I'll likely stay with the classic way. Besides I don't like the constant-naming, so not only I might have to merge the files, but also rename everything as well.

A disadvantage I see atm, is that one would always have to post at least two codes to pass on an example ... and everyone would have to save two files first, instead of just pasting a test-code into a nameless empty new tab and compile it straight away. ... and not having to remove those testfiles thereafter.

Greets ~ Vera Image
vmars316
Enthusiast
Enthusiast
Posts: 474
Joined: Fri Jun 29, 2012 12:24 am
Contact:

Re: Error msg: "default target" has no main source file .

Post by vmars316 »

kenmo wrote:Assuming you have created a Project (otherwise you shouldn't get this error):

Compiler > Compiler Options > Input Source File
Browse for the "main" file of your project [Gadget_Events.pb] which will be passed to the compiler.

It is slightly confusing since they are labeled differently ("input source file" vs. "main source file").
Works...Thanks
vmars.us Win11 x64 , Martin Guitar 000-16 (1995)
"All things in moderation , except for love and forgiveness."
vmars316
Enthusiast
Enthusiast
Posts: 474
Joined: Fri Jun 29, 2012 12:24 am
Contact:

Re: Error msg: "default target" has no main source file .

Post by vmars316 »

Vera wrote: A disadvantage I see atm, is that one would always have to post at least two codes to pass on an example ... and everyone would have to save two files first, instead of just pasting a test-code into a nameless empty new tab and compile it straight away. ... and not having to remove those testfiles thereafter.

I just tested "Once I get the Form perfect , can I just rename it from .pbf file to .pb , and away we go ?" Answer: YES
That might help some of your concerns ...Vern
vmars.us Win11 x64 , Martin Guitar 000-16 (1995)
"All things in moderation , except for love and forgiveness."
User avatar
Vera
Addict
Addict
Posts: 858
Joined: Tue Aug 11, 2009 1:56 pm
Location: Essen (Germany)

Re: Error msg: "default target" has no main source file .

Post by Vera »

vmars316 wrote:I just tested "Once I get the Form perfect , can I just rename it from .pbf file to .pb , and away we go ?" Answer: YES
That might help some of your concerns ...Vern
Not really.

You've just posted a coding problem split into two files and I still haven't figured out how I'd have to merge them into one code to see if I can help.

... I'll give it a second try hereafter :-)

***
addendum: No way - that's not PureBasic how I know it.

The main event loop made a procedure, which isn't ever called and above that it doesn't even contain the only one gadget event, because that also has been exported to into its own procedure, which isn't called either.
Atm I'd have to re-write your really small example from the scratch or I am forced to save two separat files.

To me the FormDesigner breaks PureBasic.
vmars316
Enthusiast
Enthusiast
Posts: 474
Joined: Fri Jun 29, 2012 12:24 am
Contact:

Re: Error msg: "default target" has no main source file .

Post by vmars316 »

Hmm ,
Oh , i see .
I was focused just on the "can i run it as two .pb files ?"
instead as one .pb file and one .pbf file.
I am a complete newbie , just tinkering to understand .

I'll try and devote some to do more tinkering with this issue .

I am trying to get my first program to work properly (xRainbow.pb and .pbf) .
So far it is running but 'button_clicked' isn't yet working .
ie., MessageRequester("Starting:", "And away we go !") doesn't show .
And after I figure that out , hopefully 'If LoadImage(0, "RainbowBar.png") '
will start working.
..vern

Anyways , here is where it stands now :

Code: Select all

; ProgramName: xRainbow.pb
IncludeFile "xRainbow.pbf"
UsePNGImageDecoder() 
OpenWindow_0()
Procedure button_clicked(eventType)
  MessageRequester("Starting:", "And away we go !")
  If LoadImage(0, "RainbowBar.png")    
;      ImageGadget(10,  120, 150, 50, 83, ImageID(0)) ; imagegadget standard
    Result = ImageGadget(#Gadget, x, y, Width, Height, ImageID [, #PB_Image_Raised)  
   EndIf
EndProcedure 
    Repeat  
    Until WaitWindowEvent() = #PB_Event_CloseWindow
    End

Code: Select all

;
; This code is automatically generated by the FormDesigner.
; Manual modification is possible to adjust existing commands, but anything else will be dropped when the code is compiled.
; Event procedures needs to be put in another source file.
;

Global Window_0   ; ProgramName: xRainbow.pb

Global Image_0, Button_0, ListView_0, ListView_1, ListView_2, ListView_3, Text_0, Text_1, Text_2, Text_3

Declare button_clicked(Event, Window)

Procedure OpenWindow_0(x = 0, y = 0, width = 800, height = 490)
  Window_0 = OpenWindow(#PB_Any, x, y, width, height, "Hex Colors in Rainbow Sequence", #PB_Window_SystemMenu)
  Image_0 = ImageGadget(#PB_Any, 20, 20, 150, 50, 0)
  Button_0 = ButtonGadget(#PB_Any, 20, 100, 150, 24, "START")
  ListView_0 = ListViewGadget(#PB_Any, 260, 50, 100, 420)
  ListView_1 = ListViewGadget(#PB_Any, 390, 50, 100, 420)
  ListView_2 = ListViewGadget(#PB_Any, 520, 50, 100, 420)
  ListView_3 = ListViewGadget(#PB_Any, 650, 50, 120, 420)
  Text_0 = TextGadget(#PB_Any, 270, 10, 80, 30, "  Pixel POS")
  Text_1 = TextGadget(#PB_Any, 400, 10, 80, 30, " Pixel HEX")
  Text_2 = TextGadget(#PB_Any, 530, 10, 90, 30, " Html HEX")
  Text_3 = TextGadget(#PB_Any, 660, 10, 100, 30, "Html Name")
EndProcedure

Procedure Window_0_Events(event)
  Select event
    Case #PB_Event_CloseWindow
      ProcedureReturn #False

    Case #PB_Event_Menu
      Select EventMenu()
      EndSelect

    Case #PB_Event_Gadget
      Select EventGadget()
      EndSelect
    Default
      button_clicked(event,Window_0)
  EndSelect
  ProcedureReturn #True
EndProcedure
vmars.us Win11 x64 , Martin Guitar 000-16 (1995)
"All things in moderation , except for love and forgiveness."
vmars316
Enthusiast
Enthusiast
Posts: 474
Joined: Fri Jun 29, 2012 12:24 am
Contact:

Re: Error msg: "default target" has no main source file .

Post by vmars316 »

Code: Select all

I'll try and devote some to do more tinkering with this issue .
I inserted xRainbow.pb into xRainbow.pbf --> xRainbowPBF.pb
after line 20 of xRainbow.pbf .
And I only had to change;
Procedure Start_clicked(eventType) # of parameters don't match
Declare Start_clicked(Event, Window) [in .pbf] changet to
Start_clicked(eventType)
Start_clicked(event,Window_0) [in .pbf] changed to
Start_clicked(eventType)

It compiles clean and runs.
But it only Flashes the window for a second, then exits .
Not sure why it only flashes for a second .?

...vern

Code: Select all

; ProgramName; xRainbow
Global Window_0

Global Image_0, Button_0, ListView_0, ListView_1, ListView_2, ListView_3, Text_0, Text_1, Text_2, Text_3

Declare Start_clicked(eventType)

Procedure OpenWindow_0(x = 0, y = 0, width = 800, height = 490)
  Window_0 = OpenWindow(#PB_Any, x, y, width, height, "Hex Colors in Rainbow Sequence", #PB_Window_SystemMenu)
  Image_0 = ImageGadget(#PB_Any, 20, 20, 150, 50, 0)
  Button_0 = ButtonGadget(#PB_Any, 20, 100, 150, 24, "START")
  ListView_0 = ListViewGadget(#PB_Any, 260, 50, 100, 420)
  ListView_1 = ListViewGadget(#PB_Any, 390, 50, 100, 420)
  ListView_2 = ListViewGadget(#PB_Any, 520, 50, 100, 420)
  ListView_3 = ListViewGadget(#PB_Any, 650, 50, 120, 420)
  Text_0 = TextGadget(#PB_Any, 270, 10, 80, 30, "  Pixel POS")
  Text_1 = TextGadget(#PB_Any, 400, 10, 80, 30, " Pixel HEX")
  Text_2 = TextGadget(#PB_Any, 530, 10, 90, 30, " Html HEX")
  Text_3 = TextGadget(#PB_Any, 660, 10, 100, 30, "Html Name")
EndProcedure

; ProgramName: xRainbowPB.pb
;IncludeFile "xRainbow.pbf"
UsePNGImageDecoder() 
OpenWindow_0()
Procedure Start_clicked(eventType)
  MessageRequester("Starting:", "And away we go !")
  If LoadImage(0, "RainbowBar.png")    
      ImageGadget(10,  120, 150, 50, 83, ImageID(0)) ; imagegadget standard
;    Result = ImageGadget(#Gadget, x, y, Width, Height, ImageID [, #PB_Image_Raised)  
   EndIf
EndProcedure 
;    Repeat  
;    Until WaitWindowEvent() = #PB_Event_CloseWindow
;    End

Procedure Window_0_Events(event)
  Select event
    Case #PB_Event_CloseWindow
      ProcedureReturn #False

    Case #PB_Event_Menu
      Select EventMenu()
      EndSelect

    Case #PB_Event_Gadget
      Select EventGadget()
      EndSelect
    Default
      Start_clicked(eventType)
  EndSelect
  ProcedureReturn #True
EndProcedure
vmars.us Win11 x64 , Martin Guitar 000-16 (1995)
"All things in moderation , except for love and forgiveness."
missile69
User
User
Posts: 25
Joined: Mon Feb 21, 2011 12:15 pm

Re: Error msg: "default target" has no main source file .

Post by missile69 »

Hi Vern,

Here's the corrected code for you. When associating an event procedure with a button using the form designer, add it in the "Event procedure" field without any parameters or parentheses:
Image

The generated code for that will say Declare button_clicked(EventType). You can't add any additional parameters to this or it won't match the actual function.

xRainbow.pbf

Code: Select all

;
; This code is automatically generated by the FormDesigner.
; Manual modification is possible to adjust existing commands, but anything else will be dropped when the code is compiled.
; Event procedures needs to be put in another source file.
;

Global Window_0   ; ProgramName: xRainbow.pb

Global Image_0, Button_0, ListView_0, ListView_1, ListView_2, ListView_3, Text_0, Text_1, Text_2, Text_3

Declare button_clicked(eventType)

Procedure OpenWindow_0(x = 0, y = 0, width = 800, height = 490)
  Window_0 = OpenWindow(#PB_Any, x, y, width, height, "Hex Colors in Rainbow Sequence", #PB_Window_SystemMenu)
  Image_0 = ImageGadget(#PB_Any, 20, 20, 150, 50, 0)
  Button_0 = ButtonGadget(#PB_Any, 20, 100, 150, 24, "START")
  ListView_0 = ListViewGadget(#PB_Any, 260, 50, 100, 420)
  ListView_1 = ListViewGadget(#PB_Any, 390, 50, 100, 420)
  ListView_2 = ListViewGadget(#PB_Any, 520, 50, 100, 420)
  ListView_3 = ListViewGadget(#PB_Any, 650, 50, 120, 420)
  Text_0 = TextGadget(#PB_Any, 270, 10, 80, 30, "  Pixel POS")
  Text_1 = TextGadget(#PB_Any, 400, 10, 80, 30, " Pixel HEX")
  Text_2 = TextGadget(#PB_Any, 530, 10, 90, 30, " Html HEX")
  Text_3 = TextGadget(#PB_Any, 660, 10, 100, 30, "Html Name")
EndProcedure

Procedure Window_0_Events(event)
  Select event
    Case #PB_Event_CloseWindow
      ProcedureReturn #False

    Case #PB_Event_Menu
      Select EventMenu()
      EndSelect

    Case #PB_Event_Gadget
      Select EventGadget()
        Case Button_0
          button_clicked(EventType())
      EndSelect
  EndSelect
  ProcedureReturn #True
EndProcedure
xRainbow.pb

Code: Select all

; ProgramName: xRainbow.pb
IncludeFile "xRainbow.pbf"
UsePNGImageDecoder() 
OpenWindow_0()
Procedure button_clicked(eventType)
  MessageRequester("Starting:", "And away we go !")
  If LoadImage(0, "RainbowBar.png")    
    ;      ImageGadget(10,  120, 150, 50, 83, ImageID(0)) ; imagegadget standard
    ; Malformed line
    ;Result = ImageGadget(#Gadget, x, y, Width, Height, ImageID [, #PB_Image_Raised)
    Result = ImageGadget(10, x, y, Width, Height, ImageID(0), #PB_Image_Raised)  
   EndIf
EndProcedure 
Repeat
  e = WaitWindowEvent()
  ;When using the form designer, you need to send any received events from your event loop to the form's event procedure.
  ;if you had multiple windows, you'd check which window caused the event and send that event to the proper event procedure
  ;for that window. Something like this:
  ;   If EventWindow() = Window_0
  ;     Window_0_Events(e)
  ;   ElseIf EventWindow() = Window_2
  ;     Window_2_events(e)
  ;   EndIf
  
  ;You only have one window so we don't need to check that.
  Window_0_Events(e) ;Send event to form's event procedure
  
  ;if you had other things you wanted to do with that event, you'd add them here like so:
  ;   If e = #PB_Event_Gadget
  ;     Debug "gadget event"
  ;   EndIf
  
Until e = #PB_Event_CloseWindow
End
Also, if you'd like to at some point combine the files into one for easier sharing with other users like Vera said, all you usually have to do is copy the form's code to the top of your main file and comment out the xinclude for the form. Just don't save the file in this state if you'd still like to be able to use the form designer to make modifications later. Here's what it would look like as one file:

Code: Select all

;
; This code is automatically generated by the FormDesigner.
; Manual modification is possible to adjust existing commands, but anything else will be dropped when the code is compiled.
; Event procedures needs to be put in another source file.
;

Global Window_0   ; ProgramName: xRainbow.pb

Global Image_0, Button_0, ListView_0, ListView_1, ListView_2, ListView_3, Text_0, Text_1, Text_2, Text_3

Declare button_clicked(eventType)

Procedure OpenWindow_0(x = 0, y = 0, width = 800, height = 490)
  Window_0 = OpenWindow(#PB_Any, x, y, width, height, "Hex Colors in Rainbow Sequence", #PB_Window_SystemMenu)
  Image_0 = ImageGadget(#PB_Any, 20, 20, 150, 50, 0)
  Button_0 = ButtonGadget(#PB_Any, 20, 100, 150, 24, "START")
  ListView_0 = ListViewGadget(#PB_Any, 260, 50, 100, 420)
  ListView_1 = ListViewGadget(#PB_Any, 390, 50, 100, 420)
  ListView_2 = ListViewGadget(#PB_Any, 520, 50, 100, 420)
  ListView_3 = ListViewGadget(#PB_Any, 650, 50, 120, 420)
  Text_0 = TextGadget(#PB_Any, 270, 10, 80, 30, "  Pixel POS")
  Text_1 = TextGadget(#PB_Any, 400, 10, 80, 30, " Pixel HEX")
  Text_2 = TextGadget(#PB_Any, 530, 10, 90, 30, " Html HEX")
  Text_3 = TextGadget(#PB_Any, 660, 10, 100, 30, "Html Name")
EndProcedure

Procedure Window_0_Events(event)
  Select event
    Case #PB_Event_CloseWindow
      ProcedureReturn #False

    Case #PB_Event_Menu
      Select EventMenu()
      EndSelect

    Case #PB_Event_Gadget
      Select EventGadget()
        Case Button_0
          button_clicked(EventType())
      EndSelect
  EndSelect
  ProcedureReturn #True
EndProcedure

; ProgramName: xRainbow.pb
;IncludeFile "xRainbow.pbf"
UsePNGImageDecoder() 
OpenWindow_0()
Procedure button_clicked(eventType)
  MessageRequester("Starting:", "And away we go !")
  If LoadImage(0, "RainbowBar.png")    
    ;      ImageGadget(10,  120, 150, 50, 83, ImageID(0)) ; imagegadget standard
    ;Result = ImageGadget(#Gadget, x, y, Width, Height, ImageID [, #PB_Image_Raised)
    Result = ImageGadget(10, x, y, Width, Height, ImageID(0), #PB_Image_Raised)  
   EndIf
EndProcedure 
Repeat
  e = WaitWindowEvent()
  ;When using the form designer, you need to send any received events from your event loop to the form's event procedure.
  ;if you had multiple windows, you'd check which window caused the event and send that event to the proper event procedure
  ;for that window. Something like this:
  ;   If EventWindow() = Window_0
  ;     Window_0_Events(e)
  ;   ElseIf EventWindow() = Window_2
  ;     Window_2_events(e)
  ;   EndIf
  
  ;You only have one window so we don't need to check that.
  Window_0_Events(e) ;Send event to form's event procedure
  
  ;if you had other things you wanted to do with that event, you'd add them here like so:
  ;   If e = #PB_Event_Gadget
  ;     Debug "gadget event"
  ;   EndIf
  
Until e = #PB_Event_CloseWindow
End
User avatar
Vera
Addict
Addict
Posts: 858
Joined: Tue Aug 11, 2009 1:56 pm
Location: Essen (Germany)

Re: Error msg: "default target" has no main source file .

Post by Vera »

Hello missile,
thanks for your merged example and you additional explanations. :)
for easier sharing with other users like Vera said, all you usually have to do is copy the form's code to the top of your main file and comment out the xinclude for the form
Yes, I too tried that straight away, but it didn't work.

Looks like one also has to enhance the minimalistic event loop manually to activate the event loop procedure at all. Here I don't understand why this is not supplied by the form designer (how shall it work without?)

To me it is crazy to have the main pb-file catching the event-types to send them to the pbf-file where they are specified. Then the event-identification is send back to the main-file where its according commands are read and processed.
What's the advantage of such a confusing criss-cross?
Does one always have to have both (many) files open to switch between them to reach the splitted event-parts?


Another thing I find disturbing;
If the main window procedure uses #PB_Any for the gadgets and also saves the asigned values in variables. Why then does one have to assing another fixed value for the same gadget and can't use the variable?
See the imagegadget, which get's a '10' in the button_clicked procedure.
What are those variables good for if they can't be used?
What is #PB_Any good for if I still have to set the gadget-constants myself?
How does one decide what values to take? -out of the blue? - Could Enumeration still be used?


And in the end. Even if I manage to merge these kind of files and I could figure out a solution to something and post it. The questioner would then have to port it back into his separated files. ... and/or again merge them for the next issue ... and so forth.

This is surely anything but dividing the purbasic-programers into two groups with a huge obstacle between them.

I'll surely try to catch up how to merge those files but it disallows a cross testing of a same code as that wouldn't exist and further issues can arise if the merging itself is somehow faulty.

This is still not inviting to use the form designer for my part.

greets ~ Vera
missile69
User
User
Posts: 25
Joined: Mon Feb 21, 2011 12:15 pm

Re: Error msg: "default target" has no main source file .

Post by missile69 »

Hi Vera,
I think Vmars edited his code in the forum text box after pasting it and introduced additional errors as the code he posted didn't work for me either at first, even as two separate files.
Vera wrote:To me it is crazy to have the main pb-file catching the event-types to send them to the pbf-file where they are specified... What's the advantage?...
I think the intended advantage is just that there's less code that you have to write manually. When you fill in the 'Event procedure' field for each of your gadgets through the form editor, then all you need in your main code file is to pass the events to the form's event procedure. You don't need to check the type of event or anything other than the originating window if you had multiple windows. Now whenever there's an event, the form automatically calls the procedure associated with that gadget, all with you only having written a few lines for your main code's event loop.
Vera wrote:If the main window procedure uses #PB_Any for the gadgets and also saves the asigned values in variables. Why then does one have to assing another fixed value for the same gadget and can't use the variable?
The variable that was used in the form can be used in that line where I put a '10'. This was my mistake. In the line Vmars wrote, he used the constant '#Gadget' which I didn't see defined anywhere and would cause an error, so I just stuck a ten in there instead to get the code to run... and yes, I did just pick it out of blue when I should have used the image gadget that was already defined in the form and just updated it's displayed image with SetGadgetState(Image_0, ImageID(0)) :oops:

That being said, I agree with you and don't particularly like having my code spread out this way either. There is a option you can uncheck in the form editor that is labeled 'Generate events procedure'. This seems to be checked by default but when you clear the check mark, the automatically generated code is purely just for the layout... no more need for passing events back and forth or changing the way you usually write your event loop. This makes more sense to me - pbf file only for the layout and the pb file for your actual code. I went from disliking the form editor, to using it for just about all my projects when I found that option and I think having it checked by default probably keeps other users from liking it too.

I urge you to try the form designer again sometime with that option turned off, Vera. You'll find it makes more sense than the default way it works and though you'll still have two files, you might enjoy the flexibility of being able to visually design/edit your form whenever you want, while not having to change the way you usually process your events. :)
User avatar
Vera
Addict
Addict
Posts: 858
Joined: Tue Aug 11, 2009 1:56 pm
Location: Essen (Germany)

Re: Error msg: "default target" has no main source file .

Post by Vera »

Hello missile,

thanks so much for having the patience and taking your time to give me (us) this thorough response. Image

I can see the advantage now and it 'paints a conclusive picture', especially when a program becomes more complex.

When Image_0 failed for me, I too assumed it might lie within Vern's unknown changes, but alike you with '#Gadget' I too missed to realize that the passed on 'image sizes' were just the classic 'patterns', but not meant to be send to an already completely presetted gadget.
Your 'SetGadgetState(Image_0, ImageID(0))' works out fine :-)

Thanks for pointing me to that FormDesigner presetting. I had also thought of something similar, which would be just to use the FormDesigner to build up a basic gui for a start and port this to the main file and proceed as normal.
But I also get your point to keep it as valid form-file for any later quick changes.
I'll certainly give it a fair try when the time is right. (But not while being highly active with another project.)

On a sidenote: Before I descided to choose PureBasic for good, I also tested Delphi for a while and to 'program' by playing with the forms like baking in a sandbox was really tempting, but it in no way helped me to get the idea of Pascal, so I dropped it and moved to more clear spaces.

Thanks again~ Vera Image
vmars316
Enthusiast
Enthusiast
Posts: 474
Joined: Fri Jun 29, 2012 12:24 am
Contact:

Re: Error msg: "default target" has no main source file .

Post by vmars316 »

missile69 wrote:There is a option you can uncheck in the form editor that is labeled 'Generate events procedure'. This seems to be checked by default but when you clear the check mark, the automatically generated code is purely just for the layout...
Aha, great , thats what I have been trying to do . Thanks !

Well , I've (we) made some headway .
Here is my working code (sorry about my bad code above!) :

Code: Select all

; ; ProgramName: xRainbow.pb
Global Window_0
Global Image_0, Button_0, Button_1, ListView_0, ListView_1, ListView_2, ListView_3, Text_0, Text_1, Text_2, Text_3
Declare Button_0_clicked(eventType)
Declare Button_1_clicked(eventType)
UsePNGImageDecoder()
Procedure OpenWindow_0(x = 0, y = 0, width = 800, height = 490)
  Window_0 = OpenWindow(#PB_Any, x, y, width, height, "Hex Colors in Rainbow Sequence", #PB_Window_SystemMenu)
  Image_0 = ImageGadget(#PB_Any, 20, 75, 150, 50, 0)
  Button_0 = ButtonGadget(#PB_Any, 20, 150, 150, 24, "Load Image")
  Button_1 = ButtonGadget(#PB_Any, 20, 200, 150, 24, "Process Image")
  ListView_0 = ListViewGadget(#PB_Any, 260, 50, 100, 420)
  ListView_1 = ListViewGadget(#PB_Any, 390, 50, 100, 420)
  ListView_2 = ListViewGadget(#PB_Any, 520, 50, 100, 420)
  ListView_3 = ListViewGadget(#PB_Any, 650, 50, 120, 420)
  Text_0 = TextGadget(#PB_Any, 270, 10, 80, 30, "  Pixel POS")
  Text_1 = TextGadget(#PB_Any, 400, 10, 80, 30, " Pixel HEX")
  Text_2 = TextGadget(#PB_Any, 530, 10, 90, 30, " Html HEX")
  Text_3 = TextGadget(#PB_Any, 660, 10, 100, 30, "Html Name")
;  MessageRequester("Procedure OpenWindow_0...", " Finished Loading Gadgets")
EndProcedure

OpenWindow_0()
Procedure Button_0_clicked(eventType)  ; (eventType)
                                       ; Couldnt find an Upload option on this Forum:
    ; Copy RainbowBar.png from here: http://www.vmars316.com/ShowMe/RainbowBar.png
  If LoadImage(0, "RainbowBar.png")    
      ImageGadget(Image_0, 20, 75, 150, 50, ImageID(0)) ; imagegadget standard
;    Result = ImageGadget(#Gadget, x, y, Width, Height, ImageID [, #PB_Image_Raised)  
   EndIf
 EndProcedure 
 Procedure Button_1_clicked(eventType)
   MessageRequester("Processing Image..", "Coming Soon...") 
 EndProcedure 
      
 Repeat
     Event = WaitWindowEvent()
     Select Event
       Case #PB_Event_Gadget
      Select EventGadget()
        Case Button_0
          Button_0_clicked(EventType())
        Case Button_1
          Button_1_clicked(EventType())
      EndSelect
       Case #PB_Event_Menu
         Select EventMenu()
         EndSelect
     EndSelect
   Until Event = #PB_Event_CloseWindow
 End    
 


It runs fine .

I am still perplexed about :
Why do I need two "OpenWindow_0()" commands .

Thanks All...
vmars.us Win11 x64 , Martin Guitar 000-16 (1995)
"All things in moderation , except for love and forgiveness."
Post Reply