Need Help using VBScript

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
djDeeJay_dot_com
Newbie
Posts: 14
Joined: Fri Aug 20, 2010 9:08 am

Need Help using VBScript

Post by djDeeJay_dot_com » Fri Aug 27, 2010 12:24 pm

Hello

i tried to use VBscript in a macroscript

its primitive and easy but i get type mismacht errors all the time and dont know why, can somebody help me out with that?

if i debug(stepping withF8) the code it makes a difference if i start on the line VBStart or after VBEnd (line 46)
if i start on VBStart the first VBEval fails
if i start on line 46 the first runs but the second fails

i commented out the complet code in the second sub so the error mus be from the way i call but what do i wrong ?

here is the code:
[code]
//Set IGNORESPACES to 1 to force script interpreter to ignore spaces.
//If using IGNORESPACES quote strings in {" ... "}
//Let>IGNORESPACES=1

VBSTART

Dim gamefield()
Sub init_gamefield()
ReDim gamefield(9, 7,1)
End Sub
Sub set_gamefield(x, y, value1, value2)
' gamefield(x, y, 0) = CStr(value1)
'gamefield(x, y, 1) = CStr(value2)
End Sub
Function get_gamefield(x, y)
get_gamefield = gamefield(x, y, 0 ) + "_" + gamefield(x, y, 1 )
End Function

Function CBin (Number)
Dim Temp
Temp = 1
cbin="00000"
Do Until Temp > Number 'sets starting point for Len
Temp = Temp * 2
Loop
Do Until Temp = Temp Then
cbin = cbin + "1"
Number = Number - Temp
Else
cbin = cbin + "0"
End If
Temp = Temp / 2
Loop 'Loop until string is complete

End Function


VBEND


vbeval>init_gamefield,vbresult
VBEval>set_gamefield(1,1,"0000","0100"),vbresult


[/code]

i am getting crazy with this spending now 3 days without results

please help me with this

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Fri Aug 27, 2010 1:07 pm

Your issue is you are using VBEval> to call a Sub which is wrong, because VBEval is expecting to get a return value from a Function.

Change to VBRun> and it runs without error.

Code: Select all

VBRun>init_gamefield,vbresult
VBRun>set_gamefield(1,1,"0000","0100"),vbresult


djDeeJay_dot_com
Newbie
Posts: 14
Joined: Fri Aug 20, 2010 9:08 am

Post by djDeeJay_dot_com » Fri Aug 27, 2010 5:03 pm

Thanks a lot i didn´t have seen that
changed them to function works fine, now i have the next problem :
i have this function:
[code]
VBSTART
DIM gamefield(9,7,1)
function set_gamefield(x, y, value1, value2)
gamefield(x, y, 0) = cstr(value1)
gamefield(x, y, 1) = cstr(value2)
set_gamefield=gamefield(x, y, 0 ) + "_" + gamefield(x, y, 1 )
End function
VBEND
[/code]

if i call the function
VBEval>set_gamefield(%X%,%Y%,"0000","0100"),vbresult
everything is perfect vbresult contains 0000_0100
if i call
(%pattern% is 0000_1111)
VBEval>set_gamefield(1,%yi%,left("%pattern%",4),right("%pattern%",4)),vbresult

everything is perfect vbresult contains 0000_1111

but if i call
( %FE2COMP% = 1111 and %FT2COMP% = 0110)
VBEval>set_gamefield(%xi%,%yi%,"%FE2COMP%","%FT2COMP%"),value

i get value = %FE2COMP%_%FT2COMP%

if i do the call without quoting the strings (what is wrong as i think?)
i get an error invalid character VBScrpt:1032
UPDATE:
i see in the watchwindow the right values for this variables
%FE2COMP% and %FT2COMP%
but when i show them at this line of code with MDL> it seems they ARE GONE (mdl displays me %FE2COMP%) not 0010 or something similar what is shown in the watchwindow????


how and why variables r unbound ?

strange







[quote="adroege"]Your issue is you are using VBEval> to call a Sub which is wrong, because VBEval is expecting to get a return value from a Function.

Change to VBRun> and it runs without error.


[code]
VBRun>init_gamefield,vbresult
VBRun>set_gamefield(1,1,"0000","0100"),vbresult

[/code][/quote]

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Fri Aug 27, 2010 5:33 pm

This works fine for me in version 12.0.6

Code: Select all


VBSTART
DIM gamefield(9,7,1)
function set_gamefield(x, y, value1, value2)
   gamefield(x, y, 0) = cstr(value1)
   gamefield(x, y, 1) = cstr(value2)
   set_gamefield=gamefield(x, y, 0 ) + "_" + gamefield(x, y, 1 )
End function
VBEND

Let>xi=1
Let>yi=0
Let>FE2COMP=1111
Let>FT2COMP=0110
VBEval>set_gamefield(%xi%,%yi%,"%FE2COMP%","%FT2COMP%"),rval
MessageModal>rval
Thanks a lot i didn´t have seen that changed them to function works fine,
Why change them to a function? They don't return anything. Leave them as a Sub and just use VBRun> to execute. Less overhead that way.

