Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 6th, 2012, 10:55 PM
Authorized User
 
Join Date: Feb 2006
Posts: 21
Thanks: 0
Thanked 1 Time in 1 Post
Default VB Annoyances

Annoyance1)
Code:
If objReferrence IsNotNothingAndAlsoNotString.IsNullOrEmpty(objReferrence.value) Then
Why not define a Shared property in a module?
Code:
PublicModuleModuleIs1
'verify reference points to an object, and it's value is valid
  PublicReadOnlyProperty IsProperObjectAndValue(objReferrence AsObject) AsBoolean
   Get
     Return objReferrence IsNotNothingAndAlsoNotString.IsNullOrEmpty(objReferrence.value)
   EndGet
 EndProperty
  o   o   o
EndModule
then use the following line instead:
Code:
If IsProperObjectAndValue(objReferrence) Then
Willl this not be more readable?
2) I have tried to do the same for IsPostBack, as follows:
Code:
PublicReadOnlyProperty IsFirstPageRequest AsBoolean
 Get
   ReturnNotPage.IsPostBack
 EndGet
EndProperty
NOTE: the expression in red causes an error.
Any suggestions to correcting the problem?
Thanks,
Michael Kaftor
 
Old August 7th, 2012, 03:51 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Re 1: yes, you could if you wanted to, although you probably want to type the objReference parameter as a string.


Re 2: "the expression in red causes an error" is a bit vague. What error do you get and when? Where did you try this code? In the Module? If so, it makes sense as the module doesn't have access to the Page instance.

I would probably implement this as an extension method on the Page class, or not implement this at all as IsPostBack is, once you get the hang of it, just the reverse of IsFirstPageRequest ;-)

If you post code, can you please paste it in Notepad first to remove color coding and then use the forum editor's Code toolbar button to wrap your code in code tags. Otherwise, this forum messes up the code.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old August 11th, 2012, 06:46 PM
Authorized User
 
Join Date: Feb 2006
Posts: 21
Thanks: 0
Thanked 1 Time in 1 Post
Default VB Annoyances

Thanks for all your help. This was exactly what the doctor ordered and I was not aware of this language feature. As you said, after a while one gets the hang of it, except at debug time -- that I need to pay extra attention to the statement;
Here is the code that does the trick:
Code:
Imports Microsoft.VisualBasic
Imports System.Runtime.CompilerServices
 
Public Module ModuleExtensions
   'Is initial page request (v. IsPostBack)
   <Extension()>
   Public Function IsInitialRequest(ByRef aPage As Page) As Boolean
      Return Not aPage.IsPostBack
   End Function
 
End Module
The Following User Says Thank You to mkaftor For This Useful Post:
Imar (August 12th, 2012)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Running a VB 2005 exe file on a system without VB dilionyi Pro Visual Basic 2005 3 September 21st, 2009 07:37 PM
VB.NET 2003 Appendix B convert to VB 2008 Express Edition brucechess BOOK: Beginning VB.NET Databases 10 February 5th, 2009 12:52 PM
How do I write this vb 6 code to work in vb 2008? sanderson Visual Basic 2008 Essentials 3 June 10th, 2008 01:46 PM
Converting the DTS file execution from vb to vb . ankur.nagdeve .NET Framework 2.0 0 February 27th, 2008 05:12 AM
VB.Net/VB/Access97/Access2002 Comparison doveb VB.NET 4 October 10th, 2003 09:54 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.