View previous topic :: View next topic |
Author |
Message |
Serge Professional Member


Joined: 04 Mar 2002 Posts: 1480 Location: Australia
|
Posted: Fri Apr 25, 2003 11:49 pm Post subject: error sub routine |
|
|
hi all,
i have put together an error subroutine that i will be using with all my programs...the idea of this subroutine is when a user comes across an error, instead of the usual ERROR whatever AT LINE whatever, the user now has a way to let me know of the error + some basic information about his computer and his settings
i have included things like date and time separator as they can be problem with vds code if not done properly, and i have included the decimal point for the same reason
feel free to change it to suit you and to add or delete things if you to
Code: |
:error_sub
DIALOG CREATE,%%title Error,30,30,400,375,NOSYS,ONTOP
DIALOG ADD,LIST,error_list,5,5,390,320,
list loadtext, error_list
"This program has come across an error.
"
"To make it easy for you to report this error
"to the author, information about the error
"and about your computer have been put
"together in this list which has been
"saved on your desktop as a file: error.txt
"
"If you are happy with the contents of this
"list, please send the error file to the
"author at your@email.address
"
list add,error_list, Program Information
list add,error_list, ===================
list add,error_list, Title: %%title
list add,error_list, Version: %%version
list add,error_list, Date: %%date
list add,error_list,
list add,error_list, Error Details
list add,error_list, =============
list add,error_list,Error Number: @error(e)
list add,error_list,Line Number: @error(n)
list add,error_list,
list add,error_list, Regional Settings
list add,error_list, =================
%%locale = @regread(curuser,Control Panel\International,Locale)
if @equal(@len(%%locale),3)
%%locale = 00000%%locale
end
if @equal(@len(%%locale),4)
%%locale = 0000%%locale
end
list add,error_list,Language: @regread(local,System\CurrentControlSet\Control\Nls\Locale,%%locale)
list add,error_list,Locale: @regread(local,System\CurrentControlSet\Control\timezoneinformation,standardname)
list add,error_list,
list add,error_list, Hardware Specifications
list add,error_list, =======================
list add,error_list,CPU (make): @lower(@regread(local,Hardware\Description\System\CentralProcessor\0,VendorIdentifier))
list add,error_list,CPU (type): @lower(@regread(local,Hardware\Description\System\CentralProcessor\0,Identifier))
list add,error_list,
list add,error_list, Monitor: @sysinfo(screenwidth)x@sysinfo(screenheight)x@sysinfo(pixperin)
list add,error_list,
%%free_memory = @format(@fdiv(@sysinfo(freemem),1024),3.1)Mb
%%free_HD = @volinfo(%%local_hd,f)
if @greater(%%free_HD,1024)
if @greater(%%free_HD,1048576)
%%free_HD = @format(@fdiv(@fdiv(%%free_HD,1024),1024),3.1)Gb
else
%%free_HD = @format(@fdiv(%%free_HD,1024),3.1)Mb
end
else
%%free_HD = %%free_HD Kb
end
%%HD = @volinfo(%%local_hd,s)
if @greater(%%HD,1024)
if @greater(%%HD,1048576)
%%HD = @format(@fdiv(@fdiv(%%HD,1024),1024),3.1)Gb
else
%%HD = @format(@fdiv(%%HD,1024),3.1)Mb
end
else
%%HD = %%HD Kb
end
list add,error_list,Memory (free physical): %%free_memory
%a = @regread(stats,perfstats\statdata,vmm\cpglocked)
gosub compute
list add,error_list,
list add,error_list,Hard Disk (free): %%free_HD
list add,error_list,Hard Disk (total): %%HD
list add,error_list,Fat Type: @lower(@volinfo(@windir(),y))
list add,error_list,
%a = @regread(stats,perfstats\statdata,vmm\cpgswapfile)
gosub compute
list add, error_list,Swap File (size): @format(@fdiv(%a,1048572),2.1)MB
%a = @regread(stats,perfstats\statdata,vmm\cpgswapfileinuse)
gosub compute
list add, error_list,Swap File (in use): @format(@fdiv(%a,1048572),2.1)MB
list add,error_list,
list add,error_list, Windows Information
list add,error_list, ===================
list add,error_list,Version: @regread(local,software\microsoft\windows\currentversion,versionnumber)@regread(local,software\microsoft\windows\currentversion,subversionnumber)
list add,error_list,Windows Folder: @lower(@windir())
list add,error_list,
list add,error_list, Date and Time
list add,error_list, =============
list add,error_list, Current Date: @datetime(dddd dd mmmm yyyy)
list add,error_list, Current Time: @datetime(tt)
list add,error_list, Date Separator: @datetime(/)
list add,error_list, Time Separator: @datetime(:)
list add,error_list,
list add,error_list, Other
list add,error_list, =====
list add,error_list, Decimal Point: @fdiv(1,2)
list savefile, error_list, @windir()\desktop\error.txt
DIALOG ADD,BUTTON,child_ok,335,140,110,30,OK
window position, %%title Error, @div(@diff(@sysinfo(screenheight),380),2), @div(@diff(@sysinfo(screenwidth),400),2)
DIALOG SHOWMODAL
dialog close
%%dummy = @event()
%%event =
stop
:COMPUTE
list create, 14
%b = @len(%a)
%c = 2
repeat
%d = @substr(%a,%c,%c)
if @equal(%d,"|")
list add, 14, @diff(%c,1)
end
%c = @succ(%c)
until @equal(%c,%b)
list seek, 14, 0
%i = @next(14)
%1 = @substr(%a,1,%i)
%j = @next(14)
%2 = @substr(%a,@sum(%i,2),%j)
%k = @next(14)
%3 = @substr(%a,@sum(%j,2),%k)
%4 = @substr(%a,@sum(%k,2),%b)
%a = @sum(@sum(@sum(%1,@prod(256,%2)),@prod(65536,%3)),@prod(16777216,%4))
list clear, 14
list close, 14
exit |
note that it is desgined to work with win 95/98/me because of the registry settings it accesses
note also, this comment is for the newbies, that you will need to include the following code near the start of your code
Code: | option errortrap, error_sub |
Serge _________________
|
|
Back to top |
|
 |