djDeeJay_dot_com
Newbie
Posts: 14
Joined: Fri Aug 20, 2010 9:08 am

Post by djDeeJay_dot_com » Fri Aug 27, 2010 7:06 pm

this simple example for me too ;o)
but fact is that in a bigger loop the values got lost and i cant find how and why, i do NOT overwrite or touch the variables in between and the watchlist shows good results but mdl> didnt and the vbeval also gets wrong values
i did a workaround coping them to another vaariable and use that but...

it seems that intensive debugging for every small pice of code is really time
to post the code here i will try be switching off all FIP statements because u dont have all the bitmaps and when i can then reproduce the error i post it

UPDATE HERE IS THE CODE WITHOUT FIP wich reproduces the error:
run it with 12.0.5e until the breakpoint and look in the watchlist for
%FE2COMP% and %FT2COMP%
u will see there values for them

step to the mdl>and u will see they have no value, they r treated as strings

this behaivor i descripted already some days ago when a case like that caused me overwriting 2 with 3 and totally silly arithmetical behaivor.

cheers
dj

[code]
VBSTART

Dim gamefield()
function init_gamefield()
ReDim gamefield(9, 7,1)
End function
function set_gamefield(x, y, value1, value2)
gamefield(x, y, 0) = cstr(value1)
gamefield(x, y, 1) = cstr(value2)
set_gamefield=gamefield(x, y, 0 ) + "_" + gamefield(x, y, 1 )
End function
Function get_gamefield(x, y)
get_gamefield = gamefield(x, y, 0 ) + "_" + gamefield(x, y, 1 )
End Function
Function debug_gamefield()
dim x,y
dim result
reult = ""
for y = 0 to 7
for x = 0 to 9
result = result+" " + gamefield(x, y, 0 ) + "_" + gamefield(x, y, 1 )
next
result=result+chr(13)+chr(10)
next
debug_gamefield=MsgBox(result,0,"Hello World")
End Function

Function CBin (Number)
Dim Temp
Temp = 1
cbin="00000"
Do Until Temp > Number 'sets starting point for Len
Temp = Temp * 2
Loop
Do Until Temp = Temp Then
cbin = cbin + "1"
Number = Number - Temp
Else
cbin = cbin + "0"
End If
Temp = Temp / 2
Loop 'Loop until string is complete

End Function
VBEND


vbeval>init_gamefield,vbresult
VBEval>set_gamefield(1,1,"0000","0100"),vbresult



//Set IGNORESPACES to 1 to force script interpreter to ignore spaces.
//If using IGNORESPACES quote strings in {" ... "}
let>IGNORSPACES=1
'Let>VAREXPLICIT=1
ASS>screentoproofstart,isassigned
if>%isassigned%=FALSE,setname,skipname
label>setname
let>screentoproofstart=C:\deejaysfolder\tropicana\captures\nemo_start_466427.bmp
let>screentoproofoffen=C:\deejaysfolder\tropicana\captures\nemo_offen_466427.bmp
label>skipname
'search bottom left corne of an image that is close to x0,y0
'FindImagePos>C:\deejaysfolder\tropicana\nemo_find_maze_x0_y0.bmp,%screentoproofstart%,20,3,XArr,YArr,NumFound
'if we cannot find this position then we better do nothing
let>NumFound=1
let>XArr_0=0
let>YArr_0=0
if>NumFound>0

let XStart=%XArr_0%+30
let YStart=%YArr_0%+30
'Alle karten aufdecken
'MouseMove>%XStart%,%XStart%
'LClick
let>y=0
repeat>y
let>x=0
repeat>x
' rand des spiels markieren, hier muessen dannn noch ein und ausgang wieder freigemacht werden
if>{(%x% = 0) OR (%y% = 0) OR (%x% = 9) OR (%y% = 7) }
VBEval>set_gamefield(%X%,%Y%,"0000","0100"),vbresult
let>gamefield[%x%,%y%]=%vbresult%
else
'mit nichts belegen am anfang (sonderzeichen 0000 hat keine eingange ist aber verschiebbar = 0110)
VBEval>set_gamefield(%x%,%y%,"0000","0110"),vbresult
let>gamefield[%x%,%y%]=%vbresult%
let>xy={%XStart% + ( %x% -1) *60}
let>yy={%YStart% + ( %y% -1) *60}

'MouseMove>xy,yy
' LClick
'wait>1
endif
let>x=%x%+1
Until>x>9
let>y=%y%+1
Until>y>7

' here we will find out the configuration of the actual maze
'were is start? coded as 0100_0100 (exit to the left not movable)
' we do this now in finding the first blocked part (fieldelement) because that more is accurate as i found out

