|
Post by Walt Decker on Dec 1, 2020 14:45:53 GMT -5
Are there no constants in LB? Can one declare a type in a sub, e.g. :
Struct Mystruct A as long, B as string SUB AnySub()
DIM G as MyStruct
END SUB
Can one define one's own stylebits? In the help I noticed that static controls have only 2 styles listed when there are quite a number of styles available.
Sorry about the format. I am not used to this forum.
|
|
|
Post by Carl Gundel on Dec 1, 2020 14:55:10 GMT -5
Are there no constants in LB? Can one declare a type in a sub, e.g. :
Can one define one's own stylebits? In the help I noticed that static controls have only 2 styles listed when there are quite a number of styles available. Not really. You can make pretend constants by just naming variables all uppercase. MYCONSTANT = 4 myVariable = 4 You can add stylebits values this way. LB doesn't support TYPE, but LB5 will let you do something comparable.
|
|
|
Post by Chris Iverson on Dec 1, 2020 15:05:00 GMT -5
1. There are no explicit constants in LB.
2. LB does not natively have any form of type declaration/definition. You cannot make your own custom types in LB, and have new variables use those types. LB CAN make structs, but those are one-time use single variables, not a typedef that you can apply to any number of variables.
3. Depends on what you mean by "define". If you mean make up style values on the fly and have them mean something that you define, then no.
If you mean defined styles beyond what LB recognizes built-in, then yes.
Most default Win32 styles should be usable in LB, by prefixing an underscore to the Win32 style name. For example, to use SS_CENTER to center-justify text on a statictext control, you can use it in LB as _SS_CENTER.
However, many Win32 controls have gained new styles over the years, and those style names may not have been added to LB.
If that's the case, as long as you know what the numeric value of the style SHOULD be, you can define your own variable to represent it, and use that variable in place of the style.
For example, centered statictext caption:
'Form created with the help of Freeform 3 v07-15-08 'Generated on Dec 01, 2020 at 13:57:36
[setup.main.Window]
'-----Begin code for #main
nomainwin WindowWidth = 550 WindowHeight = 410 UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)
'-----Begin GUI objects stylebits #main.statictext1, _SS_CENTER, 0, 0, 0 statictext #main.statictext1, "StaticText Caption", 5, 57, 535, 20
'-----End GUI objects code
open "untitled" for window as #main print #main, "font ms_sans_serif 10" print #main, "trapclose [quit.main]"
[main.inputLoop] 'wait here for input event wait
[quit.main] 'End the program close #main end
That uses the style constant _SS_CENTER.
If _SS_CENTER was not defined in LB, you could look up the value of the constant:
#define SS_CENTER 0x00000001L
And use that value in a variable:
' 0x00000001L is just 1 SS.CENTER = 1
'Form created with the help of Freeform 3 v07-15-08 'Generated on Dec 01, 2020 at 13:57:36
[setup.main.Window]
'-----Begin code for #main
nomainwin WindowWidth = 550 WindowHeight = 410 UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)
'-----Begin GUI objects stylebits #main.statictext1, SS.CENTER, 0, 0, 0 statictext #main.statictext1, "StaticText Caption", 5, 57, 535, 20
'-----End GUI objects code
open "untitled" for window as #main print #main, "font ms_sans_serif 10" print #main, "trapclose [quit.main]"
[main.inputLoop] 'wait here for input event wait
[quit.main] 'End the program close #main end
So even if LB doesn't recognize a style name natively, there shouldn't be any style that you can't use from LB, as long as you know the numeric value of it.
|
|
|
Post by Walt Decker on Dec 1, 2020 15:15:00 GMT -5
I have seen some code that used "as ptr." Is ptr a reserved word? I saw no mention of it in help.
|
|
|
Post by Chris Iverson on Dec 1, 2020 20:30:43 GMT -5
As far as I can tell, the datatype definitions aren't reserved words, but you might want to be careful using them.
See the page "Using types with STRUCT and CALLDLL" for a list of the datatypes supported by the STRUCT and CALLDLL statements.
|
|
|
Post by Walt Decker on Dec 2, 2020 10:24:36 GMT -5
What is the significance of "." in a numaric variable, as in MAX.PATH = ? Can char variables use the same syntax?
PS: The browsforfolder.bas example throws a GPF after selecting a directory.
|
|
|
Post by Chris Iverson on Dec 2, 2020 13:23:38 GMT -5
There's no real significance, it's mainly used as a separator in variables intended to be constants, because underscores can't be used in variable names in LB.
You'll note in my example above, when I translated the constant SS_CENTER manually, I named it SS.CENTER. I can't name it SS_CENTER, or I would've. This is very common with various constants defined by the Win32 API; if the constant itself can't be used in LB(by prepending an underscore, i.e. _SS_CENTER), then the value of the constant is manually assigned to a variable with the same name as the constant, with underscores replaced by periods.
String variables can be named the same, too.
As for the browseForFolder.bas example, is there a specific folder you select that causes it to happen? Or does it always happen? I've tested it a couple times now, and haven't gotten a crash yet.
|
|
|
Post by tsh73 on Dec 2, 2020 13:24:09 GMT -5
LB does not uses "." for anything. So variable "a.x" is valid, but does not relate to variable "a", at all. So you can write crazy stuff like things below - just do not wonder if all other BASIC would refuse compile this.
a.n.y.t.h.i.n.g=1/3 print a.n.y.t.h.i.n.g nothing.$="NULL" print nothing.$ a=1 a.x=2 a.y=3 b.z=4 print a.x, a.y '2 3 print a '1 print a. '0 - not defined print b.z print b '0 - not defined c...=5 print c... '5
|
|
|
Post by Carl Gundel on Dec 2, 2020 14:57:18 GMT -5
LB does not uses "." for anything. So variable "a.x" is valid, but does not relate to variable "a", at all. So you can write crazy stuff like things below - just do not wonder if all other BASIC would refuse compile this. LB actually does use the . for handles and subhandles. i.e. button #win.bttn, etc....
|
|
|
Post by Walt Decker on Dec 2, 2020 15:03:08 GMT -5
Mr. Iverson, IIR, it happened when I selected a directory on my E drive and again on my D drive.
|
|
|
Post by Carl Gundel on Dec 2, 2020 15:07:12 GMT -5
Mr. Iverson, IIR, it happened when I selected a directory on my E drive and again on my D drive. Hey Walt, what version of Windows? I assume LB v4.5.1?
|
|