Author Topic: LookUp array ...hmm  (Read 3049 times)

0 Members and 2 Guests are viewing this topic.

Aurel

  • Guest
LookUp array ...hmm
« on: October 20, 2013, 12:20:23 PM »
Charles
This thing look very weird to me ,
Why variable id is not set by p in this simple function ???
Infact is it set but it looks that is not visible to outside print statment ??

Code: [Select]
string vList[65535]
int rList[65535]
int id

function Lookup(string k) as int
=====================================
int p,v,i
i = 65534
vList[i]="target"
rList[i] = 4
string s
DO
s=vList[p] 
 If s = k
      v = rList[p]
      id = p
      'print str(id) 7/ here is id 65534
      exit do
 End If
 
p=p+1
if p=65535 then exit do
END DO

Return v
end function

'but here is id set to null ??
print "Pos<ID>: " + str(id) +" " + Lookup("target")

Charles Pegge

  • Guest
Re: LookUp array ...hmm
« Reply #1 on: October 20, 2013, 01:26:34 PM »
This had me puzzled for a while :)

In the print expression:  id is evaluated before Lookup is executed, (to alter the value of id)

The prog also needs indexbase 0

Aurel

  • Guest
Re: LookUp array ...hmm
« Reply #2 on: October 21, 2013, 12:20:26 AM »
Hmm..
this way work...
but i suspect that something is wrong ,because other ways not work at all.. ???
Code: [Select]
'$ filename "lookup.exe"
'include "rtl32.inc"
'include "awinh.inc"
#lookahead
string vList[65535]
int rList[65535]
int id,res
'indexbase 1

res=LookUp("target")
string rs
rs=str(res)
'MsgBox(res,"ok")
print res + " " + str(id)


function Lookup(string k) as int
=====================================
int p,v
i = 65534
vList[i]="target"
rList[i] = 4
string s
DO
s=vList[p] 
 If s = k
      v = rList[p]
      id = p
      'print str(id)
      exit do
 End If
 
p=p+1
if p=65535 then exit do
END DO

Return v
end function



Charles Pegge

  • Guest
Re: LookUp array ...hmm
« Reply #3 on: October 21, 2013, 01:17:48 AM »
How about this one:

Code: [Select]
indexbase 0
#lookahead

'STORAGE
========

string vList[65535]
int    rList[65535]

'TEST DATA
==========
int i = 65534
vList[i]="target"
rList[i] = 4

'TEST LOOKUP
============
int res,id
res=LookUp("target",id)
print "res: " res  "  id: " id


function Lookup(string k,int*p) as int
======================================
p=0
do
  if k=vList[p]
    return rList[p]
 end If
 p=p+1
 if p=65535 then exit do
end do
end function

Simplified further:

Code: [Select]
function Lookup(string k,int*p) as int
======================================
for p=0 to 65535
  if k=vList[p]
    return rList[p]
  end if
next
end function
« Last Edit: October 21, 2013, 01:24:37 AM by Charles Pegge »

Aurel

  • Guest
Re: LookUp array ...hmm
« Reply #4 on: October 21, 2013, 03:15:29 AM »
Now work ,even without indexbase 0...
hmmm

but when i try with include file then not work
because i use MsgBox() functiom from awinh.inc...
well sometimes i am completely confused where to look...
ok.. ;)

Charles Pegge

  • Guest
Re: LookUp array ...hmm
« Reply #5 on: October 21, 2013, 10:43:57 AM »
Subtle but important correction to the right macro:


  macro right(s,i)
  mid(s,-(i))
  end macro

Aurel

  • Guest
Re: LookUp array ...hmm
« Reply #6 on: October 21, 2013, 11:02:08 AM »
thanks Charles
i know for that and i fix this...
I will compare my few programs with latest oxygen and with older release
just to see why some things not work as espected....
because something is not as it has to be .

Aurel

  • Guest
Re: LookUp array ...hmm
« Reply #7 on: October 21, 2013, 10:55:23 PM »
so i try with older oxygen.dll and yes ...
with this older version all my programs work without problems
so i will use this older version and wait for new release.
 :)

Charles Pegge

  • Guest
Re: LookUp array ...hmm
« Reply #8 on: October 22, 2013, 06:50:38 AM »
Hi Aurel, if you post your latest, I will try it with the Oxygen I am working on.

Aurel

  • Guest
Re: LookUp array ...hmm
« Reply #9 on: October 22, 2013, 09:24:42 AM »
Ok Charles
I will send you code there is no problem about that.
But just one thing...
error is the same as in some old versions of oxygen which point into
simple Tally function and is about comma inside Tally(src,",")
so here is well know tally...
Code: [Select]
FUNCTION Tally (string Main$,string Match$) As INT
'print "TALLY:" + main$
INT n
For n=1 TO 20:dPos[n]=0:Next n

    Dim i,j,q,mlen,matchlen As INT
Dim t$ As STRING
    mlen = Len(Main$)
    matchlen = Len(Match$)
    i = 1
    j = 0
    q = 0
    If (mlen = 0) Or (matchlen = 0)
        Return j
    End If
   
    do

t$ = Mid(Main$,i,matchlen)
If t$ = Chr(34) THEN q = q + 1
If q=2 THEN q = 0
        If t$ = Match$ And q=0
           j++
'mem del$ position
dpos[j]=i
  'j = j + 1
         
        End If

           i++
        If i > mlen then
           exit do
        End If
    End do
'tbreak:
    Return j
End FUNCTION


Compiler complain about this comma sign ,why?

then complain about MsgBox() function to...

Code: [Select]
'MsgBox--------------------------------
Function MsgBox (lpText AS STRING,lpCaption AS STRING) as INT
If lpCaption = "" then lpCaption="<MsgBox>"
Return MessageBox 0,lpText,lpCaption,0
End Function

Peter

  • Guest
Re: LookUp array ...hmm
« Reply #10 on: October 22, 2013, 10:41:44 AM »
Quote
then complain about MsgBox() function to...
Code: [Select]
Function MsgBox (sys hwnd, string lpText, lpCaption, sys flags) as INT
    If lpCaption = "" then lpCaption="<MsgBox>"
    Return MessageBox 0,lpText,lpCaption,0
End Function