Post by Mark Dunham on Apr 24, 2019 13:30:10 GMT -5
Okay this maybe my lack of sleep but I cannot figure this out. When I use filedialog to open my daggers.dat file and I hit cancel I get my "No file chosen!" message but if I click load again the code for my "New" button runs. It does the same thing if I load the file and then try to load another.
Daggers.dat (201 B)
nomainwin
'ARRAY ITEMS$(ID,NAME,WEIGHT)
dim items$(100,3)
entries = 0
length = 0
id = 0
nm = 0
wt = 0
'PRINT A SPECIFIC ITEMS NAME
'for x = 1 to idcount - 1
'if items$(x,1) = id$ then print items$(x,2)
'next x
'PRINT ALL ITEMS IN A NICE FORMAT
'print "ID:"; TAB(15); "Name:"; TAB(43); "Weight:"
'for i = 1 to idcount - 1
'print items$(i,1), items$(i,2), items$(i,3)
'next i
[Main]
WindowWidth = 640
WindowHeight = 480
UpperLeftX = int((DisplayWidth - WindowWidth)/2)
UpperLeftY = int((DisplayHeight - WindowHeight)/2)
statictext #Parse.st1, "ID", 25, 20, 20, 20
statictext #Parse.st2, "Description", 105, 20, 110, 20
statictext #Parse.st3, "Weight", 350, 20, 60, 20
texteditor #Parse.Editor, 25, 40, 500, 300
button #Parse.Load, "Load", LoadData, UL, 25, 375, 50, 25
button #Parse.NewEntry, "New", [NewEntry], UL, 80, 375, 50, 25
menu #Parse, "&File","E&xit",[Parse.Quit]
menu #Parse, "Edit"
open "Load Data" for window as #Parse
#Parse, "trapclose [Parse.Quit]"
#Parse, "font courier 12 bold"
#Parse.Editor, "!disable"
#Parse.NewEntry, "!disable"
hMain=hWnd(#Parse)
hMainMenu=GetMenu(hMain)
hMainEdit=GetSubMenu(hMainMenu,1)
result=RemoveMenu(hMainMenu,hMainEdit)
Call DrawMenuBar hWnd(#Parse)
wait
[LoadData]
#Parse.NewEntry, "!enable"
filedialog "open", "*.dat", filename$
if filename$ <> "" then
open filename$ for input as #dat
'myDat$ = INPUT$(#dat, LOF(#dat))
input #dat, entries
for i = 1 to entries
input #dat, items$(i,1)
length = len(items$(i,1))
if id < length then id = length
input #dat, items$(i,2)
length = len(items$(i,2))
if nm < length then nm = length
input #dat, items$(i,3)
length = len(items$(i,3))
if wt < length then wt = length
next i
close #dat
#Parse.Editor, "!cls"
for i = 1 to entries
List$ = items$(i,1) + SPACE$(id-len(items$(i,1))+5) + items$(i,2) + SPACE$(nm-len(items$(i,2))+5) + items$(i,3)
#Parse.Editor, List$
next i
else
notice "No file chosen!"
end if
wait
[NewEntry]
WindowWidth = 250
WindowHeight = 200
UpperLeftX = 100'int((DisplayWidth - WindowWidth)/2)
UpperLeftY = 100'int((DisplayHeight - WindowHeight)/2)
statictext #NE.1, "ID:", 5, 30, 15, 20
textbox #NE.Id, 45, 25, 180, 25
statictext #NE.2, "Name:", 5, 60, 30, 20
textbox #NE.Name, 45, 55, 180, 25
statictext #NE.3, "Weight:", 5, 90, 40, 20
textbox #NE.Weight, 45, 85, 180, 25
button #NE.Save, "Save", [SaveEntry], UL, 25, 125, 50, 25
open "New Entry" for dialog_modal as #NE
#NE, "trapclose [NE.Quit]"
wait
[SaveEntry]
entries = entries + 1
#NE.Id, "!contents? id$"
#NE.Name, "!contents? name$"
#NE.Weight, "!contents? weight$"
items$(entries,1) = id$
items$(entries,2) = name$
items$(entries,3) = weight$
open "Daggers.dat" for output as #SE
#SE, entries
for i = 1 to entries
#SE, items$(i,1)
#SE, items$(i,2)
#SE, items$(i,3)
next i
close #SE
close #NE
goto [LoadData]
wait
[NE.Quit]
close #NE
wait
[Parse.Quit]
close #Parse
end
wait
'functions:
Sub DrawMenuBar hWnd
CallDLL #user32, "DrawMenuBar",_
hWnd As ulong, r As boolean
End Sub
Function GetSubMenu(hMenuBar,nPos)
CallDLL #user32, "GetSubMenu",_
hMenuBar As ulong, nPos As long,_
GetSubMenu As ulong
End Function
Function GetMenu(hWnd)
CallDLL #user32, "GetMenu",hWnd As ulong,_
GetMenu As ulong
End Function
Function RemoveMenu(hMenu,hSubMenu)
CallDLL #user32, "RemoveMenu", hMenu As ulong,_
hSubMenu As ulong, _MF_BYCOMMAND As ulong,_
RemoveMenu As boolean
End Function