Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Urgent coding help? EO3\. VB6 Error that I dont think should be happening…


IFX
 Share

Recommended Posts

 So I have an urgent error. I am currently coding a Friend System, as a few of the more outspoken people on this forum may know. And for some reason some form of issue pops up that I have not encountered yet. 

I have a label that calls SendFriendReq, exactly how you would think it would (from frmMain):

private sub SendReq_Click()
Call SendFriendReq
End Sub

But for some reason it erors with the line "argument not optional" and hylights the code "Call SendFriendReq. The public sub (sendFriendReq) is in modClientTCP, and reads as follows:

Public Sub SendFriendReq(ByVal FriendMessage As String, ByVal FriendName As String, ByVal SenderUsername As String)

    FriendMessage = Trim$(frmMain.NameText.text)
    FriendName = Trim$(frmMain.MessageFriend.text)
    SenderUsername = Trim$(Options.Username)

    Set buffer = New clsBuffer
    buffer.WriteLong CFriendReqSend
    buffer.WriteString FriendName
    buffer.WriteString FriendMessage
    buffer.WriteString SenderUsername
    SendData buffer.ToArray()
    Set buffer = Nothing
End Sub

There might be some more Errors in this code then just what I have gotten to. But so far, this is what I have. Can anyone help me out? please?
Link to comment
Share on other sites

"argument not optional" gives away the problem. 

SendFriendReq is declared as follows: SendFriendReq(Byval String, Byval String, Byval String). When you call SendFriendReq from the method you aren't passing any arguments to the parameters. As soon as you provide them, VB6 will compile. 

You may also want to call SendFriendReq with no requirement for an argument in other words, pass the arguments only if the callers wants to. In this case add the optional keyword before the parameter declaration. For instance in this case: 

```
SendFriendReq(Optional ByVal FriendMessage As String = "DefaultValue", Optional ByVal FriendName As String = "DefaultValue", Optional ByVal SenderUsername As String = "DefaultValue")

```
In this case your code would still compile even if you don't pass any arguments. Be warned though that optional parameters can only be declared after all the non-optional parameters have been declared. So, if you have an optional byval in between to normal byvals it won't work.
Link to comment
Share on other sites

> So I copied and pasted your code and it crapped out on "optional" "expected expression"

I suggest that you understand how it works rather than just copy pasting it. 

```
SendFriendReq(Optional ByVal FriendMessage As String = "DefaultValue", Optional ByVal FriendName As String = "DefaultValue", Optional ByVal SenderUsername As String = "DefaultValue")

```
This is isn't a method declaration. It's just the name of the methods along with the parameters involved. Copy pasting this into VB6 won't work because VB6 doesn't know what do with it. Declare it as a method by using Private/Public Sub/Function
Link to comment
Share on other sites

> I suggest that you understand how it works rather than just copy pasting it. 
>
> ```
> SendFriendReq(Optional ByVal FriendMessage As String = "DefaultValue", Optional ByVal FriendName As String = "DefaultValue", Optional ByVal SenderUsername As String = "DefaultValue")
>
> ```
> This is isn't a method declaration. It's just the name of the methods along with the parameters involved. Copy pasting this into VB6 won't work because VB6 doesn't know what do with it. Declare it as a method by using Private/Public Sub/Function

Could you possibly explain this a little bit more? i am rather new to vb.

PFFFFFFFFFFFFFFFFFFFFFFFFFT I GET IT NOW!

I understand what I did wrong. Thank you for your marvelous help. Now I have another issue for another post. (*nervous laughter*)
Link to comment
Share on other sites

> Could you possibly explain this a little bit more? i am rather new to vb.
>
> PFFFFFFFFFFFFFFFFFFFFFFFFFT I GET IT NOW!
>
> I understand what I did wrong. Thank you for your marvelous help. Now I have another issue for another post. (*nervous laughter*)

Glad that you figured it out. 

Btw: Googling the error description you had "Arguments not optional" would've helped you faster.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...