Results 1 to 8 of 8

Compressing multi used variables

Threaded View

  1. #1
    Valued Forum Contributor
    Join Date
    05-14-2009
    Location
    gold coast
    MS-Off Ver
    Excel 2007
    Posts
    843

    Compressing multi used variables

    How are you guys.

    What i would like to know is, In the code im using to make a phone call from a userform the varibles are set in each and every sub. It all works well though could they be compressed into only being used once like an option variable or somethink like that.
    i know that more that one variable can be decleared at the same time of the same type "dim x, Y, z as long.

    Option Explicit
    
    Const WM_CLOSE = &H10
    Const WM_DESTROY = &H2
    'Const SW_HIDE = 0
    Const WM_SETTEXT = &HC
    Const WM_COMMAND = &H111
    Const VK_RETURN = &HD
    Const WM_CHAR = &H102
    Const WM_KEYDOWN = &H100
    Const WM_KEYUP = &H101
    Const VK_SPACE = &H20
    
    Const GW_CHILD As Long = 5
    'Const WM_CHAR = 258
    Const VK_F10 = &H79
    Const VK_F5 = &H74
    Const VK_L = &H4C
    
    Const SW_HIDE = 0
    Const SW_SHOW = 5
    
    Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    
    'API use Phone Dialer to make call
    Private Declare Function tapiRequestMakeCall Lib "TAPI32.DLL" _
    (ByVal DestAddress As String, ByVal AppName As String, ByVal CalledParty As String, _
    ByVal Comment As String) As Long
    
    'API find applcation by full caption
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
    (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    
    'API bring Window to foreground
    Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
    
    'API set ShowWindow to hide window
    Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long)
    
    'API send message to application
    Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" _
    (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    
    Private Declare Function WaitForSingleObject Lib "kernel32" _
    (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
    
    Private Declare Function CloseHandle Lib "kernel32" _
    (ByVal hObject As Long) As Long
    
    Private Declare Function OpenProcess Lib "kernel32" _
    (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, _
    ByVal dwProcessId As Long) As Long
    
    Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
    
    Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
    
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    
    Private Const INFINITE = -1&
    Private Const SYNCHRONIZE = &H100000
    
    '******************************************************************************************
    
    Sub bussinessphone()                                               'Bussiness Phone Number
    On Error GoTo HandleErr                                         '*******************
    Dim varDialWait             As Variant
    Dim varStart                As Variant
    Dim lThreadId               As Long
    Dim lProcessId              As Long
    Dim ret                     As Long
    Dim strDial                 As String
    Dim lngRetVal               As Long
    Static blnDialing           As Boolean 'Prevent Re-Entry Into Sub While Dialing
    Dim strMsg                  As String
    Dim varReturn               As Long
    Dim lngX                    As Long
    Dim AppCaption              As String
    Dim hwnd                    As Long
    
    DoEvents
    
    blnDialing = False
    If blnDialing Then Exit Sub
    If Combobox_List_Search.TextBox9.Value = "" Then Exit Sub
                             'Conferm Dial Message
    If msgbox("Dial Number " _
    & vbNewLine _
    & Combobox_List_Search.ComboBox2.Value & " " & Combobox_List_Search.TextBox20.Value & " " _
    & "Mobile Phone" _
    & vbNewLine _
    & Combobox_List_Search.TextBox9.Text, _
    vbQuestion Or vbYesNo, "Phone Dialler") = vbNo Then Exit Sub Else
    
    strDial = Combobox_List_Search.TextBox9 ' Number To Dial
    lngRetVal = tapiRequestMakeCall(Trim$(strDial), "", "", "") 'Make call to Number Through Dialer.exe
    If lngRetVal = 0 Then blnDialing = True 'Exit sub on tapiRequestMakeCall Fail
    
    Call TestPlayWavFile ' Play Dial Sound Message
    
    For lngX = 1 To 10 ' Number of Loop Times For Sleep
    DoEvents
    Sleep 1000 ' Sleep 1 Second
    Next lngX
        
    'hwnd = FindWindow(vbNullString, AppCaption)
    
    hwnd = FindWindow(vbNullString, "Call Status")
        If hwnd <> 0 Then Call SendMessage(hwnd, WM_CLOSE, 0&, 0&)
    hwnd = FindWindow(vbNullString, "Phone Dialer")
        If hwnd <> 0 Then PostMessage hwnd, WM_CLOSE, 0&, 0&
    hwnd = FindWindow(vbNullString, "Dialer")
        If hwnd <> 0 Then
            PostMessage hwnd, WM_KEYDOWN, VK_RETURN, 0
            PostMessage hwnd, WM_KEYUP, VK_RETURN, 0
        End If
    
    Exit Sub
    HandleErr:
    Select Case Err.Number
    Case 94 'Invalid Use of Null - if double-click on blank, open dialer
    msgbox "here" 'Call Shell("c:\windows\dialer.exe", vbNormalFocus)
    Exit Sub
    Case Else
    'modHandler.LogErr ("frm0Telephone"),("Telephone_Numbers_DblClick" )
    End Select
    'Resume Exit_Here
    End Sub
    Sub homephone()                                               'Home Phone Number
    On Error GoTo HandleErr                                         '*******************
    Dim varDialWait             As Variant
    Dim varStart                As Variant
    Dim lThreadId               As Long
    Dim lProcessId              As Long
    Dim ret                     As Long
    Dim strDial                 As String
    Dim lngRetVal               As Long
    Static blnDialing           As Boolean 'Prevent Re-Entry Into Sub While Dialing
    Dim strMsg                  As String
    Dim varReturn               As Long
    Dim lngX                    As Long
    Dim AppCaption              As String
    Dim hwnd                    As Long
    
    DoEvents
    
    blnDialing = False
    If blnDialing Then Exit Sub
    If Combobox_List_Search.TextBox10.Value = "" Then Exit Sub
                             'Conferm Dial Message
    If msgbox("Dial Number " _
    & vbNewLine _
    & Combobox_List_Search.ComboBox2.Value & " " & Combobox_List_Search.TextBox20.Value & " " _
    & "Mobile Phone" _
    & vbNewLine _
    & Combobox_List_Search.TextBox10.Text, _
    vbQuestion Or vbYesNo, "Phone Dialler") = vbNo Then Exit Sub Else
    
    strDial = Combobox_List_Search.TextBox10 ' Number To Dial
    lngRetVal = tapiRequestMakeCall(Trim$(strDial), "", "", "") 'Make call to Number Through Dialer.exe
    If lngRetVal = 0 Then blnDialing = True 'Exit sub on tapiRequestMakeCall Fail
    
    Call TestPlayWavFile ' Play Dial Sound Message
    
    For lngX = 1 To 10 ' Number of Loop Times For Sleep
    DoEvents
    Sleep 1000 ' Sleep 1 Second
    Next lngX
        
    'hwnd = FindWindow(vbNullString, AppCaption)
    
    hwnd = FindWindow(vbNullString, "Call Status")
        If hwnd <> 0 Then Call SendMessage(hwnd, WM_CLOSE, 0&, 0&)
    hwnd = FindWindow(vbNullString, "Phone Dialer")
        If hwnd <> 0 Then PostMessage hwnd, WM_CLOSE, 0&, 0&
    hwnd = FindWindow(vbNullString, "Dialer")
        If hwnd <> 0 Then
            PostMessage hwnd, WM_KEYDOWN, VK_RETURN, 0
            PostMessage hwnd, WM_KEYUP, VK_RETURN, 0
        End If
    
    Exit Sub
    HandleErr:
    Select Case Err.Number
    Case 94 'Invalid Use of Null - if double-click on blank, open dialer
    msgbox "here" 'Call Shell("c:\windows\dialer.exe", vbNormalFocus)
    Exit Sub
    Case Else
    'modHandler.LogErr ("frm0Telephone"),("Telephone_Numbers_DblClick" )
    End Select
    'Resume Exit_Here
    End Sub
    Sub phonemobile()                                               'Mobile Phone Number
    On Error GoTo HandleErr                                         '*******************
    Dim varDialWait             As Variant
    Dim varStart                As Variant
    Dim lThreadId               As Long
    Dim lProcessId              As Long
    Dim ret                     As Long
    Dim strDial                 As String
    Dim lngRetVal               As Long
    Static blnDialing           As Boolean 'Prevent Re-Entry Into Sub While Dialing
    Dim strMsg                  As String
    Dim varReturn               As Long
    Dim lngX                    As Long
    Dim AppCaption              As String
    Dim hwnd                    As Long
    
    DoEvents
    
    blnDialing = False
    If blnDialing Then Exit Sub
    If Combobox_List_Search.TextBox11.Value = "" Then Exit Sub
                             'Conferm Dial Message
    If msgbox("Dial Number " _
    & vbNewLine _
    & Combobox_List_Search.ComboBox2.Value & " " & Combobox_List_Search.TextBox20.Value & " " _
    & "Mobile Phone" _
    & vbNewLine _
    & Combobox_List_Search.TextBox11.Text, _
    vbQuestion Or vbYesNo, "Phone Dialler") = vbNo Then Exit Sub Else
    
    strDial = Combobox_List_Search.TextBox11 ' Number To Dial
    lngRetVal = tapiRequestMakeCall(Trim$(strDial), "", "", "") 'Make call to Number Through Dialer.exe
    If lngRetVal = 0 Then blnDialing = True 'Exit sub on tapiRequestMakeCall Fail
    
    Call TestPlayWavFile ' Play Dial Sound Message
    
    For lngX = 1 To 10 ' Number of Loop Times For Sleep
    DoEvents
    Sleep 1000 ' Sleep 1 Second
    Next lngX
        
    'hwnd = FindWindow(vbNullString, AppCaption)
    
    hwnd = FindWindow(vbNullString, "Call Status")
        If hwnd <> 0 Then Call SendMessage(hwnd, WM_CLOSE, 0&, 0&)
    hwnd = FindWindow(vbNullString, "Phone Dialer")
        If hwnd <> 0 Then PostMessage hwnd, WM_CLOSE, 0&, 0&
    hwnd = FindWindow(vbNullString, "Dialer")
        If hwnd <> 0 Then
            PostMessage hwnd, WM_KEYDOWN, VK_RETURN, 0
            PostMessage hwnd, WM_KEYUP, VK_RETURN, 0
        End If
    
    Exit Sub
    HandleErr:
    Select Case Err.Number
    Case 94 'Invalid Use of Null - if double-click on blank, open dialer
    msgbox "here" 'Call Shell("c:\windows\dialer.exe", vbNormalFocus)
    Exit Sub
    Case Else
    'modHandler.LogErr ("frm0Telephone"),("Telephone_Numbers_DblClick" )
    End Select
    'Resume Exit_Here
    End Sub
    Last edited by D_Rennie; 07-05-2009 at 09:56 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1