Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
arrays
#1
gintaras could you please some me some array string examples ?

i don't get it from the help.

in ppro i use (copy and paste):

Code:
Copy      Help
local sel fname drive mode
drive = arg(1)
v = vec.create(10,50)
v[1]= "open"
v[2]= "Öffnen"
v[3]= "Import"
v[4]= "Anderes Symbol"
v[5]= "Select Icon"

for (i=0;i<vec.length(v);i=i+1)
    line = vec.get(v,i)
       if (caption == line) do
        mode = 0
        break
    else
        mode = 1
       endif
endfor
vec.destroy(v)
qm.macro("show_it_ginti", mode)
the variable caption in caption == line is getwintext(anything)

function show_it_ginti :
Code:
Copy      Help
function %i
mes i
pi
#2
;tranlated to qm:

Code:
Copy      Help
int mode i
int hwnd=win
;______________________________

;version 1 (dynamic str array)
str caption.getwintext(hwnd)
str* v=calloc(10 sizeof(str))
v[0]= "open"
v[1]= "Öffnen"
v[2]= "Import"
v[3]= "Anderes Symbol"
v[4]= "Select Icon"

mode=1
for(i 0 10) if(caption~v[i]) mode=0; break
out mode

for(i 0 10) v[i].all
free v
;______________________________

;version 2 (static str array)
type STR10 ~s[10]
STR10 vv
vv[0]= "open"
vv[1]= "Öffnen"
vv[2]= "Import"
vv[3]= "Anderes Symbol"
vv[4]= "Select Icon"

mode=1
for(i 0 10) if(caption~vv[i]) mode=0; break
out mode
;______________________________

;version 3
str windowlist="open[]Öffnen[]Import[]Anderes Symbol[]Select Icon" ;;or .getmacro("list") or .getfile("list.txt")
mode=1
if(wintest(hwnd windowlist "" "" 16|1|2)) mode=0
out mode
#3
SA_Alloc
Code:
Copy      Help
;/
function# numelem

;Creates dynamic str array

;EXAMPLE: see function StringToArray


ret calloc(numelem sizeof(str))

SA_Realloc
Code:
Copy      Help
;/
function# str*a numelem

;Resizes dynamic str array


dll msvcrt memset !*dest c count

if(!a) ret calloc(numelem sizeof(str))

int i lena(SA_Len(a)) diff(numelem-lena)

if(diff>0) ;;grow
,a=realloc(a numelem*sizeof(str))
,memset(a+(lena*sizeof(str)) 0 diff*sizeof(str))
else if(diff<0) ;;shrink
,for(i numelem lena) a[i].all
,a=realloc(a numelem*sizeof(str))

ret a

SA_Free
Code:
Copy      Help
;/
function# str*a

;Frees dynamic str array

if(!a) ret

int i
for(i 0 SA_Len(a)) a[i].all
free a

SA_Len
Code:
Copy      Help
;/
function# str*a

;Returns number of elements in dynamic str array

dll# msvcrt _msize !*v

if(a) ret _msize(a)/sizeof(str)

_____________________

StringToArray
Code:
Copy      Help
;/
function# $s [$delim] [flags]

;Parses string s and returns str array.
;Arguments same as for str.gett()

;EXAMPLE
;str s = "one two three four five six seven eight nine ten eleven twelve"
;
;str* a=StringToArray(s)
;
;int i
;for(i 0 SA_Len(a)) out a[i]
;
;a=SA_Free(a)


int i na=10
str* a=SA_Alloc(na)

for i 0 1000000000
,if(i=na) na+na; a=SA_Realloc(a na)
,if(a[i].gett(s -i delim flags)<0) break

ret SA_Realloc(a i)


Forum Jump:


Users browsing this thread: 1 Guest(s)