example in liberty basic 4 does not run on liberty basic 5
Apr 14, 2023 4:59:57 GMT -5
gaslouk likes this
Post by splash3313 on Apr 14, 2023 4:59:57 GMT -5
This example found on these forums runs on liberty basic 4 but liberty basic 5, why not
[setup.main.Window]
'-----Begin code for #main
nomainwin
WindowWidth = 550
WindowHeight = 440
UpperLeftX=int((DisplayWidth-WindowWidth)/2)
UpperLeftY=int((DisplayHeight-WindowHeight)/2)
'-----Begin GUI objects code
open "notepad.ini" for input as #1
while eof(#1) = 0
line input #1, text$
temp$ = left$(text$,10)
if temp$ = "background" then
temp1$ = mid$(text$,12,len(text$))
TexteditorColor$ = temp1$
'notice temp1$
end if
if instr(temp$,"path") then
temp1$ = mid$(text$,6,len(text$))
path$ = temp1$
end if
wend
close #1
'TexteditorColor$ = "yellow"
texteditor #main.textedit3, 5, 37, 525, 317
global fileN$
fileN$ = "Untitled"
global fileName$
global filestatus
groupbox #main.groupbox1, fileN$, 0, 20, 535, 340
bmpbutton #main.bmpbutton1, ".\bmp\NEW.BMP", [filenew], UL, 0, 0
bmpbutton #main.bmpbutton2, ".\bmp\OPEN2.BMP", [fileopen], UL, 25, 0
bmpbutton #main.bmpbutton3, ".\bmp\SAVE2.BMP", filesave, UL, 50, 0
'bmpbutton #main.bmpbutton4, ".\bmp\PRINT.BMP", [fileprint], UL, 75, 0
bmpbutton #main.bmpbutton5, ".\bmp\RUN.BMP", [runbas], UL, 75, 0
'statictext #main.statictext4, "Line 1 Col 1 CAPS INS NUM", 2, 362, 535, 20
'-----End GUI objects code
'-----Begin menu code
menu #main, "File",_
"New" , [filenew],_
"Open" , [fileopen],_
"Save" , filesave,_
"Save as", filesaveas,|,_
"Print" , [fileprint],|,_
"Quit" , [quit.main]
menu #main, "Edit" ' <-- Texteditor menu.
menu #main, "Options",_
"Change font", [fontchange],_
"Background Color", [backcolor]
menu #main, "Run",_
"Run .bas file", [runbas],_
"Debug .bas file", [debugbas],_
"Set Liberty.exe path", [setlibertypath]
menu #main, "Help",_
"About", [aboutapp]
'-----End menu code
open "Liberty Notepad v0.1" for window as #main
print #main, "font segoe_ui 9"
print #main, "trapclose [quit.main]"
print #main.textedit3, "!font courier_new 10"
'----Begin code for statusbar
h=hwnd(#main)
print #main.textedit3, "!origin? columnVar rowVar " ;
countVar=0
value$ = "Total Lines 0"
styleValue = _WS_VISIBLE or _WS_CHILD
hStatusBar=initalizeStatusBar(h,value$)
print #main, "resizehandler [resizeStatusbar]"
timer 500, [updatestats]
'----End code for statusbar
struct caretpos, _
xpos as long, _
ypos as long
struct tagsize, _
cx as long, _
cy as long
[main.inputLoop] 'wait here for input event
wait
[updatestats]
CallDLL #user32, "GetKeyState", _VK_CAPITAL as Long, result as Long
If result <> 0 Then
capsres$ = " CAPS "
Else
capsres$ = " "
End If
CallDLL #user32, "GetKeyState", _VK_INSERT as Long, result as Long
If result <> 0 Then
insres$ = " INS "
Else
insres$ = " "
End If
CallDLL #user32, "GetKeyState", _VK_NUMLOCK as Long, result as Long
If result <> 0 Then
numres$ = " NUM "
Else
numres$ = " "
End If
'CallDLL #user32, "GetCaretPos", caretpos as struct, result as Long
'If result <> 0 Then
'hndl = hwnd(#main.textedit3)
'lpstring$ = "A"
'lpstringlen = len(lpstring$)
'CallDLL #gdi32, "GetTextExtentPoint32A", hndl as ulong, lpstring$ as ptr, lpstringlen as long, tagsize as struct, result as long
'print #main.textedit3, result
'If result <> 0 Then
'rowVar = caretpos.ypos.struct / tagsize.cy.struct
'columnVar = caretpos.xpos.struct / tagsize.cx.struct
'End if
rowVar = caretpos.ypos.struct
columnVar = caretpos.xpos.struct
'Else
' rowVar = -1
' columnVar = -1
'End If
print #main.textedit3, "!lines countVar";
value$ = "Total lines "; countVar; capsres$; insres$; numres$
a = SendMessagePtr(hStatusBar,_WM_SETTEXT,0, value$)
goto [main.inputLoop]
[filenew] 'Perform action for menu File, item New
'Insert your own code here
filestatus = CheckFileModified()
if filestatus = 1 then
confirm "Save changes?"; answer$
if answer$ = "yes" then
'write file save routine here
if fileN$ = "Untitled" then call filesaveas "" else call filesave ""
end if
end if
fileN$ = "Untitled"
print #main.groupbox1, fileN$;
print #main.textedit3, "!cls";
wait
[fileopen] 'Perform action for menu File, item Open
filestatus = CheckFileModified()
if filestatus = 1 then
confirm "Save changes?"; answer$
if answer$ = "yes" then
'write file save routine here
if fileN$ = "Untitled" then call filesaveas "" else call filesave ""
end if
end if
'Insert your own code here
filedialog "Open text file", "*.txt", fileName$
if fileName$ <> "" then
print #main.groupbox1, fileName$;
open fileName$ for input as #1
print #main.textedit3, "!contents #1";
print #main.textedit3, "!origin 1 1";
close #1
fileN$ = fileName$
end if
wait
SUB filesave handle$ 'Perform action for menu File, item Save
if fileN$ = "Untitled" then
call filesaveas ""
exit sub
else
print #main.textedit3, "!contents? edited$"
open fileName$ for output as #1
print #1, edited$
close #1
end if
END SUB
SUB filesaveas handle$ 'Perform action for menu File, item Save as
filedialog "Save file", "*.txt", fileNewName$
if fileNewName$ <> "" then
print #main.textedit3, "!contents? edited$"
open fileNewName$ for output as #1
print #1, edited$
close #1
fileName$ = fileNewName$
fileN$ = fileNewName$
print #main.groupbox1, fileN$;
end if
END SUB
[fileprint] 'Perform action for menu File, item Print
'Insert your own code here
print #main.textedit3, "!origin?";
input #main.textedit3, rowVar,columnVar
print #main.textedit3, "!contents?";
input #main.textedit3, saveit$
lprint saveit$
dump
print #main.textedit3, "!origin ";rowVar;" ";columnVar;"";
wait
[fontchange] 'Perform action for menu Font, item Change font
'Insert your own code here
fontdialog "arial 10 italic", chosenFont$
if chosenFont$ <> "" then
print #main.textedit3, "!font "; chosenFont$
wait
end if
wait
[runbas]
if right$(fileName$,4)=".bas" then
runcmd$ = path$ + " -r " + fileName$
run runcmd$
else
notice "Not a .bas file"
end if
goto [main.inputLoop]
[debugbas]
if right$(fileName$,4)=".bas" then
runcmd$ = path$ + " -d " + fileName$
run runcmd$
else
notice "Not a .bas file"
end if
goto [main.inputLoop]
[setlibertypath]
filedialog "Locate Liberty.exe", "*.exe", fileName$
if fileName$ <> "" then
notice "Requires restart to take effect."
open "notepad.ini" for input as #temp1
open "temp.ini" for append as #temp2
while eof(#temp1)=0
line input #temp1, text$
temp$ = left$(text$,4)
if temp$ = "path" then
print #temp2, "path=";fileName$
else
print #temp2, text$
end if
wend
close #temp1
close #temp2
kill "notepad.ini"
name "temp.ini" as "notepad.ini"
end if
goto [main.inputLoop]
[changeMessageBar]
'----This changes the text in the statusbar
'----Change the text in value$ then gosub this routine
a = SendMessagePtr(hStatusBar,_WM_SETTEXT,0, value$)
wait
[resizeStatusbar]
'----This makes the statusbar fit when window is resized
wWid = WindowWidth
wHig = WindowHeight
print #main.groupbox1, "!locate 0 20 "; wWid; " "; wHig-38;
print #main.textedit3, "!locate 5 37 "; wWid-10; " "; wHig-65;
a= SendMessageLong(hStatusBar,_WM_SIZE,0,WindowWidth)
print #main, "refresh"
wait
'----End of statusbar resizer code
[aboutapp] 'Perform action for menu Help, item About
'Insert your own code here
Notice "Liberty Notepad ver 0.1 programmed in Liberty BASIC ver 4.5.1 by JagSOFT 2021."
wait
[quit.main] 'End the program
filestatus = CheckFileModified()
if filestatus = 1 then
confirm "Save changes? Press no if already saved."; answer$
if answer$ = "yes" then
if fileN$ = "Untitled" then
call filesaveas ""
else
call filesave ""
end if
end if
end if
close #main
end
[backcolor]
'Form created with the help of Freeform 3 v07-31-2015
'Generated on Sep 15, 2021 at 21:51:09
[setup.bkcolor.Window]
'-----Begin code for #bkcolor
WindowWidth = 295
WindowHeight = 100
UpperLeftX=int((DisplayWidth-WindowWidth)/2)
UpperLeftY=int((DisplayHeight-WindowHeight)/2)
'-----Begin GUI objects code
statictext #bkcolor.statictext7, "Choose background color", 5, 5, 137, 20
ComboboxColor$ = "white"
array$(1)="yellow"
array$(2)="red"
array$(3)="pink"
array$(4)="blue"
array$(5)="green"
array$(6)="cyan"
array$(7)="white"
array$(8)="lightgray"
combobox #bkcolor.combobox8, array$(), [combobox8DoubleClick], 150, 7, 100, 100
button #bkcolor.button9,"OK",[button9Click], UL, 45, 32, 65, 25
'-----End GUI objects code
open "Background color" for dialog_modal as #bkcolor
print #bkcolor, "font segoe_ui 9"
print #bkcolor, "trapclose [quit.bkcolor]"
[bkcolor.inputLoop] 'wait here for input event
wait
[combobox8DoubleClick] 'Perform action for the combobox named 'combobox8'
'Insert your own code here
goto [bkcolor.inputLoop]
[button9Click] 'Perform action for the button named 'button9'
'Insert your own code here
print #bkcolor.combobox8, "selection? selected$"
if selected$ = "" then selected$="white"
[quit.bkcolor] 'End the program
close #bkcolor
notice "Requires restart to take effect"
open "notepad.ini" for input as #temp1
open "temp.ini" for append as #temp2
while eof(#temp1)=0
line input #temp1, text$
temp$ = left$(text$,10)
if temp$ = "background" then
print #temp2, "background=";selected$
else
print #temp2, text$
end if
wend
close #temp1
close #temp2
kill "notepad.ini"
name "temp.ini" as "notepad.ini"
goto [main.inputLoop]
'------------------------------------------------------
'----------------- Subs and Functions -----------------
'------------------------------------------------------
FUNCTION initalizeStatusBar(h, value$)
calldll #comctl32,"InitCommonControls",_
result as long
styleValue = _WS_VISIBLE or _WS_CHILD
calldll #comctl32,"CreateStatusWindow",_
styleValue as long,_
value$ as ptr,_
h as long,_
22 as long,_
r as long
initalizeStatusBar=r
END FUNCTION
FUNCTION SendMessagePtr(hWnd,msg,w,p$)
CallDLL #user32, "SendMessageA",_
hWnd As long, _
msg As long,_
w As long,_
p$ As ptr,_
SendMessagePtr As long
END FUNCTION
FUNCTION SendMessageLong(hStatusBar,msg,w,p)
CallDLL #user32, "SendMessageA",_
hStatusBar As long, _
msg As long,_
w As long,_
p As long,_
SendMessagePtr As long
END FUNCTION
FUNCTION CheckFileModified()
print #main.textedit3, "!modified? textmodified$" ;
retval=0
if textmodified$ = "true" then retval=1
CheckFileModified=retval
END FUNCTION
'------------------------------------------------------
'--------------- End Subs and Functions ---------------
'------------------------------------------------------