Argument of Repeat Until can't handle Scientific Notation

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
evangelmike
Pro Scripter
Posts: 56
Joined: Sun May 11, 2008 9:39 pm

Argument of Repeat Until can't handle Scientific Notation

Post by evangelmike » Tue Sep 02, 2008 1:14 am

When Excel spreadsheet cells are set to numbers in Scientific Notation, and these values are read by a Macro Scheduler macro, the compare in the Until statement of a Repeat-Until loop, returns an error when the condition in the Until statement involves a compare against a number expressed in Scientific Numeric Format. Consider the following macro:

[code]
// Use the proper focus for the workbook you open
SetFocus>Microsoft Excel*

// Set A2 through A4 of a workbook named Microsoft Excel*
// to large numbers:
GoSub>SetCell, a2,10000000000
GoSub>SetCell, a3,100000000000
GoSub>SetCell, a4,-100000000000
GoSub>SetCell, a5,2
// Go to Cell A1
Press CTRL
Wait>0.1
Press Home
Wait>0.1
Release CTRL
Let>COUNT=0
// The following loop repeats until Excel Cell A5 (which contains a 2)
// is processed
Repeat>SIssuerAmount
SetFocus>Microsoft Excel*
Press Down
Wait>0.2
// Get contents of first/next location:
Press CTRL
Wait>0.2
Send>c
Wait>0.2
Release CTRL
Wait>0.2
GetClipBoard>SSIssuerAmount
Len>SSIssuerAmount,SSLen
Let>LastChr=SSlen-2
midstr>SSIssuerAmount,1,LastChr,SIssuerAmount
MessageModal>SIssuerAmount = %SIssuerAmount%
SetFocus>Microsoft Excel*

/*
// Check if SIssuerAmount is in Scientific Format, i.e. having an "E" in it.
Position>E,SIssuerAmount,1,StartPos
If>StartPos0
// Here, if possible, we could put some logic to convert SIssuerAmount
//from Scientific Notation to normal notation. For the time being we will
// set it to 2. It should be mentioned that if SetCell had been used to
// set Excel cells to numbers in Scientific Notation, even resetting these
// cells to small numbers leads to these small numbers being
// expressed in Scientific Notation.
Let>SIssuerAmount=2
Endif
*/

Until>SIssuerAmount=2
Press Esc
MessageModal>SIssuerAmount = %SIssuerAmount% OK!
Exit>0

// SetCell is used to set Excel Locations.
// SetCell is called thusly: Gosub SetCell, celladdr, cellcontents
SRT>SetCell
Press F5
wait>0.20
WaitWindowOpen>Go To
wait>0.20
Send>%SetCell_Var_1%%CR%
Wait>0.2
Send>%SetCell_Var_2%
Press Tab
Wait>0.1
End>SetCell
[/code]

The above logic runs perfectly if a new clean workbook is opened and cells A2 through A4 are set to small integers (like 4, 10, -6), but if these locations are set to numbers large enough to invoke the Scientific Number Format as above (for A3 and A4), although A2 works fine when this code is run and the Until statement is executed, when A3 and A4 are processed in the Until statement, the attempt to execute the Until statement results in the error: "Line 43: Bad Numeric Format." The workaround is obtained by uncommenting the commented block in the above code.
May you have a blessed day!

Michael D Fitzpatrick
Reg. US Patent Agent

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