Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pulling variable(s) from secondary macro 1

Status
Not open for further replies.

Person51

Programmer
Mar 3, 2006
16
0
0
US
Hey all, after coming up with some macro's, and obeying company policy, I had to password protect the code behind all the code, requiring me to go to each individual desktop when installing to edit 2 simple lines of code. As this is rather tedious and time consuming, I tried to come up with a solution.

Each macro has to have an employee's id # and username, the id consisting of 3 characters / digits (ex: XX8) and the username, being the first letter of their first name, and their last name, (ex: J.Smith).
Within the code, I had simply declared it as :

eid = ("XX8")
username = ("J.Smith")
And simply doing the Sendkeys when I needed it. Rather than have to go around to over 400 desktops as updates are needed for the heart of the code, I started using the Shell Function to call up two .txt files. Like this :

EID = Shell("notepad.exe C:\Program Files\Attachmate\E!E2K\Macros\ENU\eid.txt", 1)
Pause .6
Sendkeys "^a"
Sendkeys "^c"
Sendkeys "%{F4}"
&

USERNAME = Shell("notepad.exe C:\Program Files\Attachmate\E!E2K\Macros\ENU\username.txt", 1)
Pause .6
Sendkeys "^a"
Sendkeys "^c"
Sendkeys "%{F4}"

Instead of getting the info from a outside source from a copy / paste method from notepad, I'm trying to have a standalone macro that has the employee ID and username, to which I can call upon, and use those variables in the running macro.
Now, in the macro the user runs, I've included this line :
TEST = Shell("C:\Program Files\Attachmate\E!E2K\ebrun.exe C:\Program Files\Attachmate\E!E2K\Macros\ENU\INFO.ebm", 7)

With the INFO.ebm containing the eid and username declarations, I put the above line in pw macro, have a msgbox pop up to test, and I'm not getting the strings. If I put a msgbox in the unprotected macro and run it from the pw macro, the strings work.

Any ideas, or would what I'm after even work?
 
not sure where your employee ID is stored but have you tried
Code:
Sub Main
    sUserName = Environ("UserName")
    msgbox sUserName
End Sub

You could save this info in an .ini file for each user instead of cut pasting a txt file check out thread1-1185554 to find out how

[thumbsup2] Wow, I'm having amnesia and deja vu at the same time.
I think I've forgotten this before.


 
Milson, ID's aren't stored anywhere on individual user's computers, but were rather input manually into orders being processed on a manual keyed entry level.
So, in the 'automation' of order types, I used their ID's as a string to negate them from typing it in. Since the code is now passworded, I'm required to edit everyone's ID and name. What I'm trying to do in a nutshell, is call upon a second macro, to which all it contains is the eid = ("111") and username = ("J.Smith") strings, and have those strings input as needed in the originating macro.
I did have a 2 .txt files, I set the macro to Select All, Copy, Close out the notepad, paste it into the Extra Session, grab it as string variable to use later on in the macro, and then use the <EraseEOF> to delete.
Now, it worked to some extent, however, there was delays in opening / copying / pasting that had to be accounted for, but I'd rather not have the .txt files appear on the screen, nor use them at all. It seemed like there would be a way to use these 2 variables that users have access to in a macro they could edit themselves.
Hope that might clarify things a bit.
 
Did you look at the thread I referenced? Run this

