How to read and write variables in ini file with VBscript
1. Store variables in .ini file:
Public Function setGlobal (par_name, par_value) ' Pupose: Store parameters variable gDATAFOLDER= Environment.Value("TestLocation or some path") &"Data" gPARFILENAME = gDATAFOLDER & "qtpparam.ini" Dim rc Extern.Declare micInteger,"WritePrivateProfileStringA", "kernel32.dll","WritePrivateProfileStringA",micString, micString, micString, micString rc = Extern.WritePrivateProfileStringA("PARAMS",par_name,par_value, gPARFILENAME ) FnReadGlobalFile End function
2. Read variables stored in .ini file:
Public Function FnReadGlobalFile ' Pupose: To Reterive the data's from data sheet dyanmically Dim gDATAFOLDER Dim gPARFILENAME gDATAFOLDER= Environment.Value("TestLocation or some path") &"Data" gPARFILENAME = gDATAFOLDER & "qtpparam.ini" Dim fArrFileLines() i = 0 Set fObjFSO = CreateObject("Scripting.FileSystemObject") If (fObjFSO.FolderExists(gDATAFOLDER) = False) Then fObjFSO.CreateFolder(gDATAFOLDER) End If If fObjFSO.FileExists(gPARFILENAME)=False Then Exit Function End If Set fObjFile = fObjFSO.OpenTextFile(gPARFILENAME, 1) Do Until fObjFile.AtEndOfStream Redim Preserve fArrFileLines(i) fArrFileLines(i) = fObjFile.ReadLine i = i + 1 Loop fObjFile.Close For l = Ubound(fArrFileLines) to 1 Step -1 fTempstr=split (fArrFileLines(l),"=") fvar= fTempstr(0) fval=fTempstr(1) Execute fVar & "=fVal" Next Set fObjFSO=Nothing End Function
Discover more from Automation Script
Subscribe to get the latest posts sent to your email.