
-----------------------------------
r0ssar00
Mon Feb 20, 2006 11:19 am

string manipulation and arrays
-----------------------------------
i have a function (already written)nameTag(data:string,part:int):int that returns a piece of data in the form of f_$tag or t_$tag or /f_$tag or /t_$tag where $tag can change and the function that calls this function manipulates that string.  my problem is i hit the error "right bound of substring is greater than length of string" the two erroring lines are indicated with comments

    var debug:boolean:=true
    fcn classData (dataVar : string) : string
        var tmp : array 1 .. 3 of string % where 1 is opentag, 2 is data, and 3 is closing tag
        tmp (1) := nameTag (dataVar, 1)
        tmp (2) := nameTag (dataVar, 2)
        tmp (3) := nameTag (dataVar, 3)
        if debug then
            for i : 1 .. 3
                put tmp (i)
            end for
        end if
        var openTagTest, closeTagTest : string
        openTagTest := tmp (1) (1 .. 2) % error #1
        if openTagTest = "f_" then
            result "ofile"
        elsif openTagTest = "t_" then
            result "otree"
        else
            closeTagTest := tmp (3) (1 .. 3) % error #2 (same error as #1)
            if openTagTest = "/f_" then
                result "cfile"
            elsif openTagTest = "/t_" then
                result "ctree"
            else
                result Errors (1)
            end if
        end if
        %put openTagTest
        %put closeTagTest
    end classData

any help would be appreciated

-----------------------------------
Cervantes
Mon Feb 20, 2006 7:20 pm


-----------------------------------
Something is wrong.  You say nameTag returns an integer, and yet the code you show us treats it as returning a string.  I'll assume it's a typo, and it returns a string.

nameTag (dataVar, 1) is returning a string of length more than 2.
nameTag (dataVar, 3) is returning a string of length more than 3.

I can't say more without knowing what dataVar is, or the nameTag function.

-----------------------------------
r0ssar00
Tue Feb 21, 2006 11:31 am


-----------------------------------
it was a typo
dataVar is the input to a the function which determines from dataVar if it should be labeled fileopen,fileclose,diropen,dirclose
nameTag (dataVar, 1) where dataVar is "test string 1
would return "f_test"
nameTag (dataVar, 2) where dataVar is "test string 1
would return "test string 1"
nameTag (dataVar, 3) where dataVar is "test string 1
would return "/f_test"
this allows me to figure out what the first and last parts are going to be
problem is, which i figured out with some puts, is that nameTag is returning "", not "f_trest"
i guess that means you need the nameTag code so here it is

    fcn nameTag (raw : string, data : int) : string
        var tmpString : string := ""
        var tmpInt : int := 0
        % lets find out how many spaces are before the start of the real data
        loop
            tmpInt += 1
            exit when raw (tmpInt) not= " "
        end loop
        % lets eliminate the whitespace from the string
        for i : tmpInt .. length (raw)
            tmpString := tmpString + raw (i)
        end for
        var tmp2String : string
        % lets remove the tags from the string
        tmp2String := tmpString (2 .. * -1)
        % now we determine what to return: 1 for opentag, 2 for data, 3 for closetag
        if data = 1 then
            if debug then
                put processName.returnFirst (tmp2String, ">")
            end if
            result processName.returnFirst (tmp2String, ">")
        elsif data = 2 then
            if debug then
                put processName.returnMiddle (tmp2String, ">", "", "")
        end if
        result tmpString (index (tmpString, "") - 1) % processName.returnFirst (tmp2String, ">")processName.returnFirst (tmp2String, ">")
    elsif data = 2 then
        if debug then
            put "dg2" % processName.returnFirst (tmp2String, ">")processName.returnMiddle (tmp2String, ">", "") + 1 .. index (tmp2String, "")processName.returnMiddle (tmp2String, ">", "")processName.returnLast (tmp2String, "")processName.returnLast (tmp2String, "")
            end if
            result processName.returnFirst (tmp2String, ">")
        elsif data = 2 then
            if debug then
                put processName.returnMiddle (tmp2String, ">", "", "=2"
        put "returnMiddle: returns the middle word, same limitations +         usage.  Must have # of words =2"
        put "returnLast: returns the last word, same limiations + usage.               Must have # of words >=2"
        put "press any key to continue"
        var test : string (1)
        getch (test)
        Window.SetActive (currentwin)
        Window.Select (currentwin2)
        Window.Close (win)
    end help
end processName

ha, beat that upload script! you cant fubar this!
neways, thanks

-----------------------------------
Andy
Thu Mar 23, 2006 9:55 am


-----------------------------------
done, done and done  :)

-----------------------------------
r0ssar00
Tue Apr 04, 2006 10:38 am


-----------------------------------
thanks
i still need some help with this though, if anybody would wish to join me in my quest to make a xml access library, feel free to pm me

-----------------------------------
Cervantes
Tue Apr 04, 2006 9:27 pm


-----------------------------------
im sorry, i have to say it, and no insult intended, but cervantes:are you thick? if you bothered to read _everything_ in both of my posts with code, you would find all the answers you are looking for.  read from top to bottom, and then ask an intelligent question *please*, it will save us both time
i already gave an example for dataVar, tmp is an array, look at the nameTag funtion for what it _should_ equal
cervantes, read _all_ of the code i have posted, everything you need is right there
Hmm, I didn't notice this when it was first posted. It's long since passed, so I'll speak (sort of) generally.

If you're asking others for help, it's a good idea to present all the information you think they'll need, and then some more. Those who help shouldn't have to read it scrupulously just to offer help. You're making it hard for people to help you. You talk as though I'm looking for answers in your code and that I should be asking the questions. Gah?

Anyways, if I remember correctly, I was looking for the exact string you were passing that it failed on, not any odd string. (These could be the same.) I was also looking for whether your function actually correctly did what you said it did.


Perhaps he was so stressed about which one of his 8K+ scholarships he should accept that he skipped a few words... 

10K scholarship from Queen's, today! And 3K bursary money for Eng / 1K bursary for Science! :)
