VBscript: EOF/AtEndOfStream not recognised? - vbscript

I am running macros in a mainframe emulator that read a text file to get the input key for a CICS screen and loop through the pages of the CICS screen outputting to Excel. Our emulator software has changed from Passport to Bluezone which has required some re-engineering of the proprietary screen logic but has also thrown up some weird errors with VB syntax. A number of them whilst annoying were easily resolved but my issue now is that I cannot seem to get the script to handle the end of file properly. Below is a snapshot of the logic that I have tried. When using the AtEndOfStream logic I get an "Input past end of file" error - when using the EOF logic the script just loops, continually processing the last record on file. It seems like neither version is recognising the end of the file, the file being used is a simple ASCII notepad that in this case contains a 6-character string, each line terminated with return. Note that the version 1 logic is exactly the same as it was in the old macro that ran perfectly fine in the Passport Emulator without throwing any errors, also the Bluezone emulator developer guide suggests using the version 2 logic.
Version 1:
ForReading = 1
Set objFSObject = CreateObject("Scripting.FileSystemObject")
Set strFileContents = objFSObject.OpenTextFile(strFile,ForReading)
Do while not strFileContents.AtEndOfStream
dline = strFileContents.readLine
Version 2:
Open strFile For Input As #1
Do While Not EOF(1)
Line Input #1, dline
Any help will be greatly appreciated as I have reviewed numerous threads on "Input past end of file" errors and not found a resolution and this is particularly annoying given that it works fine in the old emulator software.

Related

Weird characters on creating a ftp folder via VBA

