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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get variable from ini 1

Status
Not open for further replies.

timotai

Technical User
Apr 13, 2002
119
GB
Hi All

I have created a vb script in PCOMM which logs on and pulls back data from an AS400. What I want it to do is to take data from an ini file which contains the username and password to logon.

Here is the ini:

[Logon_Details]
userid=user1
password=password1

My code is below

Code:
[PCOMM SCRIPT HEADER]
LANGUAGE=VBSCRIPT
DESCRIPTION=
[PCOMM SCRIPT SOURCE]
OPTION EXPLICIT
autECLSession.SetConnectionByName(ThisSessionName)
dim struserid, strpassword

REM This line calls the macro subroutine
subAWDPrty_

sub subAWDPrty_()
Dim Strinput
   autECLSession.autECLOIA.WaitForAppAvailable


    rem strInput = InputBox ( "Please enter your user ID", "User ID")
    rem autECLSession.autECLPS.SendKeys strInput

autECLSession.autECLPS.SendKeys [COLOR=#ff0000] USERID VARIABLE FROM INI [/color]


   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[TAB]"

    rem strInput = InputBox ( "Please enter your password ", "Password")
    rem autECLSession.autECLPS.SendKeys strInput 

[COLOR=#ff0000] autECLSession.autECLPS.SendKeys PASSWORD VARIABLE FROM INI [/color]


   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[ENTER]"
   autECLSession.autECLOIA.WaitForInputReady


How do I do it??

This has been confusing me for a while.

If possible aswell csn you show me how to write back to the ini aswell?

All help and advise is appreciated

Many Thanks

Tim
 
This is how I do it in VB:

Writeinivalue and readinivalue are the bits you're interested in:

Option Explicit
Const MUTEX_ALL_ACCESS = 2
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function OpenMutex Lib "kernel32" Alias "OpenMutexA" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal lpName As String) As Long
Public 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

Public 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

Public Sub btnCallApp(strLocalAccountNo As String, strLocalBranchCode As String)
Dim APPlusHandle As Long
Dim WindowName As String
Dim ShellResult As Long
Dim i As Long
Dim Module2String As String
Dim strDrivePath As String
Dim strResults As String

strResults = Dir$("C:\WINNT\APP.ini")
If strResults = "" Then
MsgBox "Cannot launch APP - ini file missing"
End If

frmBusySplash.Show
frmBusySplash.lblBusyCaption = "Loading APP"
frmBusySplash.Refresh

strDrivePath = GetBranchPath(strLocalBranchCode)
strDrivePath = Left(strDrivePath, (InStr(strDrivePath, "BMPC\") + 3))

Call WriteIniValue("Databases", "DrivePath", strDrivePath)
Call WriteIniValue("Databases", "Bankbranch", Mid(strLocalBranchCode, 3, 2))

'See if BM+ Menu is running
WindowName = "TfrmMainMenu"
BMPlusHandle = FindWindow(WindowName, vbNullString)

'Check result
If APPlusHandle = 0 Then
'Start up APP
ShellResult = Shell("I:\APP32\MENU.EXE")
If ShellResult = 0 Then
MsgBox "Unable to Start APP" 'Report unable to start menu
GoTo btnCallAPPExit 'get out
Else
'wait for APP menu to start
i = 0
While (i < 20000) And (APPlusHandle = 0)
'look to see if APP has started
APPlusHandle = FindWindow(WindowName, vbNullString)
i = i + 1
Wend
'if APP did not start then warn and exit
If APPlusHandle = 0 Then
MsgBox "APP did not start"
GoTo btnCallAPPlusExit
End If
End If
End If

'if we get here then APP is running so start module 2 - build the start string
If strLocalAccountNo <> Space(0) Then
If Len(strLocalAccountNo) > 6 Then
Module2String = "I:\APP32\Module2.exe " + Mid(strLocalAccountNo, 6, 6) + " " + strLocalAccountNo
Else
Module2String = "I:\APP32\Module2.exe " + strLocalAccountNo
End If
Else
Module2String = "I:\APP32\Module2.exe "
End If

'Call the enquiry module
Shell Module2String
btnCallAPPlusExit:
Unload frmBusySplash
End Sub

Public Function ReadIniValue(strSection As String, strElement As String) As String

Dim iret As Long 'Return Code
Dim retStr As String * 30 'Return String -> Answer is in it
Dim strdisplay As String

iret = GetPrivateProfileString(strSection, strElement, "Default", retStr, 30, "c:\WINNT\APP.ini")
ReadIniValue = "Return Code: " & iret & vbCrLf & "Return String: " & retStr

End Function

Public Function WriteIniValue(strSection As String, strElement As String, strValue As String) As String
Dim iret As Long 'return code
iret = WritePrivateProfileString(strSection, strElement, strValue, "c:\WINNT\APP.ini")
WriteIniValue = "Return Code: " & iret
End Function

 
Hi TomKane

I am having trouble understanding what bits to use in my code from yours. Could you give me a bit of info to help me adapt this to work in my code.

I gave it an attempt but Pcomm didnt seem to like the public functions. does all vbscript in different applications work the same?

This is the first time I have worked with vb script so you'll have to forgive me if I seem dull at any point. I do use visual basic coding in Access and vb 6 though so I have some understanding

Thanks

Tim
 
try this
Code:
dim fso
dim ts
dim strIni

set fso =  createobject("Scripting.FileSystemObject")
set ts = fso.Opentextfile("C:\Doc.ini")
strIni = ts.readall
msgbox strIni
Then you can parse the string or use the readline method to read each line individually
Sam

Sam
 
Thanks sdraper, That was really helpful. I have now been able to get the data I wanted. Many thanks for your help.

Tim
 
Glad to help. One addition. add the following lines at the end to cleanup resources.
set fso = Nothing
set ts = Nothing

Sam
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top