Conversion of Reflection to PComm scripts

30 pts.
Tags:
CSV file
PCOMM
Visual Basic
Hi, I have a Reflection script that basically uses a CSV file and inputs the data for as long as the loop into variables A and B for instance. It then moves the cursor to a certain position and enters it into the screen and f9 to update/save. How can I replicate the same thing in PComms. I have this code so far but it does not seem to work:
[PCOMM SCRIPT HEADER]
LANGUAGE=VBSCRIPT
DESCRIPTION=
[PCOMM SCRIPT SOURCE]
OPTION EXPLICIT
autECLSession.SetConnectionByName(ThisSessionName)

Sub Main()

autECLSession.autECLOIA.WaitForAppAvailable
autECLSession.autECLOIA.WaitForInputReady

Rem Opening the csv file for reading only
Dim secuencia

Dim landedcost

Dim fs
' as FileSystemObject
Dim TSa
' as TextStream
fs=CreateObject("Scripting.FileSystemObject")
Set TSa = fs.OpenTextFile("Receipts.csv",ForReading)

Do While TSa.AtEndOfStream True
arr = Split(TSa.ReadLine, ",")
data1= arr(0)
cost= arr(1)

autECLSession.autECLOIA.WaitForAppAvailable
autECLSession.autECLOIA.WaitForInputReady
autECLSession.autECLPS.SetCursorPos 6, 31
autECLSession.autECLPS.SendKeys "[eraseeof]"
autECLSession.autECLPS.SendKeys "[data1]"
autECLSession.autECLOIA.WaitForInputReady
autECLSession.autECLPS.SetCursorPos 8, 31
autECLSession.autECLPS.SendKeys "[eraseeof]"
autECLSession.autECLPS.SendKeys "[cost]"

Rem Press F9 to update/save

autECLSession.autECLOIA.WaitForAppAvailable
autECLSession.autECLOIA.WaitForInputReady
autECLSession.autECLPS.SendKeys "[pf9]"
autECLSession.autECLOIA.WaitForAppAvailable
autECLSession.autECLOIA.WaitForInputReady

Loop

Tsa.Close

end sub


Software/Hardware used:
PComm

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Discuss This Question: 4  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • TheRealRaven
    I have this code so far but it does not seem to work

    Why not? What goes wrong? Are there errors?
    21,845 pointsBadges:
    report
  • pwincess05

    Hi,

    Well, it doesn't seem to do anything when I run the macro. How can I ensure that it is reading the csv files? Should I specify the full path? Also, I would like to write to a file, a bit like a log. How can I do this?

    30 pointsBadges:
    report
  • pwincess05
    The file stream object is not recognised by Pcomm. WHy is this? It is VBA script so it should work. I need to read from a file in Pcomm.
    30 pointsBadges:
    report
  • TheRealRaven
    First thing that must always be remembered:
    VBS <> VBA <> VB <> VB.Net
    There are lots of little details that trip up coders when working with different ones of those. I've put together the beginning of a VBS macro that "works", though it is neither complete for what you need nor correct. E.g., the path to Receipts.csv is simply one that works for me; it won't work for you. You'll need to determine what's correct. Also, I merely display data1 and cost variables; you'll need to insert your code to write to your screen.

    But with a correct path, you should be able to follow what happens:
    [PCOMM SCRIPT HEADER]
    LANGUAGE=VBSCRIPT
    DESCRIPTION=
    [PCOMM SCRIPT SOURCE]
    OPTION EXPLICIT
    autECLSession.SetConnectionByName(ThisSessionName)
    
    msgbox "Start"
    
    sub1
    
    Sub Sub1()
    
    msgbox "In main"
    
    autECLSession.autECLOIA.WaitForAppAvailable
    autECLSession.autECLOIA.WaitForInputReady
    
    msgbox "Waits done"
    
    Rem Opening the csv file for reading only
    
    Const ForReading = 1
    
    Dim secuencia
    
    Dim landedcost
    
    Dim fs
    ' as FileSystemObject
    Dim TSa
    ' as TextStream
    
    Dim arr
    Dim data1
    Dim cost
    
    msgbox "Dims done"
    
    set fs = CreateObject("Scripting.FileSystemObject")
    
    msgbox "Create done"
    
    Set TSa = fs.OpenTextFile("C:\Documents and Settings\TOML\Receipts.csv",ForReading)
    
    msgbox "Open done"
    
    Do Until TSa.AtEndOfStream
    
    msgbox "In DO"
    
    arr = Split(TSa.ReadLine, ",")
    data1= arr(0)
    cost= arr(1)
    
    msgbox "For: " & data1 & " cost: " & cost
    
    Loop
    
    Tsa.Close
    
    end sub
    Compare this line by line with yours. Numerous lines have been added, and your lines to write to a screen have been removed. A few lines have been changed.

    Maybe most useful at this stage are the various msgbox lines. During testing, those are almost the only debugging help you'll get for VBscript. As parts become cleanly working, they can be removed.
    21,845 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: