CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2013
    Posts
    14

    Omitting the argument in Function

    I have a Function:

    Private Function GetMask(gX As Integer, gY As Integer, gDirect As Integer, gLen As Integer) As String

    GetMask = ""

    If gLen > 0 Then
    For i = 1 To gLen
    If Slovo(gX, gY) = "." Then Exit For
    GetMask = GetMask & Slovo.S(gX, gY)
    gX = gX + dX(gDirect)
    gY = gY + dY(gDirect)
    Next
    Else
    For i = 1 To 1000
    If gX > Grid.Width Or gY > Grid.Height Or gX < 1 Or gY < 1 Or Slovo.S(gX, gY) = "." Then Exit For
    GetMask = GetMask & Slovo.S(gX, gY)
    gX = gX + sx(gDirect)
    gY = gY + dY(gDirect)
    Next
    End If

    End Function

    1. Can Function to change, so you can omit argunent glen when calling functions when we do not need. I am in this case wrote glen = 0

    2. Can you make a function so that it returns a string array?
    I would actually be:

    Dim ii, jj
    For gDirect = 1 To 8
    GetMask(gDirect) = ""
    ii = gY
    jj = gY
    For i = 1 To 1000
    If ii > Grid.Width Or jj > Grid.Height Or ii < 1 Or jj < 1 Or Slovo.S(ii, jj) = "." Then Exit For
    GetMask(gDirect) = GetMask(gDirect) & Slovo.S(ii, jj)
    gX = gX + sx(gDirect)
    gY = gY + dY(gDirect)
    Next
    Next

    Then the function would have no arguments gDirect and Glen

    Or to put Public GetMask (8), so do not do Function. but do Sub?

    And finally, can function as we've written do simpler?

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Omitting the argument in Function

    Well have a look into Optional arguments :

    http://msdn.microsoft.com/en-us/library/f25e2b6b.aspx

  3. #3
    Join Date
    Jun 2013
    Posts
    14

    Re: Omitting the argument in Function

    hahaha cool
    Nothing I have not found there, from what I asked.
    I thank everyone and give up seeking help at the forum.

  4. #4
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Omitting the argument in Function

    What do you mean you found nothing there? i am really disappointed at your response :sad: really, really disappointed and majorly confused. flabbergasted.

    Sometimes I wonder why I even bother to help!

  5. #5
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Omitting the argument in Function

    Yeah that is rather odd.

    The Optional arguments is the solution to the first question. The second question is just a matter of changing the return of the function

    Code:
    Public MYFunction(SomeParam As String) as String()
    Always use [code][/code] tags when posting code.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured