Jumat, 24 Juli 2015

RE: [MS_AccessPros] Re: What does the colon do in the ELSE: statement?

I like using the colon as way to replace single lines with multiple lines.

For example, I once took over someone else's work, and with 25+ RunSQL statements in a sub, I was able to time them by replacing them all with

I=I+1 : debupg.print I & vbtab & "started" & now : docmd.runsql stsql : debug.print I & vbtab & "finished" & vbtab & now


So I get into my debug window which ones are taking long.


Steve Conklin




________________________________
> To: MS_Access_Professionals@yahoogroups.com
> From: MS_Access_Professionals@yahoogroups.com
> Date: Fri, 24 Jul 2015 09:29:28 -0700
> Subject: RE: [MS_AccessPros] Re: What does the colon do in the ELSE:
> statement?
>
>
>
> Bob - It's a non-nonsensical example made worse by being syntactically
> incorrect to start with.But my example is correct and will compile as
> it should.
>
> While multiple statement lines are out of the ordinary, they are used
> from time to time. It's a matter of style. I tend to use them in If
> blocks if the Else line is short. Offhand, I can't think of any other
> place I'd use them.
>
> Then there is the one-line If statement:
> If suit = spades Then MsgBox "I win!"
>
> No End If needed.
> Another funny thing about VBA, you can type endif and the editor will
> fix it for you.
>
> -Bill
>
>
> ---In MS_Access_Professionals@yahoogroups.com,
> <bob.phillips@dsl.pipex.com> wrote :
>
>
> Surely, it should be
>
>
>
>
>
> If 1> 4 Then
>
> MsgBox "1 is greater than 4"
>
> Else
>
> MsgBox "1 is less than 4"
>
> End If
>
>
>
> Or even
>
>
>
> MsgBox "1 is " & IIf(1> 4, "greater", "less") & " than 4"
>
>
>
> Multiple statement lines just don't feel right to me.
>
>
>
> From: MS_Access_Professionals@yahoogroups.com
> [mailto:MS_Access_Professionals@yahoogroups.com]
> Sent: 24 July 2015 16:24
> To: MS_Access_Professionals@yahoogroups.com
> Subject: [MS_AccessPros] Re: What does the colon do in the ELSE: statement?
>
>
>
>
>
> Phucon
>
>
>
> As per Duane's explanation, the code should have been written:
>
>
>
> If 1> 4 Then
>
> MsgBox "1 is greater than 4"
>
> Else: MsgBox "1 is less than 4"
>
> End If
>
>
>
> Regards,
>
> Bill Mosca, Founder - MS_Access_Professionals
>
> http://www.thatlldoit.com
>
> Microsoft Office Access MVP
>
> https://mvp.support.microsoft.com/profile=C4D9F5E7-BB03-4291-B816-64270730881E
>
> My nothing-to-do-with-Access blog
>
> http://wrmosca.wordpress.com
>
>
>
>
> ---In
> MS_Access_Professionals@yahoogroups.com<mailto:MS_Access_Professionals@yahoogroups.com>,
> <duanehookom@hotmail.com<mailto:duanehookom@hotmail.com>> wrote :
>
> I found this while searching the web
> http://stackoverflow.com/questions/7649101/excel-vba-pound-and-colon-signs-meaning
>
> "The colon (:) is a statement delimiter. It would be equivalent to a
> new line in VBA, or a semicolon in C (just to quote a random example).
> It allows you to write several instructions on a single line rather
> than going to a new line each time."
>
> Since your example code has not instruction on the same line after
> the ":" it serves no purpose.
>
> Duane Hookom, MVP
> MS Access
>
>
> ________________________________
>
> To:
> MS_Access_Professionals@yahoogroups.com<mailto:MS_Access_Professionals@yahoogroups.com>
> From:
> MS_Access_Professionals@yahoogroups.com<mailto:MS_Access_Professionals@yahoogroups.com>
> Date: Thu, 23 Jul 2015 08:21:06 -0700
> Subject: [MS_AccessPros] What does the colon do in the ELSE: statement?
>
>
>
>
> Hello
>
> I am trying to understand the "ELSE:". Why is the colon necessary? What
> does it do there?
>
> Thank you
>
> Phucon
>
> Sub IF_ELSEIF_FUNCTION()
> If 1> 4 Then
> MsgBox "1 is greater than 4"
> Else:
> MsgBox "1 is less than 4"
> End If
> End Sub
>
>
>
>
>
>
>
>

------------------------------------

------------------------------------


------------------------------------

Yahoo Groups Links

<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/MS_Access_Professionals/

<*> Your email settings:
Individual Email | Traditional

<*> To change settings online go to:
http://groups.yahoo.com/group/MS_Access_Professionals/join
(Yahoo! ID required)

<*> To change settings via email:
MS_Access_Professionals-digest@yahoogroups.com
MS_Access_Professionals-fullfeatured@yahoogroups.com

<*> To unsubscribe from this group, send an email to:
MS_Access_Professionals-unsubscribe@yahoogroups.com

<*> Your use of Yahoo Groups is subject to:
https://info.yahoo.com/legal/us/yahoo/utos/terms/

Tidak ada komentar:

Posting Komentar