IFX Posted February 24, 2015 Author Share Posted February 24, 2015 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 SendFriendReqEnd SubBut 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 = NothingEnd SubThere 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 More sharing options...
abhi2011 Posted February 24, 2015 Share Posted February 24, 2015 "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 More sharing options...
IFX Posted February 24, 2015 Author Share Posted February 24, 2015 > Abhi stuffThank you! you are pretty awesome. Link to comment Share on other sites More sharing options...
abhi2011 Posted February 24, 2015 Share Posted February 24, 2015 I'm guessing the problem is now solved. Please kindly tag this as solved by editing the main post in the full editor :) Link to comment Share on other sites More sharing options...
IFX Posted February 24, 2015 Author Share Posted February 24, 2015 > Abhi stuff.So I copied and pasted your code and it crapped out on "optional" "expected expression" Link to comment Share on other sites More sharing options...
abhi2011 Posted February 24, 2015 Share Posted February 24, 2015 > 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 More sharing options...
IFX Posted February 24, 2015 Author Share Posted February 24, 2015 > 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/FunctionCould 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 More sharing options...
abhi2011 Posted February 24, 2015 Share Posted February 24, 2015 > 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 More sharing options...
IFX Posted February 24, 2015 Author Share Posted February 24, 2015 > ABHI STUFFSI didn't realize that vb6 was used anymore outside of eclipse. It is kind of… dated. I figured that here would be a better more viable resource then most. Link to comment Share on other sites More sharing options...
abhi2011 Posted February 24, 2015 Share Posted February 24, 2015 VB6 isn't used much but VBA is still. And there are a lot of forums other here where both VBA and VB6 is/were being discussed. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now