Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.1
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 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 May 3rd, 2004, 12:42 PM
Authorized User
 
Join Date: Dec 2003
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to DolphinBay
Default Using variables part of IF/Then outside of Block

Good afternoon,

Can someone please tell me how I could go about using variables declared within an If/Then statement outside of the block but in the same procedure. Example:

Public Sub Test()
If test = 1 Then
    Dim var As OleDBConnection
Else
    Dim var As sqlConnection
End If
End Sub

Thank you in advance.


Dolphin Bay, Inc. -- turning visions into eReality(tm) -- West Palm Beach, FL
Website Design, Internet Strategy, Search Engine Marketing

www.DolphinBay.biz
 
Old May 3rd, 2004, 12:55 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,101
Thanks: 0
Thanked 2 Times in 2 Posts
Default

If you dim them within the if statement then they are only valid within the if statement. That means you can't really do conditional dim's


Hal Levy
Web Developer, PDI Inc.

NOT a Wiley/Wrox Employee
 
Old May 5th, 2004, 08:53 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

...and in my opinion, this is somewhat bad form. I always stick to the rule of declaring my variables at the beginning of functions. This keeps them grouped and is MUCH easier to read later on when you are trying to find where the var is declared. If you only declare the object (but not instantiate it) you shouldn't suffer from too much of a performance hit.





Similar Threads
Thread Thread Starter Forum Replies Last Post
block my microsoft MunishBhatia ASP.NET 2.0 Professional 0 July 9th, 2007 08:25 AM
How to block downloading qazi_nomi Classic ASP Basics 2 July 25th, 2005 12:51 AM
Display Block : none.... I think nancy Javascript How-To 7 September 30th, 2004 10:46 AM
Block Table Cr0vaX Access VBA 5 June 11th, 2004 05:01 AM
New Kid on the Block Needs some help johnny1628 HTML Code Clinic 3 July 3rd, 2003 07:40 PM





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