I am asking the first question on this site because I'm stuck in a problem.
Sorry for my bad English.
I'm creating a DataBase with some coding on VBA.
Some days ago I wrote some code which creates a folder on a ftp server. And it was working fine!
Today I picked up the database and testing this function and it creates a folder but with a different weird name every time.
I tried everything such as: change the windows encoding, reading the ftp server manual (there aren't changes from the last time!), testing it on a different database...but nothing happened.
I post the code maybe there is something I accidentally change.
thank you for your support!
Private Sub Tester_Logger_Click() ' TESTER
Dim hConnection, hOpen As Long
' Open Internet Connecion
hOpen = InternetOpen("FTP", 1, "", vbNullString, 0)
' Connect to FTP
hConnection = InternetConnect(hOpen, "IP", "21", "MYUsername", "MYPassword", INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0)
FtpCreateDirectory hConnection, "\\TestFolder"
' Close Internet Connection
Call InternetCloseHandle(hOpen)
Call InternetCloseHandle(hConnection)
End Sub
EDIT:
I can create folders with FileZilla and from Windows Command Line.
I also used the command "status" (from the windows command line) to see the proprieties:
Type : ascii, Verbose: On, Bell: Off, Prompting: On, Globbing: On, Debug: Off, Hash: Off.
The weird name when i create a directory with the code above is: "xӺ �" If I run it the second time it creates a directory with this name: "(j��"
EDIT 2: I don't have a second computer, but i tried to change ftp host service and it happen again. I don't know if it's a problem of Office/Windows Upragrading. I'm sure that i did not touched anything. I tried to use a old backup version of the Database and nothing change... i have always this strange characters when i'm creating a new directory.
When I try to upload something it seems that it can't read the name of the folders. The Folders are created correctly with FileZilla and they are there, i Checked!
I read somewhere that maybe it's a problem of encoding. There is a note on FileZilla that says if there is no matching with encoding there will be problems with characters reading.
EDIT 3: I tried to reset to default settings VBA and Microsoft Access whit regedit and nothing happened.
I also tried to use different functions;
I used InternetconnectW,InternetOpenW, and FtpCreateDirectoryW instead of internetConnectA etc... because is written on the Microsoft guide those are functions for the Unicode encoding. But it's always the same.
Please someone can help me?
Thank you.

Random Vb6 error , usually for 'load control(array)' statement

"Failed to load control 'A' from B.OCX. Your version of B.OCX may be
outdated. Make sure you are using the version of the control that was
provided with your application."
This error comes randomly in vb6 application exe, will not repeat when application is closed and opened (i.e can't recreate error)
usually comes for 'load control(array)' statement
What is the cause for this error? (registration of ocx file is done properly, also it works most of the time)
tried the solution given here , but same error repeats.

SAP VBS fails to playback recording

I'm automating some reports using visual basic. I've recorded some scripts that worked fine by seem to have stopped working for reasons unknown. I record the following (comments added) and the script fails at a file dialog box.
session.findById("wnd[0]").resizeWorkingPane 95,22,false
session.findById("wnd[0]/tbar[0]/okcd").text = "se16"
session.findById("wnd[0]").sendVKey 0
' Run AGR_TCODES
session.findById("wnd[0]/usr/ctxtDATABROWSE-TABLENAME").caretPosition = 10
session.findById("wnd[0]").sendVKey 0
'Select Extended Name, Multiple selection
session.findById("wnd[0]/usr/btn%_I3_%_APP_%-VALU_PUSH").press
session.findById("wnd[1]").sendVKey 23
' select file
session.findById("wnd[2]/usr/ctxtDY_PATH").text = "c:\my_directory\"
session.findById("wnd[2]/usr/ctxtDY_FILENAME").text = "myfile"
session.findById("wnd[2]").sendVKey 0
Its at this point in script playback that the script just stops with the file select text inputs blank. I can type the information in, but that kinda defeats the purpose. I can't find the reasons or a cause, but lots of various upgrades have occurred, including my laptop and a reinstall of the os to WIN10. I don't really care why - but I do need to find a way around it.
There are 2 scenarios I've identified:
It appears that SAP occasionally loses the focus of dialog boxed. Use gratuitous .setfocus commands on the window to compensate
It appears that uploads via scripts may be blocked by security settings. You can do it manually, but not via script. A telltale sign is that when you record the script, your inputs are not recorded. So the DY_FILENAME.text line will be completely missing from the recording. I'm not sure how to fix this, but at least you know where to look!
Good luck with your scripts.

VBA Control of IE - In explicable behavior

Bizarre problem.
I am using Excel VBA to control IE and download data from web sites. Pretty vanilla.
I experience an error that only happens when I am running Windows 8.1 and IE 10. On a second PC, which is running Windows 7 and IE 8, the code works fine.
Here is the behavior.
I call the following code to open a web page:
Set appIE = CreateObject("InternetExplorer.Application")
With appIE
.navigate sURL 'Where sURL is a valid web address
End With
This works fine, and opens a browser.
Shortly afterwards, I call the following:
With appIE
.navigate sURL'a different valid web address
End With
An error message pops up at the .navigate line. The message says:
Run-time Error '-2147024726(800700aa)'
Method 'Navigate' of object 'IEWebBrowser2' Failed
I have looked up this error message and the only thing that I can find is that it may relate to spyware. But I completely reinstalled the OS and all apps on the system and the same thing happened.
Another very strange phenomenon is that if I put a trace point in-between the above two sections and pause the code, then manually start the code again, everything works fine. But if, instead of me putting in a trace point I put in a wait loop, I get the same failure. That is, if I manually pause and then resume the code, the code works, but if I automate a pause and resume, the code does not work.
As you consider this situation, please remember that everything works fine under Windows 7 and IE 8, and everything works fine if I manually pause and restart.
Does any of this make sense?
1- Please Check sURL (if you check, please check again compiled folder)
2- Delete WebBrowser Control and Add New
Me forget copy original file App.Path + "\error.html" and see this problem.

Word 2003 template with VBA macros that does not run properly in Word 2011 for MAC

As the title says, I've got a word template with macros that does not run properly in the new Word version from Office 2011 for MAC.
The thing which seems to not work properly is the following code:
Sub Document_New()
myForm.Show
End Sub
The same is with Document_Open()
It doesn't seem to run this code on the Mac version.
Does anyone know why this won't work on the Mac, or if there's another way around to emulate the document_open/document_new function?
EDIT: The document is in the .dot format. And I tried to save it to .doc, then the Document_open() worked just fine, so it seems to not be working in the .dot format.. And Document_New() is not running in .doc since its not a new templatefile based on a document..
EDIT 2: Seems like it was a once only with the Document_open on .doc files. I cant make it work again. So weird! The only event I get working, and this is only when using the .doc file format, is Document_Close() - this works everytime...
EDIT 3: This is just getting weirder. I made a new .doc document with the following code:
Private Sub Document_Open()
MsgBox ("BlaBlaBla")
End Sub
The code only runs if the Visual Basic Editor is open BEFORE I close the word file and try to open it again. If I close the Visual Basic Editor and then the word file, and then open the word file; The code is not run.
??
All VB application events are suppressed if you have the VB-editor active, and the current project is not running. It is an intentional behavior, to prevent unwanted code execution, hence not debuggable.
I have used Workbook_Open() (in Excel), and I can only see it working on newly open Excel Xls (xlsm on 2010), from a non-open VB-editor Excel application.
It will work if you have other doc/xls already open, but not if vb-editor is up.
Have you checked whether Macros are allowed? Do you have generated a certificate and setup your application as a trusted source?
I'm having similar issues. It seems that MS removed support for the Document_New and Document_Open functions in the Word object model for Word 2011. See http://mac2.microsoft.com/vb/1033/Word/html/womscChangesBetweenWord2010and2011.htm

Resources