CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Nov 2006
    Location
    Australia
    Posts
    1,569

    [RESOLVED] Type mismatch

    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'
    Code:
    <%
    
    ' 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.
    Good judgment is gained from experience. Experience is gained from bad judgment.
    Cosy Little Game | SDL | GM script | VLD | Syntax Hlt | Can you help me with my homework assignment?

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Type mismatch

    Have you tried IsEmpty or IsNull as well &#191;

    Like :
    PHP Code:
    If Not IsNull(player_names(player_no))  Then 
    Or :
    PHP Code:
    If Not IsEmpty(player_names(player_no))  Then 
    Just an idea...

  3. #3
    Join Date
    Nov 2006
    Location
    Australia
    Posts
    1,569

    Re: Type mismatch

    Sorry for the late reply. I tried using IsEmpty and Not IsEmpty, but I still get the error:
    Code:
    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.
    Good judgment is gained from experience. Experience is gained from bad judgment.
    Cosy Little Game | SDL | GM script | VLD | Syntax Hlt | Can you help me with my homework assignment?

  4. #4
    Join Date
    Feb 2005
    Location
    Denmark
    Posts
    742

    Re: Type mismatch

    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....
    Last edited by Alsvha; August 10th, 2009 at 03:16 AM.

  5. #5
    Join Date
    Nov 2006
    Location
    Australia
    Posts
    1,569

    Re: Type mismatch

    Quote Originally Posted by Alsvha View Post
    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.

    Code:
    ' 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:
    Code:
    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
    Good judgment is gained from experience. Experience is gained from bad judgment.
    Cosy Little Game | SDL | GM script | VLD | Syntax Hlt | Can you help me with my homework assignment?

  6. #6
    Join Date
    Nov 2006
    Location
    Australia
    Posts
    1,569

    Re: Type mismatch

    Great..

    Code:
    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.
    Last edited by Mybowlcut; August 12th, 2009 at 05:04 AM.
    Good judgment is gained from experience. Experience is gained from bad judgment.
    Cosy Little Game | SDL | GM script | VLD | Syntax Hlt | Can you help me with my homework assignment?

  7. #7
    Join Date
    Feb 2005
    Location
    Denmark
    Posts
    742

    Re: Type mismatch

    Quote Originally Posted by Mybowlcut View Post
    Great..

    Code:
    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.

  8. #8
    Join Date
    Nov 2006
    Location
    Australia
    Posts
    1,569

    Re: Type mismatch

    Quote Originally Posted by Alsvha View Post
    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.
    Good judgment is gained from experience. Experience is gained from bad judgment.
    Cosy Little Game | SDL | GM script | VLD | Syntax Hlt | Can you help me with my homework assignment?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured