Click to See Complete Forum and Search --> : [RESOLVED] Type mismatch


Mybowlcut
August 7th, 2009, 04:01 AM
Hey. Not sure if this should go here, but I am getting this error from the code below:Script error detected at line 14.
Source line: If player_names(player_no) = "" Then
Description: Type mismatch: 'player_names'
<%

' Used to get an array of a specific teams players' atttributes (e.g. name, goals, points)
Function get_player_attributes(team_no, players_per_team, attribute_name)
Dim player_attributes()
ReDim player_attributes(players_per_team)
For player_no = 0 To players_per_team Step 1
player_attributes(player_no) = Request.form("team_" & team_no & "_player_" & player_no + 1 & "_" & attribute_name)
Next
get_players_attributes = player_attributes
End Function

' Validates a player's name.
Function validate_players_name(team_no, player_no, player_names)
If player_names(player_no) = "" Then
' Player name is blank.
Response.Write("Player #" & player_no + 1 & "'s name must not be blank.") %> <br/> <%
Else
' Only check if this name is a duplicate if it is not blank.
For dup_check_no = 0 To UBound(player_names)
' Check against all other names to see if this is a duplicate.
If player_no <> dup_check_no And player_names(player_no) = player_names(dup_check_no) Then
' Isn't checking an element against itself and elements are equal; is a duplicate.
Response.Write("Player #" & player_no + 1 & "'s name (" & _
player_names(player_no) & ") must be unique.") %> <br/> <%
' Only need to warn once.
Exit For
End If
Next
End If
End Function

' Validates a player's points.
Function validate_players_points(team_no, player_no, player_points)
If player_points = "" Then
Response.Write("Player #" & player_no + 1 & "'s points must not be blank.") %> <br/> <%
ElseIf Not IsNumeric(player_points) Then
' Only check if non-numeric if it is not blank.
Response.Write("Player #" & player_no + 1 & "'s points (" & _
player_points & ") must be a numeral.") %> <br/> <%
End If
End Function

' Validates a player's goals.
Function validate_player_goals(team_no, player_no, player_goals)
If player_goals = "" Then
Response.Write("Player #" & player_no + 1 & "'s goals must not be blank.") %> <br/> <%
ElseIf Not IsNumeric(player_goals) Then
' Only check if non-numeric if it is not blank.
Response.Write("Player #" & player_no + 1 & "'s goals (" & _
player_goals & ") must be a numeral.") %> <br/> <%
End If
End Function

Dim players_per_team
players_per_team = 22

' Validate team 1's players' attributes.

Dim team_1_player_names
team_1_player_names = get_player_attributes(1, players_per_team, "name")

Call validate_players_name(1, 0, team_1_player_names)

%>

I'm still learning asp/vbscript so I don't know why it's complaining.

Cheers.

HanneSThEGreaT
August 7th, 2009, 04:49 AM
Have you tried IsEmpty or IsNull as well ¿

Like :
If Not IsNull(player_names(player_no)) Then

Or :
If Not IsEmpty(player_names(player_no)) Then

Just an idea...

Mybowlcut
August 9th, 2009, 07:06 PM
Sorry for the late reply. I tried using IsEmpty and Not IsEmpty, but I still get the error:
Script error detected at line 14.
Source line: If IsEmpty(player_names(player_no)) Then
Description: Type mismatch: 'player_names'

I've asked my lecturer to help but he can't seem to find the problem at a quick glance.

Alsvha
August 10th, 2009, 03:07 AM
Is this classic ASP? Cause then you're properly in the wrong forum :)


If you debug your validate_players_name, can you see if it is indeed send in as an array?
What's the value of player_names before the if, how many elements does it contain?
The problem might be that the player_names(player_no) is not an array, or because what it returns isn't a string so you can't compare with "" and so on....

Mybowlcut
August 12th, 2009, 04:46 AM
Is this classic ASP? Cause then you're properly in the wrong forum :)


If you debug your validate_players_name, can you see if it is indeed send in as an array?
What's the value of player_names before the if, how many elements does it contain?
The problem might be that the player_names(player_no) is not an array, or because what it returns isn't a string so you can't compare with "" and so on....I guess it is "classic ASP", but I'm not sure because I have very limited experience with it.

' Used to get an array of a specific teams players' atttributes (e.g. name, goals, points)
Function get_player_attributes(team_no, players_per_team, attribute_name)
Dim player_attributes()
ReDim player_attributes(players_per_team)
For player_no = 0 To players_per_team Step 1
player_attributes(player_no) = Request.form("team_" & team_no & "_player_" & player_no + 1 & "_" & attribute_name)
Next
get_players_attributes = player_attributes
Response.Write("type: " & Typename(player_attributes)) %> <br> <%
Response.Write("ubound: " & Ubound(player_attributes)) %> <br> <%
For Each x in player_attributes
Response.Write(x) %> <br> <%
Next

Response.Write("type: " & Typename(get_players_attributes)) %> <br> <%
Response.Write("ubound: " & Ubound(get_players_attributes)) %> <br> <%
For Each x in get_players_attributes
Response.Write(x) %> <br> <%
Next
End Function
This prints out what I expected it should:
type: Variant()
ubound: 22
Blah
... etc
.. etc

type: Variant()
ubound: 22
Blah
.. etc


But then when I try to assign the array returned by the function to a variable, it says it's empty:
Dim team_1_player_names
team_1_player_names = get_player_attributes(1, players_per_team, "name")

Response.Write("type: " & Typename(team_1_player_names)) %> <br> <%
type: Empty

:thumbd:

Mybowlcut
August 12th, 2009, 04:52 AM
Great..

Function get_player_attributes(team_no, players_per_team, attribute_name)
' ...
get_players_attributes = player_attributes
End Function


I should mention at this point that I'm coding this with Editplus and thus have no debugger... I'm used to C++ where a stupidly simple mistake like this would have been picked up by the compiler straight away.

Alsvha
August 12th, 2009, 06:39 AM
Great..

Function get_player_attributes(team_no, players_per_team, attribute_name)
' ...
get_players_attributes = player_attributes
End Function


I should mention at this point that I'm coding this with Editplus and thus have no debugger... I'm used to C++ where a stupidly simple mistake like this would have been picked up by the compiler straight away.

Well, that's because - if I remember my classic ASP/VB script - correct, that it is legal/correct syntax in that language and a compiler wouldn't pick up on legal syntax.

Mybowlcut
August 13th, 2009, 04:32 AM
Well, that's because - if I remember my classic ASP/VB script - correct, that it is legal/correct syntax in that language and a compiler wouldn't pick up on legal syntax.Yeah I know it's legal - that was my point, although I should have phrased it better.