Public function problem

lashman
04-19-2003, 06:12 AM
Hello

I was adding this function to a simple application. But I get compile error: Argument not optional when I try to run this function. I wrote this code fully working yesterday. But today I can't.

Public Function sok3(tal1 As Integer, tal2 As Integer, tal3 As Integer) As Boolean

If tal1 = 1 Then
sok3 = True
Exit Function

ElseIf tal2 = 2 Then
sok3 = True
Exit Function

ElseIf tal3 = 3 Then
sok 3 = True
Exit Function

Else
sok3 = False
End If
End Function


My code to run this function:

Private Sub cmd1_Click()
Dim t1 As Integer, t2 As Integer, t3 As Integer
Dim resultat As Integer, summa As Integer
t1 = txt1.Text
t2 = txt2.Text
t3 = txt3.Text
resultat = antpos3(t1, t2, t3)
summa = sum3(t1, t2, t3)
MsgBox "Antal positiva " & resultat, , "TEST"
MsgBox "Summa " & summa, , "TEST"
If sok3(t1, t2, t3) = True Then <------------------------
chk1.Value = Checked
Else
chk1.Value = Unchecked
End If

cmd1.Enabled = False
End Sub

What am I doing wrong here? How do I call this function and make it check if number 1 is in txt1.text textbox etc? It's also supposed to check chk1 checkbox when true.

Squirm
04-19-2003, 06:19 AM
Public Function sok3(tal1 As Integer, tal2 As Integer, tal3 As Integer) As Boolean
If tal1 = 1 Then
sok3 = True
ElseIf tal2 = 2 Then
sok3 = True
ElseIf tal3 = 3 Then
sok 3 = True '<--- this line is causing the error, remove the space: sok3
Else
sok3 = False
End If
End Function

lashman
04-19-2003, 06:25 AM
It works now! Thank you! ;-)

Squirm
04-19-2003, 06:32 AM
Hmm, I can't see where that error is coming from. Do you have other functions named tal1, tal2, tal3, t1, t2 or t3?

For your checkbox problem, you are almost there, but your code should read vbChecked and vbUnchecked. Also, add Option Explicit as the first line of code in your form. It will pick up any small mistakes such as this.

lashman
04-19-2003, 06:37 AM
It works now. I noticed that my code was different with that I posted. I had a end function line under Public Function sok3(tal1 As Integer, tal2 As Integer, tal3 As Integer) As Boolean.

I wrote this application yesterday night. I did not even see this line. Not even now when I posted my code here. Really strange.

Anyways. Thanks for your help! I should not really code late nights.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum