What is the differences between these?

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
hoangvo81
Pro Scripter
Posts: 69
Joined: Tue Feb 07, 2012 8:02 pm

What is the differences between these?

Post by hoangvo81 » Fri Jun 15, 2012 6:20 pm

ArrayDim>abc,2
let>abc_1=1
let>abc_2=2

let>x=1
what is the differences between using

abc_%x%
abc_1

example:

mdl>abc_1
mdl>abc_%x%

gives the same result

but:

Assigned>abc_1,isAssigned
this will result in isAssigned=TRUE

Assigned>abc_%x%, isAssigned
this will result in isAssigned=FAlSE

this is on version 13.1.04

Thanks

gavind
Newbie
Posts: 4
Joined: Wed Jun 06, 2012 5:54 pm
Location: USA
Contact:

Post by gavind » Fri Jun 29, 2012 8:27 pm

I got nothing on top of my head for this. WOuld be nice if someone can share their thoughts please?
PHP Newbie Image

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Fri Jun 29, 2012 10:08 pm

what is the differences between using

abc_%x%
abc_1
abc_1 is a text string that can legitimately be used as a variable name. It will work like any other variable name every time you use it as a variable name.

abc_%x% is a text string that should not be used as-is for a variable name. It should be used only to create or retrieve arrayed variable values.

For example:

Let>abc_1=1
Let>abc_2=2


works very nicely if you only have a few variables to deal with. But if you need to assign

Let>abc_1=1
Through
Let>abc_1000=1000

Do you really want to do all that typing?

Instead you can assign values using a loop and an incrementing variable such as "x". (Though any text string will work and I prefer to not use single characters as variables)

Let>x=0
Repeat>x
Let>x=%x%+1
Let>abc_%x%=%x%
Until>x=1000


This is a very simple sample use for how one might create an array. Most times you would be drawing information from an outside source such as a database or a text file to populate your array. For example you might use the ReadLn> function to retrieve each line of a text file and assign that line to arrayed variables.

Let>x=0
Repeat>x
Let>x=%x%+1
ReadLn>C:\myTextFile.txt,%x%,line
If>Line=##EOF##
Let>x=complete
Goto>TextFileReadComp
EndIf
Let>abc_%x%=Line
Label>TextFileReadComp
Until>x=complete

///the rest of your script



You should have variables assigned for abc_1 through abc_x where x is the number of lines in C:\myTextFile.txt.


Hope this helps

hoangvo81
Pro Scripter
Posts: 69
Joined: Tue Feb 07, 2012 8:02 pm

Post by hoangvo81 » Wed Aug 01, 2012 5:07 pm

in that case what is the best option when trying to determine when a variable in an array has a value assign to it or not?

let say, i have a query that pulled a 1 long memo.

Code: Select all

set>sql=select memo from tblMemo where id=123445
dbQuery>dbH,sql,sqlRSt,r,n

if>r=1
   //there should only be 1.
   seperate>memo,crlf,MemoLine
   arraydim>line,MemoLine_count
   let>y=0
   let>x=0
   let>chk=0
   repeat>x
     add>x,1
      trim>MemoLine_%x%,tmp
      if>tmp=
          if>chk=0
              add>y,1
              let>line_%y%=tmp
              let>chk=-1
         endif
      else
         add>y,1
         let>line_%y%=tmp
         let>chk=0
      endif        
   until>x=MemoLine_count
   //check first variable
   let>x=0
   assigned>line_1,rst
   let>NewMemo=
   while>rst=true
        add>x,1
         let>tmp=line_%x%
        concat>NewMemo,%tmp%
       assigned>line_%x%,rst
   endwhile
endif

The jist of the idea is that the code is to take a memo block, split the memo via crlf.
and recreate the memo again. the new memo will filter out all extra crlf inside the memo.

aside from using VBScript to do this, or doing a repeat until>x=y (which i end up doing) for the second loop (y has the last count used), I was hoping that the assigned would have work. but unfortunately it doesn't work as i imagine it to. :(

User avatar
PepsiHog
Automation Wizard
Posts: 517
Joined: Wed Apr 08, 2009 4:19 pm
Location: Florida

Hello

Post by PepsiHog » Sat Aug 04, 2012 1:35 am

@ hoangvo81

This is kind of a work-around, or just a different way of doing it.

Code: Select all

let>line_1=Good day.
let>line_2=Good day.
// Rem out the below line after running, then run again.
let>line_3=Good day.

   //until>x=MemoLine_count
   //check first variable
   let>x=0
   assigned>line_1,rst
   let>NewMemo=
   while>rst=TRUE
        add>x,1
         let>tmp=line_%x%
        concat>NewMemo,%tmp%
        Position>line_,tmp,1,res
        if>res=0
           RegEx>0,res,0,match,nm,1,TRUE,rst
         else
           RegEx>1,res,0,match,nm,1,FALSE,rst
        endif
        //assigned>line_%x%,rst
   endwhile
mdl>Line_%x% is not assigned.
Copy and paste this and then run it once to see the result. Then rem out the line that is noted, and run again.

Does this work for you? Hope it does.

PepsiHog
Windows 7

PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2024) AND enjoy programming. (That's my little piece of heaven!)

The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!

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