Darn, why is this happening?
Blitz3D Forums/Blitz3D Beginners Area/Darn, why is this happening?
| ||
This must have a simple answer but I cannot find where the problem is: The parser function should return the values seperately exactly as they are in the string but instead it gives vastly inflated values. WTF? The parse function is from the code archieves: Test code: Graphics3D 800,600,32,2 SetBuffer BackBuffer() Include "parse.bb" SD$="-7.039824 0.000000 -12.134317 7.039824 0.000004 -12.134317 -7.039824 0.000000 12.134317 7.039824 0.000004 12.134317" Dim PARSERRETURN$(1) count=parser$(SD$) For i=1 To count myval#=parserreturn$(i) Print myval# Next Parse Function Function parser$(txt$) occurence = occurence(txt$," ") Dim parserreturn(occurence+1) For a = 1 To occurence Repeat b = b + 1 If Mid$(txt$, b, 1) <> " " c = c + Mid$(txt$, b, 1) Else endloop = 1 parserreturn(a) = c EndIf Until endloop = 1 endloop = 0 c = 0 Next b = b + 1 parserreturn(occurence+1) = Mid$(txt$, b) Return occurence+1 End Function ;simple occurence function, it finds all instances of one string in another ;txt$ is the string to find stuff in and txt2$ is the string to find in txt$ ;example: ;z = occurence("doremesofadole", "e") ;print z ;(and I dont know what the REAL music notes are :P) Function occurence(txt$, txt2$) offset = 1 occur = 0 Repeat If Instr(txt$, txt2$, offset) > 0 offset = Instr(txt$, txt2$, offset) + 1 occur = occur + 1 Else endloop = 1 EndIf Until endloop = 1 Return occur End Function Anyone? It must be something simple... Darkheart |
| ||
Hi, It was because the variable c in the parser function wasn't defined as a string variable. This works: Function parser$(txt$) occurence = occurence(txt$," ") Dim parserreturn(occurence+1) For a = 1 To occurence Repeat b = b + 1 If Mid$(txt$, b, 1) <> " " c$ = c + Mid$(txt$, b, 1) Else endloop = 1 parserreturn(a) = c EndIf Until endloop = 1 endloop = 0 c = "" Next b = b + 1 parserreturn(occurence+1) = Mid$(txt$, b) Return occurence+1 End FunctionFredborg |
| ||
Ah, thanks Fredborg I will see if I can get in touch with the original functions author to update it. Darkheart |
| ||
Be sure that the first time a variable is used you always give up the type of the var... Elseway it will always be seen as an integer... As you can see in Fredlogs example the first c is called as c$... Once that's done you don't have to use the $ anymore to tell Blitz since Blitz will memorize it... If you are not sure when c is used the first time, you could declare if first, then you are sure you'll never see any surprises... Like this... Function parser$(txt$) Local c$ occurence = occurence(txt$," ") Dim parserreturn(occurence+1) For a = 1 To occurence Repeat b = b + 1 If Mid$(txt$, b, 1) <> " " c = c + Mid$(txt$, b, 1) Else endloop = 1 parserreturn(a) = c EndIf Until endloop = 1 endloop = 0 c = "" Next b = b + 1 parserreturn(occurence+1) = Mid$(txt$, b) Return occurence+1 End Function Just always use the symbol in the first time you use a var, either when you use it for the first time or in a declaration with either "Global" or "Local".... |