Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > another stupid question - if then/click statements


Reply
 
Thread Tools Display Modes
  #1  
Old 07-16-2003, 04:17 PM
stephenlecompte's Avatar
stephenlecompte stephenlecompte is offline
Contributor
 
Join Date: Apr 2003
Location: Houston, TX
Posts: 456
Default another stupid question - if then/click statements


Observe the following: I have two objects - a control button with the name Command1 and a text box named txtBox.

Private Sub Command1_Click()

Dim A As Integer
Dim B As Integer
Dim C As Integer

If txtBox.Text = "" Then A = 0:txtBox.SetFocus

A = 1
B = 2
C = 3

End Sub

My problem with the above is that if there is nothing in the txtBox I don't want A=1, B=2, C=3. I want it to skip it without using the command ELSE!!!!
Because the above is just an example of something larger. I have about 30 code IF/THEN statements where A=1, B=2, C=3 are! Any ideas as to as to what is best is appreciated always!

Thanks,

Stephen
Reply With Quote
  #2  
Old 07-16-2003, 04:26 PM
Legend Legend is offline
Contributor
 
Join Date: Dec 2002
Posts: 542
Default

I'm not sure what you are trying to achieve - what's wrong with using Else?

Are all the if/thens for different textboxes? If you have lots of textboxes with similar code, why not just create a control array of textboxes, and code it once?
Reply With Quote
  #3  
Old 07-16-2003, 04:31 PM
00100b's Avatar
00100b 00100b is offline
Martian In Disguise

Retired Moderator
* Guru *
 
Join Date: May 2003
Location: Minneapolis, MN
Posts: 9,566
Default

The best way is to use the full "If Then...ElseIf...Else...End If" construct, but if you are set on this method then:

Code:
Private Sub Command1_Click() Dim A As Integer Dim B As Integer Dim C As Integer If txtBox.Text = "" Then A = 0: txtBox.SetFocus: Exit Sub A = 1 B = 2 C = 3 End Sub
Or if you have some other code below and before the End Sub, then place a line label and issue a GoTo.
Code:
Private Sub Command1_Click() Dim A As Integer Dim B As Integer Dim C As Integer If txtBox.Text = "" Then A = 0: txtBox.SetFocus: GoTo Resume_Here A = 1 B = 2 C = 3 Resume_Here: ' Do some other stuff End Sub
Reply With Quote
  #4  
Old 07-16-2003, 04:51 PM
stephenlecompte's Avatar
stephenlecompte stephenlecompte is offline
Contributor
 
Join Date: Apr 2003
Location: Houston, TX
Posts: 456
Default Thanks centurion

Thanks for the help.

The A=1, B=2, C=3 represents multiple IF/THEN statements that based on data entry in several text boxes & check boxes would make certain fields visible or invisible to the users based on the options. Some text boxes in groups would be different in value than others even tho they are all in arrays.

The Exit Sub tip and Resume_Here really work well.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
stupid range refernce question Goku Excel 3 10-28-2003 01:26 PM
Stupid Question Goku Word, PowerPoint, Outlook, and Other Office Products 5 10-11-2002 07:14 AM
Stupid question philipeskenazi Database and Reporting 2 03-20-2001 12:54 PM
Was my 11/22/00 10:15AM question stupid? MarkABrown General 4 11-28-2000 12:14 PM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->