Code:
Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" _
    (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, _
    ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long

Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" _
    (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, _
    ByVal lpFileName As String) As Long

Sub Main
    Dim sUserName As String * 30
    Dim sUserId As String * 30

    if GetPrivateProfileString("UserInfo", "UserName", "Default", sUserName, 30, "c:\" & Environ("UserName") & ".ini") = 7 then
        sUserName = InputBox("Enter User Name")
        RC = WritePrivateProfileString("UserInfo", "UserName", sUserName, "c:\" & Environ("UserName") & ".ini")
    End If    

    if GetPrivateProfileString("UserInfo", "UserId", "Default", sUserId, 30, "c:\" & Environ("UserName") & ".ini") = 7 then
        sUserId = InputBox("Enter User Id")
        RC = WritePrivateProfileString("UserInfo", "UserId", sUserId, "c:\" & Environ("UserName") & ".ini")
    End If    

    msgbox "User Name is " & sUserName
    msgbox "User Id is " & sUserId

End Sub
Is that what you want?

It creates an Ini file titled UserNameHere.ini on the C drive (you can switch the path if you'd like). This way different users get there own information not someone else's.

[thumbsup2] Wow, I'm having amnesia and deja vu at the same time.
I think I've forgotten this before.


 
Milson, that code works great! thanks!
How would I go about grabbing the username and id from the .ini file, and sending that into an EB session?

Based upon your code, I could have users run that macro only once, and it would save it until ran again. More than what I had ever asked for, I thank you again.

Before I had tried your code, I was looking into using a simple header file (.ebh), with the ID and Username in as Global Const.
Somehow, I was able to get the Len of the ID and Name, but when I tried to concatenate it in a msgbox, it was blank.

I'm trying now to fuse your code and my existing test code for the .ini file.
 
Run it again it'll remember you.

Add it to your macro it'll only run once anyway then use variables sUserName and sUserId whenever you need either.

assuming you have a screen object put it wherever you want

YourScreen.Putstring(sUserId,1,1)

Post your code if you need help fusing

[thumbsup2] Wow, I'm having amnesia and deja vu at the same time.
I think I've forgotten this before.


 
Milson, I see what your code was doing now.
The input boxes for name and ID would display everytime the macro was ran, and it would output the info into a .ini file located in the set path.

What I'm attempting to do, is since that information doesn't change, unless the operator of the pc changes, is it possible to draw that data into a macro several hundred times a day without the file displaying to the screen?

Example, so the info in the .ini file is on C:\, how would I tell the macro to get that data ?

I had a working code bit where I used the shell to open a .txt file named username, did the sendkeys to select all, copy, then it would close it out, paste it to the Sess screen, I'd then use a X = Sess0.Screen.GetString (1,1,1) to store in memory, then erase it from the Sess, at which point I would do sendkeys to punch it in when needed.

I ran another shell just the same for the ID. It worked, however, it was a nuisance to users, and didn't function correctly if there was any latency, often copying the wrong information.

When I created in VB6, I built mod's that I could have the rest of the program reference, when I wanted to save space, memory and time, by declaring the strings, integers I would use throughout the program. The header files in EB looked to be just that, though, I wasn't able to get the strings to display. I did check the Len(username) and Len(eid), and they came back as 7 and 3 when using the J.Smith and 111. It, however, wouldn't display the actual string value in a box, thus further driving me nuts.
Would this be something I should go about, or continue using the shell ?
-51
 
For security you'll want to store that ini in a path accesable by user only. Perhaps in an encrypted folder in their Document and Settings folder (assuming Windows OS)

[thumbsup2] Wow, I'm having amnesia and deja vu at the same time.
I think I've forgotten this before.


 
It's dynamic by using the Environ user name to build a unique .ini file for anyone using the pc. builds one for you and another one for each other user. When calling it back each user will get their own information (you would get yours and I would get mine)

It is checking to see if one exsists for the user logged on and asking for input only if it's not there.

RC = GetPrivateProfileString("UserInfo", "UserName", "Default", sUserName, 30, "c:\" & Environ("UserName") & ".ini")

is calling the info back out of the .ini file.

Rc is letting you know if it was there or not and sUserName is the variable containing what was there.

to put it into your screen

Sess0.Screen.PutString (sUserName,row,column)
is the best way or
Sess0.Screen.SendKeys (sUserName)


[thumbsup2] Wow, I'm having amnesia and deja vu at the same time.
I think I've forgotten this before.


 
Phenomenal.
I'm loving every bit of it now.
Milson, 5 Stars for you man.
From all 2 of us here, at the [can't specify location] we thank you very much.

 
Since you seem to be familiar with header files.

save this bit as a EBH
Code:
Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" _
    (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, _
    ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long

Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" _
    (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, _
    ByVal lpFileName As String) As Long

Function GetUserName() As String
    Dim strUserName As String * 30
    if GetPrivateProfileString("UserInfo", "UserName", "Default", strUserName, 30, "c:\" & Environ("UserName") & ".ini") = 7 then
        sUserName = InputBox("Enter User Name")
        RC = WritePrivateProfileString("UserInfo", "UserName", strUserName, "c:\" & Environ("UserName") & ".ini")
    End If 
    GetUserName = strUserName
End Function
    
Function GetUserId() As String
    Dim strUserId As String * 30
    if GetPrivateProfileString("UserInfo", "UserId", "Default", strUserId, 30, "c:\" & Environ("UserName") & ".ini") = 7 then
        sUserId = InputBox("Enter User Id")
        RC = WritePrivateProfileString("UserInfo", "UserId", strUserId, "c:\" & Environ("UserName") & ".ini")
    End If    
    GetUserId = strUserId
End Function

In your main macro do this
Code:
'make sure this line is at the top
'$Include "C:\APIEBH.EBH"


Sub Main

Sess0.Screen.SendKeys (GetUserName)
    
End Sub



[thumbsup2] Wow, I'm having amnesia and deja vu at the same time.
I think I've forgotten this before.


 
Milson, had a question for you.
What is the significance of the =7 in the If/Then statement?
From what I had found in EB, -1 was True, 0 was False. Reason I ask, is that, I had modified the Dim * 30 down to 12 and 4 respectively, since the user names & id's end up as J.Smith and A1A, so it's not entering an extreme amount of spaces.

In a few cases however, everytime the macro runs, it hits the user up to enter the name everytime, even when the .ini file hasn't been modified, or deleted. We also took the logic from the code and added to it, having users enter a login ID for the EB session and their password. I used a password box rather than a input for that.

For some reason, the macro will only ask for the username and login input, but once the password and id are registered in the .ini, it never asks again. Sorry to pester you again, but trying to access those wonderful help files in EB make me end up having to end the process because it has failed to load on my pc.
 
Sorry, switch your ebh file to this
Code:
Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" _
    (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, _
    ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long

Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" _
    (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, _
    ByVal lpFileName As String) As Long

Function GetUserName() As String
    Dim strUserName As String * 12
    if GetPrivateProfileString("UserInfo", "UserName", "", strUserName, 12, "c:\" & Environ("UserName") & ".ini") = 0 then
        strUserName = InputBox("Enter User Name")
        RC = WritePrivateProfileString("UserInfo", "UserName", strUserName, "c:\" & Environ("UserName") & ".ini")
    End If 
    GetUserName = strUserName
End Function
    
Function GetUserId() As String
    Dim strUserId As String * 4
    if GetPrivateProfileString("UserInfo", "UserId", "", strUserId, 4, "c:\" & Environ("UserName") & ".ini") = 0 then
        strUserId = InputBox("Enter User Id")
        RC = WritePrivateProfileString("UserInfo", "UserId", strUserId, "c:\" & Environ("UserName") & ".ini")
    End If    
    GetUserId = strUserId
End Function

The = 7 would loop anyone with a 7 character user name. It was testing for length of "Default" (which is what was returned if nothing existed.

Now it returns "" which is tested by a length of 0.

To better understand the API call and it's return check out

It explains it better than I could.

[thumbsup2] Wow, I'm having amnesia and deja vu at the same time.
I think I've forgotten this before.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top