Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Operands of Set Operators must be sets?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Insectoid




PostPosted: Fri Jul 04, 2008 9:06 am   Post subject: Operands of Set Operators must be sets?

Erm, what does this mean? I get it when comparing a string to a part of a record that is a string.

I am trying to make a database & search engine because I thought it would be fun. But I ran into a snag, as pointed out above. Here is my code so far (will be changing it to read stuff from a file later)

Turing:

var num_entries := 1
var search_by : string
var unitname : string
var foc : string
type unit_data :
    record
        name : string
        nick_name : string
        army : string
        foc_slot : string
        pointCost : int
        unit_type : string
        ws : int
        bs : int
        strength : int
        toughness : int
        wounds : int
        initiative : int
        attacks : int
        leadership : int
        save : int
    end record

var units : array 1 .. num_entries of unit_data

units (1).name := "Fire_Warrior_team"
units (1).nick_name := "Shas'La"
units (1).foc_slot := "Troops"
units (1).pointCost := 10
units (1).unit_type := "Infantry"
units (1).ws := 2
units (1).bs := 3
units (1).strength := 3
units (1).toughness := 3
units (1).wounds := 1
units (1).initiative := 2
units (1).attacks := 1
units (1).leadership := 7
units (1).save := 4

proc search_by_name (search : string)
    for check : 1 .. num_entries
        if unitname in units (check).name then
            put units (check).name
        end if
    end for
end search_by_name






put "Enter characteristic to search by:"
get search_by

if search_by = "Name" then
    put "Enter part of the unit's name"
    get unitname
    search_by_name (unitname)
end if
Sponsor
Sponsor
Sponsor
sponsor
[Gandalf]




PostPosted: Fri Jul 04, 2008 9:29 am   Post subject: RE:Operands of Set Operators must be sets?

You're trying to use the in operator on a record (or actually, something even more misplaced, a string) when it only works on sets. You're basically using the in operator in a way it shouldn't be used, and for something it doesn't do.

If I'm correct in assuming what you're looking for:
code:
if index (units (check).name, search) ~= 0 then
    put units (check).name
end if

Should be the conditional statement. Note that this also takes care of another problem with your code... You're always checking for unitname in your procedure, which ruins the purpose of passing search as a parameter in the first place.
Insectoid




PostPosted: Fri Jul 04, 2008 10:13 am   Post subject: RE:Operands of Set Operators must be sets?

Quote:

You're trying to use the in operator on a record (or actually, something even more misplaced, a string) when it only works on sets. You're basically using the in operator in a way it shouldn't be used, and for something it doesn't do.


I was actually trying to make it work for any string, so I wouldn't have to write a separate procedure for every search type, and forgot to change it back afterwords.


I thought the 'in' operator was for strings...oops, thinking the wrong language, maybe that's for python...

code:

if index (units (check).name, search) ~= 0 then
    put units (check).name
end if


Will this work for partial matches or only perfect matches?
[Gandalf]




PostPosted: Fri Jul 04, 2008 10:51 am   Post subject: Re: RE:Operands of Set Operators must be sets?

insectoid @ 2008-07-04, 10:13 am wrote:

code:

if index (units (check).name, search) ~= 0 then
    put units (check).name
end if


Will this work for partial matches or only perfect matches?

It'll work for partial matches. That's the reason index() was used, instead of just checking for equality.
Insectoid




PostPosted: Fri Jul 04, 2008 9:09 pm   Post subject: RE:Operands of Set Operators must be sets?

Oh, thank you, will use!
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: