B: Objects
Terje Johan Abrahamsen
terjej at mailandnews.com
Fri May 17 10:07:30 EDT 2002
I have just started to learn Python after writing more of a spagetti
style code in other languages with plenty of goto's. After what I have
understood, you use different objects in Python to get the same
effect. So, I took my task, to transfer Excel data over to an AS400
display, and divided the task into 4 separate parts. Basically what I
want the four parts to do is:
Accountcurrentstest:
Run the other tasks and stop when it gets the stop command from
finnxlpol. (When stopper = 5).
Finnxlpol:
Find the next policynumber in Excel. These are located in the A
collumn. When there are no more policynumbers, set stopper = 5, so
accountcurrentstest can stop the whole thing.
finnpolicy:
Find the policy that finnxlpol returned in the As400 display.
skriv:
When finnpolicy has found the correct line, get the amount info
from Excel, and paste it into the AS400 display. When this is done,
the whole process should start again.
The 3 last tasks works ok. I can run them, and they do what I want
them to do. My problem is the first one. How can I get the
accountcurrentstest to run the others? Well, actually it runs the
others, but there always ends up being errors. Like xlrow is not
defined. Even thought I tried with a config.py file that contained
'pass' and then wrote config.xlrow and so forth it didn't work. I have
tried writing global in front of all variables, and it didn't work
either. I have rewritten the thing probably 20 times, but it will not
work. (I know that the accountcurrentstest will not work with the code
I have now, but I have tried to take one step at a time, and include
more and more of what I want. But, it stops in the start, and this is
where I am now.)
Could anyone give me a little hint about how I can fix this problem?
Thanks a lot in advance......
-----------
from win32com.client import Dispatch
import finnxlpol
import skriv
import finnpolicy
import config
class accountcurrentstest:
xl = Dispatch("Excel.Application")
ex = Dispatch("Extra.System")
stopper = 0
xlrow = 1
xlcol = 1
global exrow
exrow = 15
excol = 4
polchar = 10
xl.Workbooks.Open(Filename='H:\\My documents\\account currents
test.xls')
xlBook = xl.Workbooks(1)
xlSheet = xl.Sheets(1)
while stopper != 5:
xlpol2 = finnxlpol.xlpol()
print xlpol2
stopper = 5
-------------------
from win32com.client import Dispatch
class finnxlpol():
xl = Dispatch("Excel.Application")
ex = Dispatch("Extra.System")
xlBook = xl.Workbooks(1)
xlSheet = xl.Sheets(1)
xlrow = 1 + xlrow
xlpol = xlSheet.Cells(xlrow, 1).Value
if xlSheet.Cells(xlrow, 1).Value == None:
stopper = 5
--------------------
from win32com.client import Dispatch
def finnpolicy():
ex = Dispatch("Extra.System")
expol = ex.ActiveSession.Screen.GetString(exrow, excol, polchar)
exrow = 13
while expol != xlpol:
exrow = exrow + 1
expol = ex.ActiveSession.Screen.GetString(exrow, excol,
polchar)
print expol, exrow
if exrow > 21:
ex.ActiveSession.Screen.SendKeys("<RollUp>")
exrow = 13
-----------------------
from win32com.client import Dispatch
def skriv():
xl = Dispatch("Excel.Application")
ex = Dispatch("Extra.System")
xlBook = xl.Workbooks(1)
xlSheet = xl.Sheets(1)
xlamount = xlSheet.Cells(xlrow, 3).Value
ex.ActiveSession.Screen.Select(exrow, 66, exrow, 76)
ex.ActiveSession.Screen.Paste()
More information about the Python-list
mailing list