Hortalonus Valued Contributor


Joined: 15 Mar 2002 Posts: 344 Location: Western USA
|
Posted: Sat Apr 26, 2003 4:29 pm Post subject: |
|
|
Nice Serge! Your's is quite a bit more comprehensive than my standard error routine. One thing I do find helpful sometimes is to know what the last event was. I keep track of it with %%event = @EVENT() in my event loop.
Thanks for sharing! _________________ "ah, come take my hand... we're ridin' out tonight to face the promised land"
Get a free iPod mp3 player... |
|
Back to top |
|
 |
FreezingFire Admin Team

Joined: 23 Jun 2002 Posts: 3508
|
Posted: Sat Apr 26, 2003 4:32 pm Post subject: |
|
|
Yes, I agree!  _________________ FreezingFire
VDSWORLD.com
Site Admin Team |
|
Back to top |
|
 |
Serge Professional Member


Joined: 04 Mar 2002 Posts: 1480 Location: Australia
|
Posted: Sun Apr 27, 2003 1:17 am Post subject: |
|
|
thanks hortalonus and freezingfire,
feel free to amend the code to include the last event...beta testing garrett's snipbar, i noticed that he includes the last event as well in his error sub-routine...
can i ask why the last event is important given that once you know the error line number, then you know exactly where the problem is...and if it is in a subroutine then you would know by default what event was generated for the user to end up there or how the program got you there...
Serge _________________
|
|
Back to top |
|
 |
FreezingFire Admin Team

Joined: 23 Jun 2002 Posts: 3508
|
Posted: Sun Apr 27, 2003 1:54 pm Post subject: |
|
|
Serge wrote: | can i ask why the last event is important given that once you know the error line number, then you know exactly where the problem is...and if it is in a subroutine then you would know by default what event was generated for the user to end up there or how the program got you there... |
Sometimes crazy things happen with even the smallest error in the code
and you could end up at a label which you weren't supposed to be at.
I think that the more information the better and easier it is to fix a bug.
Keep in mind that you're going to want to re-create the bug before you
attempt to fix it.  _________________ FreezingFire
VDSWORLD.com
Site Admin Team |
|
Back to top |
|
 |
Hortalonus Valued Contributor


Joined: 15 Mar 2002 Posts: 344 Location: Western USA
|
Posted: Sun Apr 27, 2003 5:40 pm Post subject: |
|
|
FreezingFire wrote: | Sometimes crazy things happen with even the smallest error in the code and you could end up at a label which you weren't supposed to be at... |
Exactly... something as simple as leaving an END off of an IF statment can do this. You'll get the line number of the error but there will be no real error in that section of code. If you know that the last event takes you to a section of code that doesn't reference the section where the error occured, then you know to look in the section where the last event should take you. Does that make sense, Serge?  _________________ "ah, come take my hand... we're ridin' out tonight to face the promised land"
Get a free iPod mp3 player... |
|
Back to top |
|
 |
Serge Professional Member


Joined: 04 Mar 2002 Posts: 1480 Location: Australia
|
Posted: Mon Apr 28, 2003 8:43 am Post subject: |
|
|
i do understand ff and hortalonus...thanks
Serge _________________
|
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|