CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com

# Thread: Omitting the argument in Function

1. Junior Member
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

If gLen > 0 Then
For i = 1 To gLen
If Slovo(gX, gY) = "." Then Exit For
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
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
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
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. ## Re: Omitting the argument in Function

Well have a look into Optional arguments :

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

3. Junior Member
Join Date
Jun 2013
Posts
14

## Re: Omitting the argument in Function

hahaha cool
I thank everyone and give up seeking help at the forum.

4. ## 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. Elite Member Power Poster
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()`

#### Posting Permissions

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