I was trying to make an function using vb. This function is to collect data for a report. Follows the example:
Public Function HeaderData() As String
Dim dados As String
dados = ""
If Not(frm.FormQuery.FieldByName("A").AsString = "S" And _
frm.FormQuery.FieldByName("B").AsString = "S" And _
frm.FormQuery.FieldByName("C").AsString = "S" And _
frm.FormQuery.FieldByName("D").AsString = "S") Then
dados = dados + "Type: "
If frm.FormQuery.FieldByName(A).AsString = "S" Then
dados = dados + "A"
End If
If frm.FormQuery.FieldByName(B).AsString = "S" Then
If frm.FormQuery.FieldByName(A).AsString = "S" Then
dados = dados + ", "
End If
dados = dados + "B"
End If
If frm.FormQuery.FieldByName(C).AsString = "S" Then
If frm.FormQuery.FieldByName(A).AsString = "S" Or _
frm.FormQuery.FieldByName(B).AsString = "S" Then
dados = dados + ", "
End If
dados = dados + "C"
End If
If frm.FormQuery.FieldByName(D).AsString = "S" Then
If frm.FormQuery.FieldByName(A).AsString = "S" Or _
frm.FormQuery.FieldByName(B).AsString = "S" Or _
frm.FormQuery.FieldByName(C).AsString = "S" Then
dados = dados + ", "
End If
dados = dados + "D"
End If
dados = dados + "; "
And this function causes the error: Expecting an existing scalar var.
I did other functions with the same purpose, with similar code, using the same variable to collect the data (dados) and did not cause the error. What could be happening?
Your logic doesn't make much sense. I highly suggest that you write just a few lines and debug. Make sure everything works properly and than write a few more lines. Writing to much at the beginning will cause trouble.