Author Topic: Check Paper/Model Space  (Read 1345 times)

0 Members and 1 Guest are viewing this topic.

Offline rom1

  • Visual Basic
  • *
  • Posts: 21
  • Karma: +3/-0
  • Gender: Male
    • prefered language: VB
    • Prog expertise: Good
    • View Profile
Check Paper/Model Space
« on: November 18, 2010, 10:40:12 AM »
Hi,

My 1st little contribution

A function to check which of Paper/Model Space is active:

Code: [Select]

    Function F_TestPaperSpace() As Boolean

        If LayoutManager.Current.CurrentLayout = "Model" Then
            F_TestPaperSpace = False
        Else
            F_TestPaperSpace = True
        End If
    End Function

target audience:{beginner}
« Last Edit: November 21, 2010, 05:42:34 PM by Patriiick »

Offline (gile)

  • C#
  • *
  • Posts: 87
  • Karma: +8/-0
  • Gender: Male
    • prefered language: F
    • Prog expertise: Good
    • View Profile
Re: Check Paper/Model Space
« Reply #1 on: November 19, 2010, 04:44:27 PM »
Hi,

As the function returns a Boolean, IMO there's no need for an If ... Then ... Else statement.
Don't make VB more verbose than it is  :clinoeil:

C#
Code: [Select]
private bool F_TestPaperSpace()
{
    return LayoutManager.Current.CurrentLayout != "Model";
}

VB
Code: [Select]
Private Function F_TestPaperSpace() As Boolean
Return LayoutManager.Current.CurrentLayout <> "Model"
End Function

Offline Patriiick

  • Administrator
  • *****
  • Posts: 130
  • Karma: +1/-0
  • Gender: Male
    • prefered language: VB
    • Prog expertise: Good
    • View Profile
  • Twitter: @Patriiick
Re: Check Paper/Model Space
« Reply #2 on: November 19, 2010, 05:59:35 PM »
True that VB is verbose!  :clinoeil:
Thanks for shortening the code, by the way, trying to make a function as short as possible is a useful and exciting exercice... when it's not at the expense of clarity. Here it is not.

Offline (gile)

  • C#
  • *
  • Posts: 87
  • Karma: +8/-0
  • Gender: Male
    • prefered language: F
    • Prog expertise: Good
    • View Profile
Re: Check Paper/Model Space
« Reply #3 on: November 19, 2010, 07:08:18 PM »
Talking about short code, I forgot to post a F# example
Code: [Select]
let F_TestPaperSpace() =
    LayoutManager.Current.CurrentLayout <> "Model"

Offline rom1

  • Visual Basic
  • *
  • Posts: 21
  • Karma: +3/-0
  • Gender: Male
    • prefered language: VB
    • Prog expertise: Good
    • View Profile
Re: Check Paper/Model Space
« Reply #4 on: November 23, 2010, 07:50:32 AM »

Thanks for this advice :clinoeil:, we don't think enough to that way of coding when we come from vba...

Also, in my case, i used an 'if ... else' statement because i had some other instructions into the false statement.