Attribute VB_Name = "Module1" '**************************************************************************************** ' ' File: MASSLYNX.BAS ' ' Author: Roberto Raso ' Date: 17th June 1994 ' '**************************************************************************************** ' ' Purpose: Provide a collection of general MassLynx functions. ' '**************************************************************************************** '**************************************************************************************** ' ' Constant/Global declarations. ' '**************************************************************************************** Const RAW_MAX_SAMPDESC_LENGTH = 120 'Windows message CLOSE WINDOW. Const IDM_FILE_NEW = 11 Const IDM_DESK_PRINTER = 12 'Printer set-up Const LANDSCAPE = &H421 Const PORTRAIT = &H420 'Constants for adding, replacing or new windows. 'Used in functions like ChroFile and SpeFile. Global Const ADD = 0 Global Const REPLACE = 1 Global Const NEW_WINDOW = 2 '--- '--- Data Browser and History Dialogue Boxes Constants '--- Global Const SPEC_OPEN = 1 Global Const CHRO_OPEN = 2 Const ID_CHK_CHRO = 107 Const ID_CHK_SPEC = 109 Const ID_FUNC_LIST = &H69 Const SAVED = "SAVED" 'Constants used for MASSLYNX.INI and VG global access. Global Const DATA_EXT = ".RAW" ' Global Const SYSPARAGRAPH = "SystemList" Const INI_FILE_SEP = "," Const PPS_BUF_SIZE = 128 Const PROC_STUB = "_PROC" Const FUNC_STUB = "_FUNC" Const DATA_FILE_EXT = "DAT" Const CMD_HISTORY = &H71 Const BROWSER_CAPTION = "Data Browser" Const HISTORY_CAPTION = "History Selector" Const ID_LB_HISTORY = 80 'Constants used by MLRawFileOpen sub-routine. 'Constants used bt MLCustSysGlobals sub-routine. Global Const AXIS_D = 0 Global Const AXIS_M = 1 Global Const AXIS_U = 2 'Constants for MassLynx program. Global Const ML_CAPTION = "MassLynx" Global Const ML_PROGRAM = "C:\MASSLYNX\MASSLYNX" 'MassLynx applictaion codes Const NUM_APPLICATIONS = 25 Global Const APP_CLI = 0 Global Const APP_SPEC = 1 Global Const APP_CHRO = 2 Global Const APP_FIND = 3 Global Const APP_QUAN = 4 Global Const APP_ACQU = 5 Global Const APP_STATUS = 6 Global Const APP_TUNE = 7 Global Const APP_MACRO = 8 Global Const APP_LOG = 9 Global Const APP_ELE = 10 Global Const APP_GLOBALS = 11 Global Const APP_LIB = 12 Global Const APP_PRES = 13 Global Const APP_READ = 14 Global Const APP_INLET = 15 Global Const APP_ASAMP = 16 Global Const APP_SCAN = 17 Global Const APP_PEP = 18 Global Const APP_MAP = 19 Global Const APP_EMBL = 20 Global Const APP_SAMPLE = 21 '*** NT messaging constants for MassLynx *** Global Const WM_GETGLOBALDIALOGWND = (WM_USER + 50) 'Sendmessage returns window handle of modeless 'dialog box, NULL if not active. 'wParam - Dialog ID code. 'lParam - Not used. Global Const WM_UPDATEINIGLOBALS = (WM_USER + 51) 'Writes MassLynx globals to INI file. 'wParam - Not used. 'lParam - Not used. Global Const WM_GETAPPLICATIONWND = (WM_USER + 52) 'Sendmessage returns window handle of MassLynx application, 'NULL if non-existant. 'wParam - Application ID (APP_???). 'lParam - Not used. Global Const GD_CHRO_INTEGRATE = 25 '**************************************************************************************** ' ' Data type declarations. ' '**************************************************************************************** '*** '*** SUPASTRING *** '*** Type SUPASTRING sz64 As String * 64 End Type '*** '*** ONEKBUFFER *** '*** Type ONEKBUFFER Buffer As String * 1024 End Type '*** '*** SINTEGER *** '*** Type SINTEGER w As Integer End Type '*** '*** SLONG *** '*** Type SLONG dw As Long End Type '*** '*** SSINGLE *** '*** Type SSINGLE f As Single End Type '*** '*** SDOUBLE *** '*** Type SDOUBLE lf As Double End Type '*** '*** SCURRENCY *** '*** Type SCURRENCY c As Currency End Type '*** '*** SCHAR *** '*** Type SCHAR Char As String * 1 End Type '*** '*** APPTYPE *** '*** Type APPTYPE hWindowHandle As Long '; /* Handle to Main Application Window */ lWindow(4) As Long '; /* Position and size of the window */ lRunning As Long '; /* Set to TRUE if Active */ nStyle As Integer '; /** Maybe SW_SHOWNORAL, SW_SHOWMINIMIZED, '*** SW_SHOWMAXIMIZED '**/ End Type '*** '*** VGFILE *** '*** MassLynx file information. '*** Type VGFILE wtype As Integer szDirectory As String * 65 szName As String * 9 szExtension As String * 4 dwEntry As Long dwSize As Long End Type '*** '*** VGRAWFILE *** '*** Same as VGFILE except function information '*** and process information is required. '*** Type VGRAWFILE lpVGFile As VGFILE wFunc As Integer wProc As Integer End Type '*** '*** RAWHEADER *** '*** Used at the RAW level of MassLynx. '*** Type RAWHEADER nVersionMajor As Integer 'Major version of file format. nVersionMinor As Integer 'Minor version of file format. szAcquName As String * 9 'Acquired filename, no extn. szAcquDate As String * 12 'Acquired date: DD-MMM-YYYY. szAcquTime As String * 9 'Acquired time: HH:MM:SS (24 hr). szJobCode As String * 9 szTaskCode As String * 9 szUserName As String * 17 szLabName As String * 33 szInstrument As String * 9 szConditions As String * 41 szSampleDesc As String * 121 'Sample description. 'szSampleDesc As String * 81 'Sample description. szSubmitter As String * 19 szSampleID As String * 15 szBottleNumber As String * 7 lfSolventDelay As Double 'Solvent delay in decimal minutes. bResolved As Integer 'TRUE if resolved data file. szPepFileName As String * 81 'Assoc pep/embl filename-inc. dir+ext. szProcess As String * 81 End Type '*** '*** DMRAWHEADER *** '*** Used at the DM level of MassLynx. '*** Type DMRAWHEADER sRawHeader As RAWHEADER wFuncsInFile As Integer wAnalogsInFile As Integer End Type '*** '*** DMRAWSTATS *** '*** Scan Statistics structure definition, at DM level. '*** Type DMRAWSTATS fLoMass As Single fHiMass As Single bMolecularMass As Integer bCalibrated As Integer 'Data is calibrated. fRT As Single 'Retention time in minutes. dwPeaksInScan As Long fTIC As Single fBPI As Single fBPM As Single wOverload As Integer bContinuum As Integer nIonMode As Integer End Type '*** '*** TRACESTATS *** '*** Collection of statistics calculated from '*** ChroStats() and SpecStats() functions. '*** - Type TRACESTATS Num As Integer Min As Single Max As Single Ave As Single SD As Single NoiseMin As Single NoiseMax As Single NoiseAve As Single NoiseSD As Single End Type '**************************************************************************************** ' ' Function declarations. ' '**************************************************************************************** Declare Function BroFileOpen Lib "util.dll" (ByVal hWnd As Long, lpsInfo As VGRAWFILE, dwFlags As Long, ByVal szTitle As String) As Integer Declare Sub DmRawClose Lib "util.dll" () Declare Function DmRawReadHeaderVB Lib "util.dll" (LPVGRAWFILE As VGRAWFILE, lpDMRawHeader As DMRAWHEADER) As Integer Declare Function DmRawReadScanStatsVB Lib "util.dll" (LPVGRAWFILE As VGRAWFILE, ByVal dwScanNumber As Long, ByVal wCalibrate As Integer, lpDmRawStats As DMRAWSTATS) As Integer Declare Function DmRawReadSpectrumVB Lib "util.dll" (LPVGRAWFILE As VGRAWFILE, ByVal dwScanNumber As Long, ByVal wCalibrate As Integer, ByVal dwStartPeak As Long, ByVal dwNumPeaks As Long, lpMass As Single, lpIntensity As Single) As Long Declare Function DmRawScansInFunction Lib "util.dll" (lpRawFile As VGRAWFILE) As Long Declare Function DmRawScanToTime Lib "util.dll" (lpRawFile As VGRAWFILE, ByVal dwScan As Long) As Single Declare Function DmRawTimeToScan Lib "util.dll" (lpRawFile As VGRAWFILE, ByVal fRetTime As Single) As Long Declare Function GetGlobalString Lib "ml_vb.dll" (ByVal szParagraph As String, ByVal szKey As String, ByVal szDefault As String, ByVal szResult As String, ByVal nMaxSize As Integer) As Integer Declare Function GetGlobalLong Lib "ml_vb.dll" (ByVal szParagraph As String, ByVal szKey As String, ByVal lDefault As Long, lResult As Long) As Integer Declare Function GetGlobalDouble Lib "ml_vb.dll" (ByVal szParagraph As String, ByVal szKey As String, lfDefault As Double, lfResult As Double) As Integer Declare Function GetGlobalFile Lib "ml_vb.dll" (ByVal szParagraph As String, ByVal szKey As String, sDefault As VGFILE, szResult As VGFILE) As Integer Declare Sub GetMassLynxWorkingDir Lib "ml_vb.dll" (ByVal lpString As String) Declare Function GetApplicationWnd Lib "ml_vb.dll" (ByVal nAppCode As Integer) As Integer Declare Function GetGlobalDialogWnd Lib "util.dll" (ByVal wDialogCode As Integer) As Integer Declare Function IsMassLynxEnabled Lib "ml_vb.dll" () As Integer Declare Function SetGlobalFile Lib "ml_vb.dll" (ByVal szParagraph As String, ByVal szKey As String, sNew As VGFILE, ByVal wAppend As Integer) As Integer '**************************************************************************************** ' ' Purpose: Routine to activate MassLynx. ' If not active it is activated/started. ' When active focus is switched to it. ' '**************************************************************************************** Function ActivateML() As Integer Dim wActivity As Integer Dim lpMLCaption As String Dim lpMLProgram As String lpMLCaption = ML_CAPTION lpMLProgram = ML_PROGRAM If ProcessActive(lpMLCaption) = False Then wActivity = Shell(lpMLProgram, 1) Do While Not ProcessActive(lpMLCaption) DoEvents Loop End If ActivateML = ProcessActive(lpMLCaption) End Function Function CBoxSelString(hWnd As Long, wID As Integer, lpSelString As String) As Integer Dim dwMsgRtn As Long Dim lpMsg As SUPASTRING lpMsg.sz64 = lpSelString + Chr$(0) dwMsgRtn = SendDlgItemMessage(hWnd, wID, CB_SELECTSTRING, -1, lpMsg) If dwMsgRtn = CB_ERR Then CBoxSelString = False Else CBoxSelString = True End If End Function '**************************************************************************************** ' ' Purpose: Provide a collection of general MassLynx functions. ' '**************************************************************************************** Function CheckMenuItem(hWnd As Long, wID As Integer, wCheck As Integer) As Integer Dim hMenu As Long Dim dwState As Long hMenu = GetMenu(hWnd) wState = GetMenuState(hMenu, wID, MF_BYCOMMAND) If Not ((wState And MF_CHECKED) = MF_CHECKED) And wCheck Then dwState = PostMessage(hWnd, WM_COMMAND, wID, 0) ElseIf ((wState And MF_CHECKED) = MF_CHECKED) And Not wCheck Then dwState = PostMessage(hWnd, WM_COMMAND, wID, 0) End If CheckMenuItem = GetMenuState(hMenu, wID, MF_BYCOMMAND) End Function '**************************************************************************************** ' ' Purpose: Convert strings into SendKeys format. ' '**************************************************************************************** Function Conv4SK(lpStringToCheck As String) As String Dim wCharPos As Integer Dim lpCharToCheck As String Dim lpConvertedString As String lpConvertedString = "" For wCharPos = 1 To Len(lpStringToCheck) lpCharToCheck = Right$(Left$(lpStringToCheck, wCharPos), 1) If lpCharToCheck = "+" Then lpCharToCheck = "{+}" End If lpConvertedString = lpConvertedString + lpCharToCheck Next wCharPos Conv4SK = lpConvertedString End Function '**************************************************************************************** ' ' Purpose: Copy buffer of record to current record in table. ' Buffer should be allocated,locked and filled to obtain start address. ' Make sure size of record is known. ' '**************************************************************************************** Sub CpyBuffToDBRec(tbl As Table, dwBuffStart As Long, lpFdSize() As Long) Dim wFdNum As Integer Dim wNumFds As Integer Dim dwBuffOS As Long Dim lpStr As String Dim lpsInt As SINTEGER Dim lpsLng As SLONG Dim lpsSng As SSINGLE Dim lpsDbl As SDOUBLE Dim lpsCur As SCURRENCY Dim lpsChr As SCHAR On Error GoTo ReadBuffError tbl.Edit dwBuffOS = 0 wEndFd = UBound(lpFdSize) For wFdNum = 0 To wEndFd Select Case tbl.Fields(wFdNum).Type Case DB_BOOLEAN, DB_BYTE, DB_INTEGER Call hmemcpyTolp(lpsInt, (dwBuffStart + dwBuffOS), lpFdSize(wFdNum)) tbl.Fields(wFdNum).Value = lpsInt.w Case DB_LONG Call hmemcpyTolp(lpsLng, (dwBuffStart + dwBuffOS), lpFdSize(wFdNum)) tbl.Fields(wFdNum).Value = lpsLng.dw Case DB_CURRENCY Call hmemcpyTolp(lpsCur, (dwBuffStart + dwBuffOS), lpFdSize(wFdNum)) tbl.Fields(wFdNum).Value = lpsCur.c Case DB_SINGLE Call hmemcpyTolp(lpsSng, (dwBuffStart + dwBuffOS), lpFdSize(wFdNum)) tbl.Fields(wFdNum).Value = lpsSng.f Case DB_DOUBLE, DB_DATE Call hmemcpyTolp(lpsDbl, (dwBuffStart + dwBuffOS), lpFdSize(wFdNum)) tbl.Fields(wFdNum).Value = lpsDbl.lf Case DB_STRING, DB_TEXT, DB_LONGBINARY, DB_MEMO Call CpyBuffToStr(lpStr, (dwBuffStart + dwBuffOS), lpFdSize(wFdNum)) tbl.Fields(wFdNum).Value = lpStr End Select Debug.Print tbl.Fields(wFdNum).Value dwBuffOS = dwBuffOS + lpFdSize(wFdNum) Next wFdNum tbl.Update Exit Sub ReadBuffError: On Error GoTo 0 Resume Next End Sub '**************************************************************************************** ' ' Purpose: Copy from hmem to a string lpStr. ' lpStr is will be initialised to an empty string. ' '**************************************************************************************** Sub CpyBuffToStr(lpStr As String, dwBuffStart As Long, dwBytes As Long) Dim dwByte As Long Dim dwBuffByte As Long Dim lpsChar As SCHAR lpStr = Space$(0) If dwBytes > 0 Then For dwByte = 0 To dwBytes - 1 dwBuffByte = dwBuffStart + dwByte Call hmemcpyTolp(lpsChar, dwBuffByte, 1) lpStr = lpStr & lpsChar.Char Next dwByte End If End Sub '**************************************************************************************** ' ' Purpose: Copy one record to another inside a data base table. ' '**************************************************************************************** Sub CpyDBRec(tbl As Table, dwRecOrig As Long, dwRecDest As Long) Dim hBuff As Long Dim wRtn As Integer Dim lpFdSize() As Long Dim dwBuffSize As Long Dim dwBuffStart As Long If SetDBRec(tbl, dwRecOrig) Then dwBuffSize = RecSize(tbl, lpFdSize()) hBuff = GlobalAlloc(GMEM_FIXED + GMEM_ZEROINIT, dwBuffSize) dwBuffStart = GlobalLock(hBuff) Call CpyDBRecToBuff(tbl, dwBuffStart, lpFdSize()) If SetDBRec(tbl, dwRecDest) Then Call CpyBuffToDBRec(tbl, dwBuffStart, lpFdSize()) End If wRtn = GlobalUnlock(hBuff) wRtn = GlobalFree(hBuff) End If End Sub '**************************************************************************************** ' ' Purpose: Copy current record from table to the supplied buffer. ' Buffer should be allocated and locked to obtain start address. ' Make sure size of record is known. ' '**************************************************************************************** Sub CpyDBRecToBuff(tbl As Table, dwBuffStart As Long, lpFdSize() As Long) Dim wFdNum As Integer Dim wNumFds As Integer Dim dwBuffOS As Long Dim lpStr As String Dim lpsInt As SINTEGER Dim lpsLng As SLONG Dim lpsSng As SSINGLE Dim lpsDbl As SDOUBLE Dim lpsCur As SCURRENCY Dim lpsChr As SCHAR dwBuffOS = 0 wEndFd = UBound(lpFdSize) For wFdNum = 0 To wEndFd Debug.Print wFdNum, tbl.Fields(wFdNum).Value If Not IsNull(tbl.Fields(wFdNum).Value) Then Select Case tbl.Fields(wFdNum).Type Case DB_BOOLEAN, DB_BYTE, DB_INTEGER lpsInt.w = tbl.Fields(wFdNum).Value Call hmemcpyFromLp((dwBuffStart + dwBuffOS), lpsInt, lpFdSize(wFdNum)) Case DB_LONG lpsLng.dw = tbl.Fields(wFdNum).Value Call hmemcpyFromLp((dwBuffStart + dwBuffOS), lpsLng, lpFdSize(wFdNum)) Case DB_CURRENCY lpsCur.c = tbl.Fields(wFdNum).Value Call hmemcpyFromLp((dwBuffStart + dwBuffOS), lpsCur, lpFdSize(wFdNum)) Case DB_SINGLE lpsSng.f = tbl.Fields(wFdNum).Value Call hmemcpyFromLp((dwBuffStart + dwBuffOS), lpsSng, lpFdSize(wFdNum)) Case DB_DOUBLE, DB_DATE lpsDbl.lf = tbl.Fields(wFdNum).Value Call hmemcpyFromLp((dwBuffStart + dwBuffOS), lpsDbl, lpFdSize(wFdNum)) Case DB_STRING, DB_TEXT, DB_LONGBINARY, DB_MEMO lpStr = tbl.Fields(wFdNum).Value Call CpyStrToBuff(lpStr, (dwBuffStart + dwBuffOS)) End Select End If dwBuffOS = dwBuffOS + lpFdSize(wFdNum) Next wFdNum End Sub '**************************************************************************************** ' ' Purpose: Copies the field to buffer at dwDest. ' dwDest must be allocated and locked. ' The return value is the number of bytes copied. ' '**************************************************************************************** Function CpyFieldToMem(fdField As Field, dwDest As Long) As Integer Dim wInt As Integer Dim dwLng As Long Dim dwBytes As Long Dim fSng As Single Dim dfDbl As Double Dim lpStr As ONEKBUFFER dwBytes = fdField.Size Select Case fdField.Type Case DB_BOOLEAN wInt = fdField.Value Call hmemcpyFromLp(dwDest, wInt, fdField.Size) CpyFieldToMem = False Case DB_BYTE wInt = fdField.Value Call hmemcpyFromLp(dwDest, wInt, fdField.Size) CpyFieldToMem = False Case DB_INTEGER wInt = fdField.Value Call hmemcpyFromLp(dwDest, wInt, fdField.Size) CpyFieldToMem = fdField.Size Case DB_LONG dwLng = fdField.Value Call hmemcpyFromLp(dwDest, dwLong, fdField.Size) CpyFieldToMem = fdField.Size Case DB_CURRENCY dwDbl = fdField.Value Call hmemcpyFromLp(dwDest, dwLong, fdField.Size) CpyFieldToMem = fdField.Size Case DB_SINGLE fSng = fdField.Value Call hmemcpyFromLp(dwDest, fSng, fdField.Size) CpyFieldToMem = fdField.Size Case DB_DOUBLE dfDbl = fdField.Value Call hmemcpyFromLp(dwDest, dwDbl, fdField.Size) CpyFieldToMem = fdField.Size Case DB_DATE lpStr.Buffer = fdField.Value Call hmemcpyFromLp(dwDest, lpStr, fdField.Size) CpyFieldToMem = fdField.Size Case DB_TEXT lpStr.Buffer = fdField.Value Call hmemcpyFromLp(dwDest, lpStr, fdField.Size) CpyFieldToMem = fdField.Size Case DB_LONGBINARY lpStr.Buffer = fdField.Value Call hmemcpyFromLp(dwDest, lpStr, fdField.Size) CpyFieldToMem = fdField.Size Case DB_MEMO lpStr.Buffer = fdField.Value Call hmemcpyFromLp(dwDest, lpStr, fdField.Size) CpyFieldToMem = fdField.Size Case Else CpyFieldToMem = False End Select End Function '**************************************************************************************** ' ' Purpose: Copy from string lpStr to a hmem buffer. ' Buffer must be allocated and locked. ' '**************************************************************************************** Sub CpyStrToBuff(lpStr As String, dwBuffStart As Long) Dim dwByte As Long Dim dwBytes As Long Dim lpsChar As SCHAR dwBytes = Len(lpStr) If dwBytes > 0 Then For dwByte = 1 To dwBytes lpsChar.Char = Mid$(lpStr, dwByte, 1) Call hmemcpyFromLp((dwBuffStart + dwByte - 1), lpsChar, 1) Next dwByte End If End Sub '---------------------------------------------------------------------------------------- ' ' Process: DataBrowserChroSpec ' ' Author: Roberto Raso ' Date: 28th April 1995 ' ' Purpose: Sets the Chromatogram and/or Spectrum check boxes in the Data Browser. ' ' Parameters: sVGRawFile holds the raw file and process that should be opened. ' hBrowser is the handle of the Data Browser dialogue box. If it ' is zero then the function assumes that the function is being called ' in a standalone mode and will set the sVGRawFile as the current raw file, ' otherwise it assumes the current raw file has been set and Data Browser ' is already open. ' ' Return: Returns nChroSpec or GEN_ERROR if there is an error. ' '---------------------------------------------------------------------------------------- Function DataBrowserChroSpec(hBrowser As Long, nChroSpec As Integer) As Integer Dim hThisBrowser As Long Dim nChroSpecSet As Long nChroSpecSet = GEN_ERROR hThisBrowser = hBrowser If hThisBrowser = 0 Then hThisBrowser = DataBrowserShow() End If If hThisBrowser Then nChroSpecSet = 0 If (nChroSpec And CHRO_OPEN) = CHRO_OPEN Then Call CheckDlgButton(hThisBrowser, ID_CHK_CHRO, True) nChroSpecSet = CHRO_OPEN Else Call CheckDlgButton(hThisBrowser, ID_CHK_CHRO, False) End If If (nChroSpec And SPEC_OPEN) = SPEC_OPEN Then Call CheckDlgButton(hThisBrowser, ID_CHK_SPEC, True) nChroSpecSet = nChroSpecSet + SPEC_OPEN Else Call CheckDlgButton(hThisBrowser, ID_CHK_SPEC, False) End If If hBrowser = 0 Then If DlgBoxClose(hThisBrowser, IDOK, CDbl(CVDate("00:00:10"))) Then DataBrowserChroSpec = nChroSpecSet End If Else DataBrowserChroSpec = nChroSpecSet End If End If End Function '---------------------------------------------------------------------------------------- ' ' Process: DataBrowserShow ' ' Author: Roberto Raso ' Date: 28th April 1995 ' ' Purpose: Displays the MassLynx data browser dialogue box. ' ' Parameters: None. ' ' Return: The window handle of the dialogue box, if it has been found. ' '---------------------------------------------------------------------------------------- Function DataBrowserShow() As Integer Dim hMassLynx As Long Dim hBrowser As Long hBrowser = 0 hMassLynx = MLAppActive(APP_CLI) If hMassLynx Then hBrowser = MnuDlg_Disp(hMassLynx, IDM_FILE_NEW, BROWSER_CAPTION, 10, True) End If DataBrowserShow = hBrowser End Function '---------------------------------------------------------------------------------------- ' ' Process: DataFileExists ' ' Author: Roberto Raso ' Date: 26th April 1995 ' ' Purpose: Checks to see if a required function/process number actually exists. ' ' Parameters: sVGFile is the VG file to check. ' nData is the number of the required file. ' strDataStub is the prefix for the data file e.g. _PROC or _FUNC. ' strDataExt is the file extension for the required data file. e.g. DAT. ' ' Return: Returns the data file number or GEN_ERROR if the file does not exist. ' '---------------------------------------------------------------------------------------- Function DataFileExists(sVGFile As VGFILE, nData As Integer, strDataStub As String, strDataExt As String) As Integer Dim nDataFile As Integer Dim nDataFiles As Integer Dim strRawFile As String Dim strDataFile As String Dim aszDataFile() As String * 16 DataFileExists = GEN_ERROR strRawFile = SZToVB(sVGFile.szDirectory) + SZToVB(sVGFile.szName) nDataFiles = GetRawProcessFiles(strRawFile, aszDataFile(), strDataStub, strDataExt) For nDataFile = 0 To nDataFiles - 1 strDataFile = TrimWS(aszDataFile(nDataFile)) strDataFile = MidStr(strDataFile, Len(strDataStub) + 1, Len(strDataFile) - (Len(strDataExt) + 1)) If CInt(strDataFile) = nData Then DataFileExists = nData Exit For End If Next nDataFile End Function '---------------------------------------------------------------------------------------- ' ' Process: DataProcessSelect ' ' Author: Roberto Raso ' Date: 28th April 1995 ' ' Purpose: Opens the required file, function and/or process. ' ' Parameters: sVGRawFile holds the raw file and process that should be opened. ' hBrowser is the handle of the Data Browser dialogue box. If it ' is zero then the function assumes that the function is being called ' in a standalone mode and will set the sVGRawFile as the current raw file, ' otherwise it assumes the current raw file has been set and Data Browser ' is already open. ' ' Return: Returns the function number or GEN_ERROR if the file does not exist. ' '---------------------------------------------------------------------------------------- Function DataFunctionSelect(sVGRawFile As VGRAWFILE, hBrowser As Long) As Integer Dim hThisBrowser As Long Dim hCtrl As Long Dim nFuncs As Integer Dim lMsgRtn As Long DataFunctionSelect = GEN_ERROR hThisBrowser = hBrowser If hThisBrowser = 0 Then If SetGlobalFile(SYSPARAGRAPH, "RAW" + Chr$(0), sVGRawFile.lpVGFile, True) = 0 Then Exit Function Else hThisBrowser = DataBrowserShow() End If End If If IsWindow(hThisBrowser) Then nFuncs = CInt(SendDlgItemMessage(DataBrowserShow(), ID_FUNC_LIST, CB_GETCOUNT, 0, 0)) If sVGRawFile.wFunc <= nFuncs Then If CInt(SendDlgItemMessage(DataBrowserShow(), ID_FUNC_LIST, CB_SETCURSEL, ByVal (sVGRawFile.wFunc - 1), 0)) = sVGRawFile.wFunc - 1 Then hCtrl = GetDlgItem(DataBrowserShow(), ID_FUNC_LIST) lMsgRtn = SendMessage(DataBrowserShow(), WM_COMMAND, ID_FUNC_LIST, MakeLong(CBN_SELCHANGE, hCtrl)) DataFunctionSelect = sVGRawFile.wFunc End If End If If hBrowser = 0 Then If DlgBoxClose(hThisBrowser, IDOK, CDbl(CVDate("00:00:10"))) Then DataFunctionSelect = sVGRawFile.wFunc Else DataFunctionSelect = GEN_ERROR End If End If End If End Function '---------------------------------------------------------------------------------------- ' ' Process: DataProcessSelect ' ' Author: Roberto Raso ' Date: 25th April 1995 ' ' Purpose: Opens the required file, function and/or process. ' ' Parameters: sVGRawFile holds the raw file and process that should be opened. ' hBrowser is the handle of the Data Browser dialogue box. If it ' is zero then the function assumes that the function is being called ' in a standalone mode and will set the sVGRawFile as the current raw file, ' otherwise it assumes the current raw file has been set and Data Browser ' is already open. ' ' Return: Returns the process number or GEN_ERROR if the file does not exist. ' '---------------------------------------------------------------------------------------- Function DataProcessSelect(sVGRawFile As VGRAWFILE, hBrowser As Long) As Integer Dim bSaved As Integer Dim hThisBrowser As Long Dim hHistory As Long Dim nProcFound As Integer Dim nProc As Integer Dim nProcs As Integer Dim nText As Integer Dim lMsgRtn As Long Dim strText As String DataProcessSelect = GEN_ERROR bSaved = False hThisBrowser = hBrowser If hThisBrowser = 0 Then If SetGlobalFile(SYSPARAGRAPH, "RAW" + Chr$(0), sVGRawFile.lpVGFile, True) = 0 Then Exit Function Else hThisBrowser = DataBrowserShow() End If End If If IsWindow(hThisBrowser) Then hHistory = MnuDlg_Disp(hThisBrowser, CMD_HISTORY, HISTORY_CAPTION, 10, True) If hHistory Then nProcs = CInt(SendDlgItemMessage(hHistory, ID_LB_HISTORY, LB_GETCOUNT, 0, 0)) For nProc = 0 To nProcs - 1 nProcFound = LoWord(SendDlgItemMessage(hHistory, ID_LB_HISTORY, LB_GETITEMDATA, ByVal nProc, 0)) If nProcFound = sVGRawFile.wProc Then nText = CInt(SendDlgItemMessage(hHistory, ID_LB_HISTORY, LB_GETTEXTLEN, ByVal nProc, 0)) strText = String$(nText + 1, 0) nText = CInt(SendDlgItemMessage(hHistory, ID_LB_HISTORY, LB_GETTEXT, ByVal nProc, ByVal strText)) If InStr(1, strText, SAVED, 1) Then bSaved = True nProc = CInt(SendDlgItemMessage(hHistory, ID_LB_HISTORY, LB_SETCURSEL, ByVal nProc, 0)) Exit For End If End If Next nProc End If End If If bSaved Then lMsgRtn = PostMessage(hHistory, WM_COMMAND, IDOK, 0) DataProcessSelect = nProcFound Else lMsgRtn = PostMessage(hHistory, WM_COMMAND, IDCANCEL, 0) End If Do While IsWindow(hHistory) DoEvents Loop End Function '**************************************************************************************** ' ' Purpose: Idle loop for wDelay seconds. ' '**************************************************************************************** Sub Delay(wDelay As Integer) Dim wEndWait As Integer Dim wWait As Integer Dim lpEntryTime As Variant lpEntryTime = Now wEndWait = False Do Until wWait >= wDelay wWait = Second(Now - lpEntryTime) DoEvents Loop End Sub '**************************************************************************************** ' ' Purpose: Checks that the specified function in the raw file, is valid. ' Return value is TRUE/FALSE. ' '**************************************************************************************** Function DMVerifyFunction(lpFile As String, wFunc As Integer, lpRawFile As VGRAWFILE) As Integer Dim wFuncOK As Long Dim lpRawHeader As DMRAWHEADER Dim lpsDebug As String Dim lpsTemp As String wFuncOK = True If GetMLFileInfo("RAW", lpRawFile.lpVGFile) Then lpRawFile.lpVGFile.szName = Trim$(lpFile) + Chr$(0) Else wFuncOK = False End If 'lpsDebug = SZToVB(lpRawFile.lpVGFile.szDirectory) + " : " + CStr(InStr(lpRawFile.lpVGFile.szDirectory, Chr$(0))) + Chr$(13) + Chr$(10) 'lpsDebug = lpsDebug + SZToVB(lpRawFile.lpVGFile.szName) + " : " + CStr(InStr(lpRawFile.lpVGFile.szName, Chr$(0))) + Chr$(13) + Chr$(10) 'lpsDebug = lpsDebug + SZToVB(lpRawFile.lpVGFile.szExtension) + " : " + CStr(InStr(lpRawFile.lpVGFile.szExtension, Chr$(0))) + Chr$(13) + Chr$(10) 'MsgBox lpsDebug If DmRawReadHeaderVB(lpRawFile, lpRawHeader) Then If wFunc > 0 And wFunc <= lpRawHeader.wFuncsInFile Then lpRawFile.wFunc = wFunc Else wFuncOK = False End If Else wFuncOK = False End If DMVerifyFunction = wFuncOK End Function '**************************************************************************************** ' ' Purpose: Checks that the specified retention time in the required function ' of the raw file, is valid. ' Return value is scan number. ' '**************************************************************************************** Function DMVerifyRT(lpFile As String, wFunc As Integer, fTime As Single, lpRawFile As VGRAWFILE) As Long Dim wFuncOK As Long wFuncOK = True If DMVerifyFunction(lpFile, wFunc, lpRawFile) Then wFuncOK = DmRawTimeToScan(lpRawFile, fTime) Else wFuncOK = False End If DMVerifyRT = wFuncOK End Function '**************************************************************************************** ' ' Purpose: Checks that the specified scan in the required function ' of the raw file. ' '**************************************************************************************** Function DMVerifyScan(lpFile As String, wFunc As Integer, dwScan As Long, lpRawFile As VGRAWFILE) As Long Dim wFuncOK As Long wFuncOK = True If DMVerifyFunction(lpFile, wFunc, lpRawFile) Then If dwScan > 0 And dwScan <= DmRawScansInFunction(lpRawFile) Then wFuncOK = dwScan Else wFuncOK = False End If Else wFuncOK = False End If DMVerifyScan = wFuncOK End Function '**************************************************************************************** ' ' Purpose: Fill a VGRAWFILE file structure. ' wFunc must be a valid function for file. ' Returns TRUE if operation was successful. ' '**************************************************************************************** Function FileToRawFile(lpFile As String, wFunc As Integer, lpRawFile As VGRAWFILE) As Integer If DMVerifyFunction(lpFile, wFunc, lpRawFile) Then FileToRawFile = True Else FileToRawFile = False End If End Function '**************************************************************************************** ' ' Process: GetMLFile ' ' Author: Roberto Raso ' Date: 19th September 1994 ' ' Purpose: Get the whole file descriptor for a MassLynx ' global file i.e. Path, name and extension. ' Return: String of file information ' '**************************************************************************************** Function GetMLFile(lpFileType As String) As String GetMLFile = GetMLFileDir(lpFileType) + GetMLFileName(lpFileType) + DOS_EXT_SEP + GetMLFileExt(lpFileType) End Function Function GetMLFileDir(FileType As String) As String 'Returns the current directory that MassLynx is using, for FileType. Dim MLFile As VGFILE If GetMLFileInfo(FileType, MLFile) = True Then GetMLFileDir = Left$(MLFile.szDirectory, InStr(MLFile.szDirectory, Chr$(0)) - 1) Else GetMLFileDir = "" End If End Function Function GetMLFileEntry(FileType As String) As Long 'Returns the current entry number that MassLynx is using, for FileType. Dim MLFile As VGFILE If GetMLFileInfo(FileType, MLFile) = True Then GetMLFileEntry = MLFile.dwEntry Else GetMLFileEntry = 0 End If End Function Function GetMLFileExt(FileType As String) As String 'Returns the current extension that MassLynx is using, for FileType. Dim MLFile As VGFILE If GetMLFileInfo(FileType, MLFile) = True Then GetMLFileExt = Left$(MLFile.szExtension, InStr(MLFile.szExtension, Chr$(0)) - 1) Else GetMLFileExt = "" End If End Function Function GetMLFileInfo(FileType As String, MLFileInfo As VGFILE) As Integer 'Gets MassLynx file information into VGFILE type. 'Set MLFileInfo before calling GetMLFileInfo. Dim ReturnStatus As Integer Dim ListDefault As VGFILE ListDefault.wtype = 0 ListDefault.szDirectory = "" ListDefault.szName = "" ListDefault.szExtension = "" ListDefault.dwEntry = 0 ListDefault.dwSize = 0 ReturnStatus = GetGlobalFile(SYSPARAGRAPH, FileType, ListDefault, MLFileInfo) If ReturnStatus = 1 Then GetMLFileInfo = True Else GetMLFileInfo = False End If End Function Function GetMLFileName(FileType As String) As String 'Returns the current filename that MassLynx is using, for FileType. Dim MLFile As VGFILE If GetMLFileInfo(FileType, MLFile) = True Then GetMLFileName = Left$(MLFile.szName, InStr(MLFile.szName, Chr$(0)) - 1) Else GetMLFileName = "" End If End Function '**************************************************************************************** ' ' Process: GetMLFileSize ' ' Author: Roberto Raso ' Date: 18th August 1994 ' ' Purpose: Get the number of entries in a file. ' Return: Number of entries. ' '**************************************************************************************** Function GetMLFileSize(lpFileType As String) As Long Dim lpMLFile As VGFILE If GetMLFileInfo(lpFileType, lpMLFile) = True Then GetMLFileSize = lpMLFile.dwSize Else GetMLFileSize = 0 End If End Function Function GetMLIniFileInfo(lpSection As String, lpEntry As String, lpFileInfo As VGFILE, lpMLIniFile As String) As Integer Dim nStartPos As Integer Dim nEndPos As Integer Dim lpReturn As String * 128 If GetPrivateProfileString(lpSection, ByVal lpEntry, "", lpReturn, PPS_BUF_SIZE, lpMLIniFile) Then nStartPos = 1 nEndPos = InStr(nStartPos, lpReturn, INI_FILE_SEP) lpFileInfo.wtype = CInt(Mid$(lpReturn, nStartPos, nEndPos - nStartPos)) nStartPos = nEndPos + 1 nEndPos = InStr(nStartPos, lpReturn, INI_FILE_SEP) lpFileInfo.szDirectory = Mid$(lpReturn, nStartPos, nEndPos - nStartPos) + Chr$(0) nStartPos = nEndPos + 1 nEndPos = InStr(nStartPos, lpReturn, INI_FILE_SEP) lpFileInfo.szName = Mid$(lpReturn, nStartPos, nEndPos - nStartPos) + Chr$(0) nStartPos = nEndPos + 1 nEndPos = InStr(nStartPos, lpReturn, INI_FILE_SEP) lpFileInfo.szExtension = Mid$(lpReturn, nStartPos, nEndPos - nStartPos) + Chr$(0) nStartPos = nEndPos + 1 nEndPos = InStr(nStartPos, lpReturn, INI_FILE_SEP) lpFileInfo.dwEntry = CLng(Mid$(lpReturn, nStartPos, nEndPos - nStartPos)) nStartPos = nEndPos + 1 nEndPos = InStr(nStartPos, lpReturn, Chr$(0)) lpFileInfo.dwSize = CLng(Mid$(lpReturn, nStartPos, nEndPos - nStartPos)) GetMLIniFileInfo = True Else GetMLIniFileInfo = False End If End Function '**************************************************************************************** ' ' Purpose: Get the current process files for the MassLynx raw file ' lpRawFile. The files found are written to lpProcessFile(). ' The return is the number of files found. ' lpRawFile must include directory but not extension. ' '**************************************************************************************** Function GetRawProcessFiles(lpRawFile As String, lpProcessFile() As String * 16, lpProcStub As String, lpProcExt As String) As Integer Dim wNumProcs As Integer Dim lpSearchPath As String lpSearchPath = Trim$(lpRawFile) + DOS_EXT_SEP + GetMLFileExt("RAW") + DOS_DIR_SEP + lpProcStub + "*" + DOS_EXT_SEP + lpProcExt wNumProcs = FileSearch(lpSearchPath, lpProcessFile()) GetRawProcessFiles = wNumProcs End Function '**************************************************************************************** ' ' Purpose: Gets the list of printers that are available ' to a Windows for WorkGroups Node/PC. ' lpWinIniFile can be a remote PC's WIN.INI file. ' lpzPrinters() is the array fo zero terminated strings to fill. ' The return value is the number of printers listed. ' '**************************************************************************************** Function GetWrkGrpPrinters(lpWinIniFile As String, lpzPrinters() As String * 64) As Integer Dim wNumPrinters As Integer Dim wPrinter As Integer Dim wPrinterLen As Integer Dim lpPrinterCode As String Dim lpPrinter As String * 64 Dim lpOrder As String * 64 wNumPrinters = GetPrivateProfileString("MRU_Printers", ByVal "Order", "", lpOrder, Len(lpOrder), lpWinIniFile) If wNumPrinters Then ReDim lpzPrinters(wNumPrinters - 1) For wPrinter = 1 To wNumPrinters lpPrinterCode = Mid$(lpOrder, wPrinter, 1) wPrinterLen = GetPrivateProfileString("MRU_Printers", ByVal lpPrinterCode, "", lpPrinter, Len(lpPrinter), lpWinIniFile) lpzPrinters(wPrinter - 1) = Left$(lpPrinter, wPrinterLen) + Chr$(0) Next wPrinter End If GetWrkGrpPrinters = wNumPrinters End Function '**************************************************************************************** ' ' Purpose: Returns the value of the High order word ' of a long integer. ' '**************************************************************************************** Function HiWord(dwLong As Long) As Integer HiWord = dwLong / &H10000 End Function '**************************************************************************************** ' ' Purpose: Returns the last process file that was generated, ' for the raw file lpRawFile. ' lpRawFile must include directory, but no extension. ' The return value is the process number, zero if there are no processes. ' '**************************************************************************************** Function LastRawProcess(lpRawFile As String) As Integer Dim w1stFile As Integer Dim wLstFile As Integer Dim wFile As Integer Dim wYoungest As Integer Dim wNumFiles As Integer Dim lpWholeFile As String Dim lpCurFile As String Dim lpRawExt As String Dim lpProcStub As String Dim lpProcExt As String Dim lpProc As String Dim lpProcessFile() As String * 16 lpRawExt = GetMLFileExt("RAW") lpProcStub = "_PROC" lpProcExt = "DAT" lpWholeFile = Trim$(lpRawFile) + DOS_EXT_SEP + lpRawExt If FileExists(lpWholeFile) Then wNumFiles = GetRawProcessFiles(lpRawFile, lpProcessFile(), lpProcStub, lpProcExt) If wNumFiles Then lpRawExt = DOS_EXT_SEP + lpRawExt + DOS_DIR_SEP w1stFile = LBound(lpProcessFile) wLstFile = UBound(lpProcessFile) wYoungest = w1stFile For wFile = w1stFile To wLstFile If FileDateTime(lpRawFile + lpRawExt + Trim$(lpProcessFile(wFile))) > FileDateTime(lpRawFile + lpRawExt + Trim$(lpProcessFile(wYoungest))) Then wYoungest = wFile End If Next lpProc = Left$(lpProcessFile(wYoungest), InStr(1, lpProcessFile(wYoungest), DOS_EXT_SEP) - 1) lpProc = Right$(lpProc, Len(lpProc) - Len(lpProcStub)) LastRawProcess = CInt(lpProc) Else LastRawProcess = 0 End If Else LastRawProcess = 0 End If End Function Function LBoxSelString(hWnd As Long, wID As Integer, lpSelString As String) As Integer Dim hLBox As Long Dim dwMsgRtn As Long hLBox = DlgItemValidate(hWnd, wID) If hLBox <> 0 Then dwMsgRtn = SendMessageAPI(hLBox, LB_FINDSTRING, -1, ByVal lpSelString) dwMsgRtn = SendMessage(hLBox, LB_SETSEL, -1, dwMsgRtn) Else dwMsgRtn = LB_ERR End If If dwMsgRtn = LB_ERR Then LBoxSelString = False Else LBoxSelString = True End If End Function '**************************************************************************************** ' ' Purpose: Returns the value of the Low order word ' of a long integer. ' '**************************************************************************************** Function LoWord(dwLong As Long) As Integer LoWord = dwLong - HiWord(dwLong) * &H10000 End Function '**************************************************************************************** ' ' Purpose: Combines two integers to give one long. ' '**************************************************************************************** Function MakeLong(wHiWord As Integer, wLoWord As Integer) As Long Dim dwHigh As Long Dim dwLow As Long dwHigh = wHiWord * &H10000 dwLow = CLng(wLoWord) And &HFFFF MakeLong = dwHigh Or dwLow End Function '**************************************************************************************** ' ' Purpose: Returns the window handle for MassLynx. ' '**************************************************************************************** Function MassLynxhWnd() As Long MassLynxhWnd = MLAppActive(APP_CLI) End Function '**************************************************************************************** ' ' Purpose: Displays File menu bar. ' Only if Alt+F is valid. ' '**************************************************************************************** Sub mbFile() SendKeys "%F", True DoEvents End Sub '**************************************************************************************** ' ' Purpose: Exit the current application. ' No file checking is carried out. ' mbFile and "X" must be valid for application. ' '**************************************************************************************** Sub mbFileExit() mbFile SendKeys "X", True DoEvents End Sub '**************************************************************************************** ' ' Purpose: New file for current application. ' No file checking is carried out. ' File must be saved as. ' mbFile and "N" must be valid for application. ' '**************************************************************************************** Sub mbFileNew() mbFile SendKeys "N", True DoEvents End Sub '**************************************************************************************** ' ' Purpose: Open an existing file. ' No file checking is carried out. ' lpFileToOpen can include directory etc. ' mbFile and "O" must be valid for application. ' '**************************************************************************************** Sub mbFileOpen(lpFileToOpen As String) mbFile SendKeys "O", True DoEvents SendKeys Trim$(lpFileToOpen), True SendKeys "{ENTER}", True DoEvents End Sub '**************************************************************************************** ' ' Purpose: Checks to see if a MassLynx application is active. ' wMLApplication is MassLynx application code. ' The return value is the window handle if the ' process is active. ' '**************************************************************************************** Function MLAppActive(wMLApplication As Integer) As Long MLAppActive = GetApplicationWnd(wMLApplication) End Function '**************************************************************************************** ' ' Purpose: Set the global default display, file access and Spec-Chro link. ' From the MassLynx top menu bar. ' '**************************************************************************************** Sub MLCustSysGlobals(Scan As Integer, UseAcquFile As Integer, Axis As Integer) 'Scan is either True or False. 'True=Use scan numbers to get scans in Spectrum. 'False=Use retention times to get scans in Spectrum. 'UseAcquFile is either True or False. 'True=Use the current acquired data file as default with Process Spectrum/Chromatogram. 'False=Use the last used data file as default with Process Spectrum/Chromatogram. 'DaPere is either True or False. 'AXIS_D=Display Spectrum mass scale as Daltons/Fundamental Charge. 'AXIS_M=Display Spectrum as Mass/Charge. 'AXIS_U=Display Spectrum as the un-SI unit/Fundamental Charge AppActivate "MassLynx" SendKeys "%C", True DoEvents SendKeys "{DOWN 6}{ENTER}", True DoEvents If Scan Then SendKeys "{UP}", True Else SendKeys "{DOWN}", True End If SendKeys "{TAB}", True 'Move to Use Acquired file. If UseAcquFile Then SendKeys "{+}", True Else SendKeys "-", True End If SendKeys "{UP}", True 'Move to Axes label. Select Case Axis Case AXIS_D SendKeys "D", True Case AXIS_M SendKeys "M", True Case AXIS_U SendKeys "U", True End Select SendKeys "{ENTER}", True DoEvents End Sub '________________________________________________________________________________________ ' ' Process: MLFilesList ' ' Author: Roberto Raso ' Date: 12th May 1995 ' ' Purpose: Gets a list of current MassLynx files, of the required type. ' ' Parameters: strFileType is the type of MassLynx file required e.g. TUNE_DB. ' astrMLFile() is an array that will hold the list of files. ' ' Return: The number of files found. '________________________________________________________________________________________ Function MLFilesList(strFileType As String, astrMLFile() As String) As Integer Dim nFile As Integer Dim nFiles As Integer Dim nDirSepPos As Integer Dim strSearch As String Dim sVGFile As VGFILE Dim astrDOSFile() As String * 16 If GetMLFileInfo(strFileType, sVGFile) Then strSearch = SZToVB(sVGFile.szDirectory) + "*." + SZToVB(sVGFile.szExtension) nFiles = FileSearch(strSearch, astrDOSFile()) If nFiles = 0 Then MLFilesList = 0 Exit Function End If ReDim astrMLFile(nFiles - 1) For nFile = 0 To nFiles - 1 nDirSepPos = InStr(astrDOSFile(nFile), ".") If nDirSepPos Then astrMLFile(nFile) = Left$(astrDOSFile(nFile), nDirSepPos - 1) End If Next nFile End If MLFilesList = nFile End Function '**************************************************************************************** ' ' Purpose: Open a MassLynx raw data file. ' '**************************************************************************************** Sub MLRawFileOpen(lpRawFile As String, wProcesses As Integer) Dim hWndML As Long Dim hWndDB As Long Dim hCtrl As Long Dim dwMsgRtn As Long hWndML = ActivateML() dwMsgRtn = PostMessage(hWndML, WM_COMMAND, IDM_FILE_NEW, 0) hWndDB = WaitForProcessStart("Data Browser", 10) If hWndDB Then hCtrl = GetDlgItem(hWndDB, 1152) 'Filename dwMsgRtn = SendMessageText(hCtrl, lpRawFile) If (wProcesses And CHRO_OPEN) = CHRO_OPEN Then Call CheckDlgButton(hWndDB, 107, True) Else Call CheckDlgButton(hWndDB, 107, False) End If If (wProcesses And SPEC_OPEN) = SPEC_OPEN Then Call CheckDlgButton(hWndDB, 109, True) Else Call CheckDlgButton(hWndDB, 109, False) End If dwMsgRtn = PostMessage(hWndDB, WM_COMMAND, IDOK, 0) End If If (wProcesses And CHRO_OPEN) = CHRO_OPEN Then CHRO End If If (wProcesses And SPEC_OPEN) = SPEC_OPEN Then SPEC End If End Sub '**************************************************************************************** ' ' Purpose: Pauses the print manager. ' '**************************************************************************************** Function PausePrintManager(wPause As Integer) As Integer Dim hPMgr As Long Dim wPauseState As Integer Dim wID As Integer Dim dwMsgRtn As Long hPMgr = ProcessActive("Print Manager") If wPause Then wID = 2 Else wID = 3 End If If hPMgr Then dwMsgRtn = PostMessage(hPMgr, WM_SYSCOMMAND, SC_RESTORE, 0) DoEvents dwMsgRtn = PostMessage(hPMgr, WM_COMMAND, wID, 0) DoEvents dwMsgRtn = PostMessage(hPMgr, WM_SYSCOMMAND, SC_MINIMIZE, 0) DoEvents End If PausePrintManager = hPMgr End Function '**************************************************************************************** ' ' Process: PrinterOrient ' ' Author: Roberto Raso ' Date: 7th November 1994 ' ' Purpose: Sets up printer for MassLynx. ' ' Parameters: bPortrait sets Portrait or Landscape printer mode. ' ' Return: True if successful. ' '**************************************************************************************** Function PrinterOrient(bPortrait As Integer) As Integer Dim hMassLynx As Long Dim hPrinter As Long Dim idPortrait As Integer Dim dwMsgRtn As Long Dim strPrinterCaption As String hMassLynx = MassLynxhWnd() strPrinterCaption = "Print Setup" If hMassLynx Then hPrinter = FindChildWindow(hMassLynx, strPrinterCaption) If hPrinter = 0 Then dwMsgRtn = PostMessage(hMassLynx, WM_COMMAND, IDM_DESK_PRINTER, 0) hPrinter = WaitForChildWindow(hMassLynx, strPrinterCaption, 10) End If If hPrinter Then If bPortrait Then idPortrait = PORTRAIT Else idPortrait = LANDSCAPE End If dwMsgRtn = SendMessage(hPrinter, WM_COMMAND, idPortrait, 0) dwMsgRtn = SendMessage(hPrinter, WM_COMMAND, IDOK, 0) Do While IsWindow(hPrinter) DoEvents Loop PrinterOrient = True End If End If End Function '**************************************************************************************** ' ' Process: ProcDialog_OK ' ' Author: Roberto Raso ' Date: 6th February 1995 ' ' Purpose: Call up a dialogue box and then OK it, sometimes to ' activate a process. ' ' Parameters: hParent is the handle of the window that the dialogue ' box will be generated from. ' nID is the command ID of the menu or tool bar item that ' will call the up the dialogue box. ' strDlgCaption is the caption of the dialogue box that will ' be activated when nID is sent to hParent. ' strProcDlg is the caption of the processing type dialogue box. ' This can be a Chr$(0) if no processing box is displayed. ' ' Return: void. ' '**************************************************************************************** Sub ProcDialog_OK(hParent As Long, nID As Integer, strDlgCaption As String, strProcDlg As String) Dim dwMsgRtn As Long Dim hDlg As Long Dim hProc As Long If IsWindow(hParent) Then hDlg = FindChildWindow(hParent, strDlgCaption) If hDlg = 0 Then dwMsgRtn = PostMessage(hParent, WM_COMMAND, nID, 0) hDlg = WaitForChildWindow(hParent, strDlgCaption, 5) End If If hDlg Then dwMsgRtn = SendMessage(hDlg, WM_COMMAND, IDOK, 0) If strProcDlg <> Chr$(0) Then hProc = WaitForProcessStart(strProcDlg, 5) If hProc Then Do While IsWindow(hProc) DoEvents Loop End If End If End If End If End Sub '**************************************************************************************** ' ' Purpose: Get the size of the current record from table tbl. ' The array of field sizes is filled. ' '**************************************************************************************** Function RecSize(tbl As Table, lpFdSize() As Long) As Long Dim wFdNum As Integer Dim dwRecSize As Integer dwRecSize = 0 ReDim lpFdSize(tbl.Fields.Count - 1) For wFdNum = 0 To tbl.Fields.Count - 1 lpFdSize(wFdNum) = tbl.Fields(wFdNum).Size If (tbl.Fields(wFdNum).Type = DB_LONGBINARY) Or (tbl.Fields(wFdNum).Type = DB_MEMO) Then lpFdSize(wFdNum) = tbl.Fields(wFdNum).FieldSize() End If dwRecSize = dwRecSize + lpFdSize(wFdNum) Next wFdNum RecSize = dwRecSize End Function '**************************************************************************************** ' ' Purpose: Send a text message to the relevant window handle. ' '**************************************************************************************** Function SendMessageText(hWnd As Long, lpMsg As String) As Long SendMessageText = SendMessageAPI(hWnd, WM_SETTEXT, 0, ByVal lpMsg) DoEvents End Function '**************************************************************************************** ' ' Purpose: Set the current record to dwRec. ' Returns TRUE if record inside range of records in table. ' Returns FALSE if outside range. ' '**************************************************************************************** Function SetDBRec(tbl As Table, dwRec As Long) As Integer Dim bRecOK As Integer Dim dwCurRec As Long bRecOK = ((tbl.RecordCount >= dwRec) And (dwRec > 0)) If bRecOK Then dwCurRec = 1 tbl.MoveFirst Do While dwCurRec < dwRec tbl.MoveNext dwCurRec = dwCurRec + 1 Loop SetDBRec = True Else SetDBRec = False End If End Function '**************************************************************************************** ' ' Purpose: Set the default MassLynx file, for file type lpFileType. ' The file is first assumed to exist in the current ' directory with the current extension. Therefore only name is required. ' If file does not exist in default form lpFileName is assumed to be the ' comlete path descriptor for file i.e. Directory and extension must be included. ' ' '**************************************************************************************** Function SetGlobalFileML(lpFileType As String, lpFileName As String) As Integer Dim bSetable As Integer Dim wVGFile As Integer Dim lpVGFile As VGFILE wVGFile = GetMLFileInfo(lpFileType, lpVGFile) If wVGFile Then bSetable = False If FileExists(SZToVB(lpVGFile.szDirectory) + lpFileName + "." + SZToVB(lpVGFile.szExtension)) Then lpVGFile.szName = lpFileName + Chr$(0) bSetable = True ElseIf FileExists(lpFileName) Then lpVGFile.szDirectory = GetDOSFilePath(lpFileName) + Chr$(0) lpVGFile.szName = GetDOSFileName(lpFileName) + Chr$(0) lpVGFile.szExtension = GetDOSFileExt(lpFileName) + Chr$(0) bSetable = True End If If bSetable Then SetGlobalFileML = SetGlobalFile(SYSPARAGRAPH, lpFileType, lpVGFile, True) End If Else SetGlobalFileML = False End If End Function '**************************************************************************************** ' ' Purpose: Set a Windows for Workgroup printer. ' If the printer port (lpPort) or ' the printer (lpPrinter) is invalid then ' the configuration is not changed. ' '**************************************************************************************** Sub SetWrkGrpPrinter(lpPrinter As String, lpPort As String) Dim hPMgr As Long Dim hInst As Long Dim hCon As Long Dim hPath As Long Dim hWarning As Long Dim wPortItem As Integer Dim dwMsgRtn As Long Dim lpPMgr As String Dim lpCon As String Dim lpWarning As String lpPMgr = "Print Manager" lpCon = "Connect Network Printer" lpWarning = "Windows for Workgroups" hPMgr = ProcessActive(lpPMgr) If hPMgr = 0 Then hInst = Shell("PRINTMAN.EXE", 1) hPMgr = WaitForProcessStart(lpPMgr, 5) End If If hPMgr Then dwMsgRtn = PostMessage(hPMgr, WM_SYSCOMMAND, SC_RESTORE, 0) DoEvents hCon = ProcessActive(lpCon) If hCon = 0 Then dwMsgRtn = PostMessage(hPMgr, WM_COMMAND, 8022, 0) 'Connect menu item DoEvents hCon = WaitForProcessStart(lpCon, 5) End If If hCon Then wPortItem = TextInCB(hCon, 603, lpPort) 'Is printer port available? If wPortItem > -1 Then dwMsgRtn = SendDlgItemMessage(hCon, 603, CB_SETCURSEL, wPortItem, 0) End If hPath = GetDlgItem(hCon, 601) 'Path text box handle. dwMsgRtn = SendMessageText(hPath, lpPrinter) dwMsgRtn = PostMessage(hCon, WM_COMMAND, IDOK, 0) hWarning = WaitForProcessStart(lpWarning, 10) If hWarning Then dwMsgRtn = PostMessage(hWarning, WM_COMMAND, IDOK, 0) DoEvents dwMsgRtn = PostMessage(hCon, WM_COMMAND, IDCANCEL, 0) DoEvents End If End If dwMsgRtn = PostMessage(hPMgr, WM_SYSCOMMAND, SC_MINIMIZE, 0) DoEvents End If End Sub Function SqrBrRem(StringToStrip As String) As String Dim LenOfExpr As Integer Dim sWork As String Dim FirstChar As String Dim LastChar As String FirstChar = "[" LastChar = "]" If Left(StringToStrip, 1) = FirstChar Then LenOfExp = Len(StringToStrip) - 1 sWork = Right$(StringToStrip, LenOfExp) LenOfExp = LenOfExp - 1 SqrBrRem = Left$(sWork, LenOfExp) Else SqrBrRem = StringToStrip End If End Function '**************************************************************************************** ' ' Purpose: Close down process with selected window caption ' Returns TRUE if lpProcess was active. ' '**************************************************************************************** Function StopProcess(lpProcess As String) As Integer Dim hWnd As Long Dim dwSendMsgRtn As Long StopProcess = False hWnd = FindWindow(0&, Trim$(lpProcess)) If hWnd Then dwSendMsgRtn = PostMessage(hWnd, WM_CLOSE, 0, 0) Call WaitForProcessEnd(lpProcess) StopProcess = True Else StopProcess = False End If End Function Function Str2Sng(NumStr As String) As Single 'Converts a string (from ClipBoard?) to single. Dim CharInStr As String Dim PosInStr As Integer Dim MantDone As Integer Dim ExpDone As Integer Dim ValMant As Single Dim ValExp As Single MantDone = False PosInStr = 1 Do While MantDone = False CharInStr = UCase$(Mid$(NumStr, PosInStr, 1)) If CharInStr = "E" Or PosInStr = Len(NumStr) Then ValMant = Val(Left$(NumStr, PosInStr)) MantDone = True End If PosInStr = PosInStr + 1 Loop If PosInStr > Len(NumStr) Then ValExp = 0 Else ValExp = Val(Right$(NumStr, Len(NumStr) - PosInStr + 1)) End If Str2Sng = ValMant * (10 ^ ValExp) End Function '**************************************************************************************** ' ' Purpose: Convert as string to an array of characters. ' '**************************************************************************************** Function StrToArray(lpString As String, lpArray() As String * 1) As Long Dim wStart As Integer Dim wChar As Integer Dim dwStrLen As Long wStart = &H8000 dwStrLen = Len(lpString) ReDim lpArray(wStart To wStart + dwStrLen) For wChar = 1 To dwStrLen lpArray(wStart + wChar - 1) = Mid$(lpString, wChar, 1) Next wChar StrToArray = wChar - 1 End Function '**************************************************************************************** ' ' Purpose: Check to see if the text lpText is in any one of the ' ComboBox entries, the first index containing lpText is returned. ' If lpText is not found -1 is returned. ' The text search is not case sensitive, do not be surprised ' if this function gives the 'wrong' result. ' '**************************************************************************************** Function TextInCB(hDlg As Long, wCBID As Integer, lpText As String) As Integer Dim wItems As Integer Dim wItem As Integer Dim wFound As Integer Dim dwMsgRtn As Long Dim lpItem As SUPASTRING wFound = 0 wItems = SendDlgItemMessage(hDlg, wCBID, CB_GETCOUNT, 0, 0) For wItem = 0 To (wItems - 1) dwMsgRtn = SendDlgItemMessage(hDlg, wCBID, CB_GETITEMDATA, ByVal wItem, 0) Call hmemcpyTolp(lpItem, dwMsgRtn, 64) wFound = InStr(1, lpItem.sz64, lpText, 1) If wFound > 0 Then Exit For End If Next wItem If wFound > 0 Then TextInCB = wItem Else TextInCB = -1 End If End Function '**************************************************************************************** ' ' Purpose: Check to see if the text lpText is in any one of the ' ListBox entries, the first index containing lpText is returned. ' If lpText is not found -1 is returned. ' The text search is not case sensitive, do not be surprised ' if this function gives the 'wrong' result. ' '**************************************************************************************** Function TextInLB(hDlg As Long, wLBID As Integer, lpText As String) Dim wItems As Integer Dim wItem As Integer Dim wFound As Integer Dim dwMsgRtn As Long Dim lpItem As SUPASTRING wFound = 0 wItems = SendDlgItemMessage(hDlg, wLBID, LB_GETCOUNT, 0, 0) Debug.Print "wItems"; wItems For wItem = 0 To (wItems - 1) dwMsgRtn = SendDlgItemMessage(hDlg, wLBID, LB_GETITEMDATA, ByVal wItem, 0) Debug.Print "Size "; GlobalSize(dwMsgRtn) Debug.Print "GETITEM "; dwMsgRtn 'Call hmemcpyTolp(lpItem, dwMsgRtn, 64) 'Debug.Print lpItem.sz64 'wFound = InStr(1, lpItem.sz64, lpText, 1) 'If wFound > 0 Then 'Exit For 'End If Next wItem 'If wFound > 0 Then 'TextInLB = wItem 'Else 'TextInLB = -1 'End If TextInLB = wItems End Function '---------------------------------------------------------------------------------------- ' ' Process: VGRawFileOpen ' ' Author: Roberto Raso ' Date: 25th April 1995 ' ' Purpose: Opens the required file, function and/or process. ' ' Parameters: sVGRawFile is the VG raw file to open. ' Note: sVGRawFile.wFunc or sVGRawFile.wProc must be set and valid. ' nChroSpec is a bit field holding CHRO_OPEN and/or SPEC_OPEN. ' ' Return: True if successful. ' '---------------------------------------------------------------------------------------- Function VGRawFileOpen(sVGRawFile As VGRAWFILE, nChroSpec As Integer) As Integer Dim bDataFile As Integer Dim hMassLynx As Long Dim hBrowser As Long Dim hHistory As Long Dim nDataFile As Integer bDataFile = False VGRawFileOpen = bDataFile hMassLynx = MLAppActive(APP_CLI) If hMassLynx Then If FileExists(SZToVB(sVGRawFile.lpVGFile.szDirectory) + SZToVB(sVGRawFile.lpVGFile.szName) + "." + SZToVB(sVGRawFile.lpVGFile.szExtension) + "\*.dat") = 0 Then VGRawFileOpen = False Exit Function End If If SetGlobalFile(SYSPARAGRAPH, "RAW" + Chr$(0), sVGRawFile.lpVGFile, True) Then hBrowser = DataBrowserShow() If hBrowser Then If sVGRawFile.wProc > 0 Then If sVGRawFile.wProc = DataFileExists(sVGRawFile.lpVGFile, sVGRawFile.wProc, PROC_STUB, DATA_FILE_EXT) Then If DataProcessSelect(sVGRawFile, hBrowser) = sVGRawFile.wProc Then bDataFile = True End If End If ElseIf sVGRawFile.wFunc > 0 Then If sVGRawFile.wFunc = DataFileExists(sVGRawFile.lpVGFile, sVGRawFile.wFunc, FUNC_STUB, DATA_FILE_EXT) Then If DataFunctionSelect(sVGRawFile, hBrowser) = sVGRawFile.wFunc Then bDataFile = True End If End If Else bDataFile = True End If If bDataFile And DataBrowserChroSpec(hBrowser, nChroSpec) = nChroSpec Then VGRawFileOpen = DlgBoxClose(hBrowser, IDOK, -1) Else bDataFile = DlgBoxClose(hBrowser, IDCANCEL, -1) VGRawFileOpen = False End If End If End If End If End Function '**************************************************************************************** ' ' Purpose: Waits for the MassLynx application to start. ' If the application is not started within the wTimeOut ' period (in seconds), then 0 is returned. If the application ' is active its window handle is returned. ' wMLApp is the MassLynx applictaion code. ' '**************************************************************************************** Function WaitForMLApp(wMLApp As Integer, wTimeout As Integer) As Integer Dim bEndWait As Integer Dim hAppWnd As Long Dim wWait As Integer Dim lpEntryTime As Variant lpEntryTime = Now bEndWait = False hAppWnd = 0 Do Until bEndWait Or hAppWnd wWait = Second(Now - lpEntryTime) hAppWnd = MLAppActive(wMLApp) If wWait > wTimeout Then bEndWait = True End If DoEvents Loop WaitForMLApp = hAppWnd End Function '**************************************************************************************** ' ' Purpose: Wait for MassLynx to finish printing. ' '**************************************************************************************** Sub WaitForMLPrint() Dim hPrint As Long Dim lpPrint As String lpPrint = "Printing..." hPrint = WaitForProcessStart(lpPrint, 10) Call WaitForProcessEnd("Printing...") End Sub Sub WaitForProcessEnd(WindowCaption As String) 'Wait for the process window to disapear. Do While FindWindow(0&, WindowCaption) DoEvents Loop End Sub Function WaitForProcessStart(Process As String, Timeout As Integer) As Integer 'Looks for the Window with caption Process. If the Window 'has not been found in Timeout seconds then function returns false. Dim EndWait As Integer Dim Wait As Integer Dim EntryTime As Variant EntryTime = Now Do Until EndWait Wait = Second(Now - EntryTime) If ProcessActive(Process) Then EndWait = True ElseIf Wait > Timeout Then EndWait = True Else DoEvents End If Loop WaitForProcessStart = ProcessActive(Process) End Function '**************************************************************************************** ' ' Purpose: Wait for the window, identified by hWnd to close down. ' '**************************************************************************************** Sub WaitForWindowClose(hWnd As Long) Do While GetWindow(hWnd, GW_HWNDFIRST) DoEvents Loop End Sub Function WrkGrpPrintPause(bPause As Integer) Dim hPMgr As Long Dim hInst As Long Dim hCon As Long Dim hPath As Long Dim hWarning As Long Dim wPortItem As Integer Dim dwMsgRtn As Long Dim lpPMgr As String Dim lpCon As String Dim lpWarning As String lpPMgr = "Print Manager" lpCon = "Connect Network Printer" lpWarning = "Windows for Workgroups" hPMgr = ProcessActive(lpPMgr) If hPMgr = 0 Then hInst = Shell("PRINTMAN.EXE", 1) hPMgr = WaitForProcessStart(lpPMgr, 5) End If If hPMgr Then dwMsgRtn = PostMessage(hPMgr, WM_SYSCOMMAND, SC_RESTORE, 0) DoEvents wPortItem = TextInLB(hPMgr, 403, "OL-400") Debug.Print "WrkGrpPrintPause "; wPortItem End If End Function