![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 | |
|
Newbie
|
i have one if and i am wanting to insert multiple thens how could i go about doing this?
For Example Quote:
__________________
http://img137.imageshack.us/img137/6162/fredsig6gs.png |
|
|
|
|
|
|
#2 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Investigate elses and elseifs. Otherwise you sound like a teen girl: She goes, then I go, then she goes, then I go....
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#3 |
|
Programmer
|
There's also "And" is there not? So, you could do "If <condition> Then <some code> And <Some more code>".
So, your code would look like this (just an example) - Private Sub Cmd.Start_Click() If Combo.Text = 1 Then MsgBox Text1.Text And MsgBox Text2.Text End Sub If I am wrong, somebody correct me, as I cannot test this... my Visual Basic 2005 program will not work properly. Everytime I open it, it crashes when I try to do a few things. |
|
|
|
|
|
#4 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Okay. That's not correct. "And" is a logical function which makes it part of the expression being dealt with in evaluating the THEN, not a separate path of execution. Here's an actual example:
If name = "" Then
result = MsgBox(" Name required for replace operation ", , "Error")
ElseIf oldRow <> newRow Then
result = MsgBox(" Name and row don't agree " + Chr(13) + " Clear the row number ", vbOKOnly, "Problem With Find")
Else:
For counter = 1 To 13
If counter <> 55 Then
Set curCell = Worksheets("Sheet1").Cells(counter, 2)
myVal = curCell.Value
Set curCell = Worksheets("Sheet1").Cells(newRow, counter)
curCell.Value = myVal
End If
Next counter
End If
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#5 |
|
Hobbyist Programmer
Join Date: Oct 2005
Posts: 134
Rep Power: 3
![]() |
Instead of "AND", you can use a semicolon (:) to seperate statements on the same line of a single line IF-THEN statement (didn't know that until a minute ago). Example:
If Combo.Text = 1 Then statement1: statement2 |
|
|
|
|
|
#6 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
That has nothing to do with the question. AND is not a statement separator. AND cannot be replaced with a semicolon. Separating statements on one line is not the same thing as instituting a conditional, alternate path of execution.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#7 | |
|
Hobbyist Programmer
Join Date: Oct 2005
Posts: 134
Rep Power: 3
![]() |
Quote:
|
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|