'find the first (blocked!) part this ist the direction were nemo will start
'there are three possiblities: 1001 1010 and 0011 so make it quick and dirty
let>i=0
repeat>i
if>i=0
let>pattern=1001_0100
else
if>i=1
let>pattern=0101_0100
else
if>i=2
let>pattern=0011_0100
endif
endif
endif
'FindImagePos>C:\deejaysfolder\tropicana\nemo_fe\nemo_fe_%pattern%.bmp,%screentoproofstart%,20,1,FE2CmpX,FE2CmpY,FE2CmpC
let>FE2CmpC=1
let>FE2CmpY_0=150
if>%FE2CmpC%>0
'let>Xi=1
'mdl>%pattern%
'vbeval>msgbox("%pattern%",0,"hello"),vbresult
let>Yi={((%FE2CmpY_0% - %YStart%) div 60)+1}
VBEval>set_gamefield(1,%yi%,left("%pattern%",4),right("%pattern%",4)),vbresult
let>gamefield[1,%yi%]=%vbresult%

'eingang ins spiel setzen
if>GAMEFIELD[0,%Yi%]=0000_0100
VBEval>set_gamefield(0,%yi%,"0100","0100"),vbresult
let>gamefield[0,%yi%]=%vbresult%

endif
endif
add>i,1
Until>i>2




'where is the goal coded as 0001_0100 (entry from the right not movable)

'FindImagePos>C:\deejaysfolder\tropicana\nemo_ziel.bmp,%screentoproofstart%,20,1,ZielXArr,ZielYArr,ZielNumFound
let>zielNumFound=1
let>ZielYArr_0=90
if>%zielNumFound%>0
let>Xi=9
'{((%ZielXArr_0% - %XStart%) div 60)+2}
let>Yi={((%ZielYArr_0% - %YStart%) div 60)+1}
VBEval>set_gamefield(0,%yi%,"0001","0100"),vbresult
let>gamefield[0,%yi%]=%vbresult%

endif
'
'now its time to search all fields we can use
'where are the deadly traps (sharks) and where are the fieldelements (streets)
'we r using a loop for k from (0000) 0101 (5) to 1100 (12) and j = 0101 to 1111 to avoid writing this code multiple times
'there r some fields(bitcombiantions not used but then Findfilepos returns -1 and we r fine with this
let>k=0

repeat>k
let>j=4
' get the bit representation
vbeval>right(Cbin(%k%),4),%FE2COMP%
if>k=0
' for the shark there is only one FT (011
let>maxj=4
else
let>maxj=15
endif
if>{(%K%=0) or (%K%=3) or (%K%=6) or (%K%=9) or (%K%=12) or (%K%=5) or (%K%=10)}
repeat>j
' get the bit representation

vbeval>right(Cbin(%j%),4),%FT2COMP%
let>pattern=%FE2COMP%
concat>pattern,_
concat>pattern,%FT2COMP%

LET>filetocompare=C:\deejaysfolder\tropicana\nemo_fe\nemo_fe_
concat>filetocompare,%pattern%
'mdl>filetocompare
'FindImagePos>%filetocompare%.bmp,%screentoproofoffen%,20,1,FE2CmpX,FE2CmpY,FE2CmpC
let>FE2CmpC=1
let>FE2CmpX_0=150
let>FE2CmpY_0=150

if>FE2CmpC>0
let>i=0
repeat>i

'mdl>FE2CmpX_%i%
let>X=FE2CmpX_%i%
let>Y=FE2CmpY_%i%
'MouseMove>%X%,%Y%

let>Xi={((%X% - %XStart%) div 60)+1}
let>Yi={((%Y% - %YStart%) div 60)+1}
'let>xy={%XStart% + ( %xi% -1) *60}
'let>yy={%YStart% + ( %yi% -1) *60}
' MouseMove>xy,yy
'when we find something in row 9 then its the changeposition wich we designed on pos 9,7
if>Xi=9
let>Yi=7
endif

**BREAKPOINT**
mdl>%FE2COMP%
VBEval>set_gamefield(1,1,"%FE2COMP%","%FT2COMP%"),value
mdl>%value%
'VBEval>set_gamefield(%xi%,%yi%,left("%pattern%",4),right("%pattern%",4)),value
let>GAMEFIELD[1,1]=%value%

add>i,1

Until>i=FE2CmpC
let>LFE[%value%]=FE2CmpC
endif

add>j,1
Until>j>%maxj%
endif
add>k,1
until>k>12

endif

VBEval>debug_gamefield,result
**BREAKPOINT**
[/code]
thanks anyway for all your help

dj

[quote="adroege"]This works fine for me in version 12.0.6

[code]

VBSTART
DIM gamefield(9,7,1)
function set_gamefield(x, y, value1, value2)
gamefield(x, y, 0) = cstr(value1)
gamefield(x, y, 1) = cstr(value2)
set_gamefield=gamefield(x, y, 0 ) + "_" + gamefield(x, y, 1 )
End function
VBEND

Let>xi=1
Let>yi=0
Let>FE2COMP=1111
Let>FT2COMP=0110
VBEval>set_gamefield(%xi%,%yi%,"%FE2COMP%","%FT2COMP%"),rval
MessageModal>rval
[/code]


[quote]
Thanks a lot i didn´t have seen that changed them to function works fine,[/quote]

Why change them to a function? They don't return anything. Leave them as a Sub and just use VBRun> to execute. Less overhead that way.[/quote]

i like them as functions to control if what they did is correct


[/code]

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts