Page 1 of 1

Trouble with IBM 5250 VB macro

PostPosted: Wed Oct 09, 2013 4:24 pm
by JoseDIA
Hello, I'm facing a problem with Dim statement into a macro for IBM 5250 (Client Access). Here is my simple code:

[PCOMM SCRIPT HEADER]
LANGUAGE=VBSCRIPT
DESCRIPTION=
[PCOMM SCRIPT SOURCE]
OPTION EXPLICIT
autECLSession.SetConnectionByName(ThisSessionName)

REM This line calls the macro subroutine
subSub1_

sub subSub1_()
   Dim value As String

   autECLSession.autECLOIA.WaitForAppAvailable
   autECLSession.autECLOIA.WaitForInputReady
   value = autECLSession.autECLPS.GetText(1, 5, 60)
   MsgBox(value)     
end sub


When I run this macro on emulator I always get an error at line "Dim value as String": End of statement expected. If I define value variable as "Dim value" without "As String" script runs fine, but I need to define the type of each variable. Any ideas? Thanks.

Re: Trouble with IBM 5250 VB macro

PostPosted: Wed Oct 09, 2013 6:11 pm
by NicC
Are you sure 'value' is an allowed variable name - I would have thought that it was a reserved word. certainly it is not a good name for a variable.

Re: Trouble with IBM 5250 VB macro

PostPosted: Wed Oct 09, 2013 7:31 pm
by JoseDIA
Thanks for your quick response. Well, you are right but I have translated this word to english because this is an english forum. The original script is like below, and "valor" is not a reserved word:

Dim valor As String

I tried to convert "As" to LowerCase and get the same error:
Dim valor as String


I think this is a weird error because refering to the API document http://publib.boulder.ibm.com/infocente ... cess08.htm there are many variables declared like mine.

Re: Trouble with IBM 5250 VB macro

PostPosted: Wed Oct 09, 2013 8:49 pm
by NicC
Val however is a VB function (or, at least, a VBA function which is the only reference I have to hand) so I wonder if VB is getting confused?

Re: Trouble with IBM 5250 VB macro

PostPosted: Wed Oct 09, 2013 9:06 pm
by JoseDIA
Val is a function but Valor isn't. I wonder too coz I copied and pasted -Dim x As Number- line from http://publib.boulder.ibm.com/infocente ... ingdim.htm to my .mac file and I run it on Client Access emulator and it gives me the same error :lol: Perhaps I'm declaring variables in a wrong section. I dont know.

Well in order to avoid creating variables I have removed OPTION EXPLICIT line, but now I have not accuracy of the type of variable.
Thank you for your time.

Re: Trouble with IBM 5250 VB macro

PostPosted: Fri Oct 18, 2013 8:43 am
by cobolcmd
hi, I think you can define the variable as below:
dim valor
no need to indicate the type, just use it.
if you give a string value to it, then it would be a String type; if you give a integer value to it, it would be a integer type. you can have a try.

Re: Trouble with IBM 5250 VB macro

PostPosted: Fri Oct 18, 2013 12:17 pm
by JoseDIA
Hello. Yes, it works like you say, but it's the same as no declaring variables.

Thanks for your response.

Re: Trouble with IBM 5250 VB macro

PostPosted: Fri Oct 18, 2013 1:49 pm
by NicC
Is it a Visual Basic macro? The page you linked to was for Basic, not Visual Basic. I could not see OPTION EXPLICIT in those pages so I cannot say if it is a part of Basic or not. Also, not specifying a type in Basic is not the same as with Visual Basic. In Basic it assumes the type of the first data assigned to it and it keeps that type from that point onwards. But, in Visual Basic you do not need to declare the type when using OPTION EXPLICIT - just the name.

Re: Trouble with IBM 5250 VB macro

PostPosted: Fri Oct 18, 2013 2:13 pm
by JoseDIA
The first page I linked is for VB, not Basic: http://publib.boulder.ibm.com/infocente ... cess08.htm and I can see there thousands of examples of variable declarations where type is defined. If I copy & paste kinda of that code to my .mac file and I run it into Client Access Emulator it crashes always at Dim statement. At first post of this thread there is a code example that everybody can try it for yourself.

Re: Trouble with IBM 5250 VB macro

PostPosted: Fri Oct 18, 2013 4:42 pm
by JoseDIA
I have found this VB code for Client Access (AS400) that export any AS400 screen to an Excel sheet: http://forums.iprodeveloper.com/forums/aft/148659
XavierM declares variables without specifying its type. Well, I am very confused with this, but I think NicC is right.
From now I'll try to declare variables with no type.

Thank you all.