Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 13th, 2006, 9:22 PM   #1
FredVietnam
Newbie
 
Join Date: Feb 2006
Location: Northern Kentucky
Posts: 9
Rep Power: 0 FredVietnam is on a distinguished road
Send a message via AIM to FredVietnam Send a message via MSN to FredVietnam
Question Multiple Thens

i have one if and i am wanting to insert multiple thens how could i go about doing this?

For Example

Quote:
Private Sub Cmd.Start_Click()

If Combo.Text = 1 Then MsgBox Text1.Text

End Sub
how would i add more thens to this one IF ?
FredVietnam is offline   Reply With Quote
Old Feb 13th, 2006, 10:12 PM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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
DaWei is offline   Reply With Quote
Old Feb 13th, 2006, 11:26 PM   #3
MrMan9879
Programmer
 
MrMan9879's Avatar
 
Join Date: Sep 2005
Location: Nanaimo, BC, Canada
Posts: 97
Rep Power: 0 MrMan9879 is an unknown quantity at this point
Send a message via MSN to MrMan9879
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.
MrMan9879 is offline   Reply With Quote
Old Feb 14th, 2006, 7:42 AM   #4
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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
DaWei is offline   Reply With Quote
Old Feb 14th, 2006, 12:51 PM   #5
Kaja Fumei
Hobbyist Programmer
 
Join Date: Oct 2005
Posts: 134
Rep Power: 3 Kaja Fumei is on a distinguished road
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
Kaja Fumei is offline   Reply With Quote
Old Feb 14th, 2006, 1:09 PM   #6
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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
DaWei is offline   Reply With Quote
Old Feb 14th, 2006, 1:26 PM   #7
Kaja Fumei
Hobbyist Programmer
 
Join Date: Oct 2005
Posts: 134
Rep Power: 3 Kaja Fumei is on a distinguished road
Quote:
Originally Posted by DaWei
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.
I'm sorry it came out sounding it was a replacement for AND or that AND was a statement seperator. I know neither is true. What I meant to say was it was a way to seperate statement on a single line if-then. Apparaently, I misinterpreted the original question as "how do i add more lines to inside a THEN?" and not "how do i add more cases/conditionals/alternate paths of execution?"
Kaja Fumei is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

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 On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:28 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC