|
Post by wexhammer on Jan 8, 2020 12:29:43 GMT -5
It seems as though i was suffering from plonker syndrome. Maybe i need to take frequent breaks. Anyway i have it sorted now so thanks! And to be honest that was simple i should of got it! Cheers again...
|
|
|
Post by Chris Iverson on Jan 8, 2020 12:29:57 GMT -5
You're mixing subroutine and branch label event handlers, which is a bad idea. Make it all branch labels, or all subroutines. The problem is, if a subroutine event handler executes(like the one you have handling the listboxes), once it reaches the end of the subroutine, it continues waiting for events, but the scope used for searching for event handlers is still in the subroutine, not the global scope. What this means is that branch labels in the main part of your program won't be found after a subroutine event handler executes. EDIT: Whoops, nevermind, Rod's example was able to point that out, and you posted your response as I was writing this
|
|
|
Post by wexhammer on Jan 12, 2020 5:54:28 GMT -5
Hello! Having understood how to create files and open them.... My code receive's an OS error when backing up one of my files. Does anyone know what the problem could be?
Open Default.dat enter some data then press backup, a prompt will appear asking you to enter the new file name then it should copy data to a new file. I am getting this error though.
open "default.dat" for output as #default close #default
[Initialize] Global hMain, hFind, incdupNum, incdupo, incaddName, increcordIndex, incinccontactCount Global incfilterCount, oldinctype$, openFlag Nomainwin Dim incomename$(10000), incomeSearch$(10000), incomedup$(500), invtype$(20), invstatus$(20) Dim invbuilder$(10000, 25), incexistInfo$(10,10), inchContents$(20), inv1$(20), inv2$(20)
incdupo=0 incaddName=1
Stylebits #main.memoinv, _WS_VSCROLL, _ES_AUTOHSCROLL, _ES_MULTILINE, 0 ' Stylebits #main, 0,_WS_MAXIMIZEBOX,0,0 WindowWidth = 495 '595 695 795 WindowHeight = 560 UpperLeftX=Int((DisplayWidth-WindowWidth)/2) UpperLeftY=Int((DisplayHeight-WindowHeight)/2) 'open the main window
Statictext #main.1inc, "Expenses", 10, 120, 60, 20 Listbox #main.invname, incomename$(, modifyInv, 10, 150, 170, 270 ' Statictext #main.inc, "Filter Contacts", 10, 170, 160, 20
Statictext #main.3inc, "Reference", 195, 150, 50, 20 Textbox #main.invtextboxname, 250, 150, 80, 25 Statictext #main.4inc, "Date", 195, 180, 50, 20 Textbox #main.invdate, 250, 180, 80, 25 Statictext #main.5inc, "Name", 195, 210, 50, 20 Textbox #main.invcost, 250, 210, 225, 25
Button #main.delinv, "Backup", [backup], UL, 120, 80, 40, 30 Button #main.newinv, "&New Record", addIncRecord, UL, 0, 80, 40, 30 Button #main.invfind "open", incloadNames, UL, 170, 80, 40, 30 Listbox #main.invdup, incomedup$(, incpick, 490, 10, 190, 395 Button #main.saveinv, "S&ave Record", acceptincEntry, UL, 40, 80, 40, 30 Open "Income" For Window As #main Print #main, "Trapclose endProgram"
Print #main.invname, "SingleClickSelect" Print #main.invdup, "SingleClickSelect" #main.saveinv "!disable" hMain=hwnd(#main)
[Code]
Print #main.invname, "Setfocus"
[invinputLoop] Wait
[acceptincEntry] Call acceptincEntry handle$ Wait
[addIncRecord] Call addIncRecord handle$ Wait
[incremoveEntry] call invremoveEntry wait
[backup]
prompt "Enter the name you want for your back up file"; newfilename$
open file$ for input as #currentbackup
open newfilename$;".dat" for output as #new
#new, input$(#currentbackup,lof(#currentbackup));
close #currentbackup close #new wait
[endProgram]
Call endProgram handle$ Wait
Sub endProgram handle$ if openFlag then close #current close #main end End Sub
Sub incloadNames handle$ '#main.invname "reload" #main.invname, "SelectIndex 0" if openFlag=2 then [continue]
reDim incomename$(10000) filedialog "Open Original file...","*.dat",file$
if file$="" then [incabort]
if openFlag then close #current
[continue]
reDim incomename$(10000)
Open file$ For Random As #current Len = 105
Field #current, 35 As incomename$, 35 As incdate$, 35 As invcost$
'if inc.dat doesn't exist, we will create it with 0 records If Eof(#current) <> 0 Then ' Close #current 'Close #currentCopy Call initializeincNames ' Goto [incskipIt] End If
'create a backup of the file each time we make a change Get #current, 1 ' Put #currentCopy, 1
incinccontactCount = Val(incomename$) If incinccontactCount = 0 Then ' Close #current 'Close #currentCopy ' Goto [incskipIt] openFlag=1 call populateinvList End If For index = 2 To incinccontactCount + 1 Gettrim #current, index Put #current, index incomename$(index - 1) = str$(index-1)+") "+incomename$ '#main.invname "reload" Next index ' #main.invname "reload" openFlag=1 #main.invname "reload" ' Goto [incskipIt]
#main.saveinv "!enable" [incabort]
call addIncRecord handle$ 'reDim incomename$(10000) '#main.invname "reload" End Sub
Sub initializeincNames 'create the data file with 0 records ' Open file$ For Random As #current Len = 16065 Field #current, 35 As incomename$, 35 As incdate$, 35 As invcost$ incomename$ = "0" Put #current, 1 '#main.invname "reload" ' Close #current End Sub
Sub loadInvFilter handle$ 'redim incomename$(10000) 'show only the records that match the filter Call addIncRecord handle$
' Open file$ For Random As #current Len = 16065 Field #current, 35 As incomename$, 35 As incdate$, 35 As invcost$ Get #current, 1 incinccontactCount = Val(incomename$) If incinccontactCount = 0 Then ' Close #current Goto [incmoveOn] End If 'compare stage to filter
' Close #current Print #main.invname, "Reload" [incmoveOn] End Sub
Sub modifyInv handle$ incaddName = 0
Print #main.invname, "Selection? selection$" If selection$ = "" Then [noincName]
Print #main.invname, "SelectionIndex? index" If index = 0 Then [noincName] 'This should never need to happen increcordIndex=val(selection$) [getinincomerecord] getIndex=increcordIndex+1 ' Open file$ For Random As #current Len = 16065 Field #current, 35 As incomename$, 35 As incdate$, 35 As invcost$ Gettrim #current, getIndex ' Close #current Print #main.invtextboxname, incomename$ Print #main.invdate, incdate$ Print #main.invcost, invcost$
oldinctype$=invtype$ [noincName] End Sub
Sub addIncRecord handle$ incaddName = 1 #main.invname, "SelectIndex 0" Print #main.invtextboxname, "" Print #main.invdate, "" Print #main.invcost, ""
' Print #main.memoinv, "" Print #main.invtextboxname, "!SetFocus" ' Print #main.invdate, "N/A" ' Print #main.modexpDate, "N/A" ' #main.invname, "Reload" End Sub
Sub acceptincEntry handle$ Print #main.invtextboxname, "!contents? incomename$"; If incomename$<>"" Then Print #main.invdate, "!contents? incdate$"; Print #main.invcost, "!contents? invcost$";
If incaddName = 1 Then incinccontactCount = incinccontactCount + 1 increcordIndex = incinccontactCount End If incomename$(increcordIndex) = Str$(increcordIndex)+") "+incomename$ print #main.invname, "Reload" date$=Date$() If oldinctype$="Opening Mailer" And invtype$="Follow Up Call" then incspare10$=Date$() End If [saveincome]
Field #current, 35 As incomename$, 35 As incdate$, 35 As invcost$ Put #current, increcordIndex + 1 ' Close #current If incaddName = 0 Then [invgoBack] ' Open file$ For Random As #current Len = 16065 Field #current, 35 As count$, 70 As fill$ count$ = Str$(incinccontactCount) Put #current, 1 ' Close #current incaddName = 0 Call loadInvFilter " " [invgoBack] Print #main.invname, "SelectIndex ";increcordIndex Call addIncRecord handle$ Else Notice "NO BUSINESS NAME"+Chr$(13)+"The business name must be entered, "_ +Chr$(13)+"before a record can be saved. " End If End Sub
Sub populateinvList
Get #current, 1 incinccontactCount = Val(incomename$) Put #current, 1
For index2 = 2 To incinccontactCount + 1 Gettrim #current, index2 For column=1 To 4 Select Case column Case 1 invbuilder$(index2, column)=incomename$ Case 2 invbuilder$(index2, column)=incdate$ Case 3 invbuilder$(index2, column)=invcost$ case 4 invbuilder$(index2, column)=date$
End Select Next column Next index2
End Sub
Sub saveinvoiceList Dim incomename$(10000)
For index2 = 2 To incinccontactCount + 1 For column=1 To 4 Select Case column Case 1 incomename$=invbuilder$(index2, column) Case 2 incdate$=invbuilder$(index2, column) Case 3 invcost$=invbuilder$(index2, column) case 4 date$=invbuilder$(index2, column)
End Select Next column Put #current, index2 Next index2
Close #current
End Sub
Function incexists(a$) Files DefaultDir$, a$, incexistInfo$() exists=val(incexistInfo$(0,0)) End Function
Sub invremoveEntry Print #main.invtypefilter, "selection? filter$" If incaddName=0 Then Confirm "YOU ARE ABOUT TO DELETE THIS RECORD"+Chr$(13)+" "+Chr$(13)+Chr$(34)_ +incomename$(increcordIndex)+Chr$(34)+Chr$(13)+" "+Chr$(13)+"Do you want to proceed?";delAns$ If Lower$(delAns$)="no" Then [noinvDelete] WindowWidth=150 WindowHeight=75 StaticText #invpatience, "PLEASE WAIT...", 10, 15, 100, 25 Open "DELETING...", For Dialog_Modal As #invpatience
' Open file$ For Random As #current Len = 16065 Field #current, 35 As incomename$, 35 As incdate$, 35 As invcost$,
For moveincRecords=increcordIndex+1 To incinccontactCount Get #current, moveincRecords+1 Put #current, moveincRecords Next moveincRecords
Get #current, 1 incomename$(Val(incomename$))="" incomename$=Str$(Val(incomename$)-1) Put #current, 1
' Close #current Close #invpatience openFlag = 1 Call incloadNamespass handle$ Call loadInvFilter handle$ Notice "RECORD DELETED"+Chr$(13)+"Names reloaded" Else Notice "NO RECORD SELECTED!"+Chr$(13)+"Please select a record," _ +Chr$(13)+"then select delete from the menu." End If
[noinvDelete] End Sub
Sub incpick handle$ Print #main.invdup, "Selection? duplicate$" locateRecord=Instr(duplicate$," @ ") recordNum=Val(Mid$(duplicate$,locateRecord+3)) Print #main.invname, "SelectIndex ";recordNum Print #main.invname, "SelectIndex 0" End Sub
sub incloadNamespass handle$
reDim incomename$(10000)
Field #current, 35 As incomename$, 35 As incdate$, 35 As invcost$
'if inc.dat doesn't exist, we will create it with 0 records If Eof(#current) <> 0 Then ' Close #current 'Close #currentCopy Call initializeincNames Goto [incskipIt] End If
'create a backup of the file each time we make a change Get #current, 1 ' Put #currentCopy, 1
incinccontactCount = Val(incomename$) If incinccontactCount = 0 Then ' Close #current 'Close #currentCopy Goto [incskipIt] openFlag=1 call populateinvList End If For index = 2 To incinccontactCount + 1 Gettrim #current, index Put #current, index incomename$(index - 1) = str$(index-1)+") "+incomename$
Next index
openFlag=1
' Goto [incskipIt]
'[incskipIt] [abortinc2] End Sub
|
|
|
Post by metro on Jan 12, 2020 6:32:49 GMT -5
I have never had a reason to use filedialog to save a file, all of my programs have hard coded paths , I open the file and print the info to it I' Guessing filedialog only gives you the path+filename you then have to create the code to put the info on disk. another option maybe to use Chris's code here libertybasiccom.proboards.com/thread/252/ooops-copying-folder-files-blogto select the file you want to copy the do just that copy it to a new location and or new name
Ooops wrong code sorry that's for a folder there is an API for a single file copy available though
I haven't read all of the prior responses above maybe you have been told how to save your data already brain fog at the moment.......
|
|