Simple loop problem

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
jonathaneaz
Newbie
Posts: 2
Joined: Mon Jan 07, 2008 7:04 am

Simple loop problem

Post by jonathaneaz » Mon Jan 07, 2008 7:17 am

Hello,

I am working on building a script that will update stock prices in an excel spreadsheet. I will have to copy the symbols from the spreadsheet, send them to yahoo finance, parse out the info, and send it back to excel.

I am new to programming so I have been taking this one step at a time and followed the excel extract sample script.

Now I am having problems with the loop. I set it to output to notepad instead of IE just to see how it works.

The loop runs continuously and only copies the first row. It seems to run better with r=2 like the sample. I used r=6 at the end of loop to test it since r=maxrows does seem to work.

My guess is that I have a problem with the way I built the dialog box.

Thanks,

Jonathan

Dialog>Dialog1
Caption=Dialog1
Width=384
Height=257
Top=458
Left=358
Edit=msEdit1,16,72,249,
Label=Excel file:,16,56,true
Button=Browse,280,72,75,25,0
Label=Browse for an Excel spreadsheet,16,16,true
Button=OK,280,128,75,25,10
Edit=msEdit2,16,128,121,0
Label=Number of rows:,16,112,true
Label=Symbols must in the first column without header,16,176,true
FileBrowse=Browse,msEdit1,Excel Files|*.xls|All Files|*.*,open
EndDialog>Dialog1

Show>Dialog1,1

Let>filename=%Dialog1.msEdit1%
Let>maxrows=%Dialog1.msEdit2%

IfFileExists>filename

//Start Excel
ExecuteFile>filename
Wait>0.5

//Open notepad
Run>Notepad.exe
Wait>0.5

Let>r=1
Repeat>r

//get the fields for this row
DDERequest>Excel,filename,R%r%C1,field_1,60

//paste each row into Notepad
SetFocus>Untitled - Notepad
Send>%field_1%

Let>r=r+1
Wait>0.5
Until>r=6

Else
MessageModal>Could not find: %filename%
Endif

Excel Spreadsheet

Column 1
AAPL
MER
XOM
C
PFE

jonathaneaz
Newbie
Posts: 2
Joined: Mon Jan 07, 2008 7:04 am

Re: Simple loop problem

Post by jonathaneaz » Mon Jan 07, 2008 7:55 am

Hello,

I think that I fixed it. The dialog block was wrong - I had a 10 after the OK instead of a 1.

Dialog>Dialog1
Caption=Dialog1
Width=384
Height=257
Top=458
Left=358
Edit=msEdit1,16,72,249,
Label=Excel file:,16,56,true
Button=Browse,280,72,75,25,0
Label=Browse for an Excel spreadsheet,16,16,true
Button=OK,280,128,75,25,1
Edit=msEdit2,16,128,121,0
Label=Number of rows:,16,112,true
Label=Symbols must in the first column without header,16,176,true
FileBrowse=Browse,msEdit1,Excel Files|*.xls|All Files|*.*,open
EndDialog>Dialog1

Thanks,

Jonathan

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