Solved

InputBox

Posted on 2000-04-10
11
556 Views
Last Modified: 2012-06-27
Hello Experts,

I would like to ask a a question regarding InputBox use in VB.

How to differenciate the buttons between ok and cancel when the field is empty.
0
Comment
Question by:dekoay
  • 4
  • 3
  • 2
  • +2
11 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 2699472
You can't.
You need to implement your own InputBox
0
 
LVL 5

Expert Comment

by:Voodooman
ID: 2699582
Hi

AngelIII is correct - the inputbox is very basic and not used by most VB Programmers.

We make our own!

Good Luck

Voodooman!
0
 
LVL 2

Expert Comment

by:corvanderlinden
ID: 2699709
If the user clicks Cancel, the function returns a zero-length string ("").
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 2699731
corvanderlinden:
if the user deletes the text in the inputbox and clicks OK, the same zero-length string ("") is returned (wink)
0
 
LVL 2

Expert Comment

by:corvanderlinden
ID: 2699741
That has nothing to do with the question.
If a zero lenght string is returned you know you have to take some action in your program (why else use an input box?)
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 50 total points
ID: 2699755
corvanderlinden: please reread the question (i put the important words in captial letters)
"How to DIFFERENTIATE the buttons between ok and cancel WHEN the field IS empty.
0
 
LVL 2

Expert Comment

by:corvanderlinden
ID: 2699959
AngelIII you are wright, I am wrong and dekoay has to make his own inputbox
0
 
LVL 27

Expert Comment

by:Ark
ID: 2703035
Hi
AngelIII
Never say never :-). Nothing impossible with VB <smile>
Take a look:
'----- Bas module code---
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Public Declare Function SetTimer& Lib "user32" (ByVal hwnd&, ByVal nIDEvent&, ByVal uElapse&, ByVal lpTimerFunc&)
Private Declare Function KillTimer& Lib "user32" (ByVal hwnd&, ByVal nIDEvent&)
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long

Public Const GWL_WNDPROC = (-4)
Public Const GW_CHILD = 5
Public Const GW_HWNDFIRST = 0
Public Const GW_HWNDNEXT = 2
Public Const NV_INPUTBOX As Long = &H5000&
Public Const WM_COMMAND = &H111
Const WM_NOTIFY = &H4E
Const WM_CLOSE = &H10


Public hMsg As Long
Public hOK As Long, hCancel As Long, hHelp As Long
Dim OldProc As Long
Public bOK As Boolean
Public bCancel As Boolean

Public Sub TimerProc(ByVal hwnd&, ByVal uMsg&, ByVal idEvent&, ByVal dwTime&)
  Dim h As Long, sClass As String, k As Long, sName As String
'If your InputBox has its own caption, change following string.
  hMsg = FindWindow("#32770", App.Title)
  KillTimer hwnd, idEvent
  h = GetWindow(hMsg, GW_CHILD)
  Do
    sClass = Space$(128)
    k = GetClassName(h, ByVal sClass, 128)
    sClass = Left$(sClass, k)
    If sClass = "Button" Then
       sName = Space$(128)
       k = GetWindowText(h, sName, 128)
       If k > 0 Then sName = Left$(sName, k)
       Select Case sName
              Case "OK"
                   hOK = h
              Case "Cancel"
                   hCancel = h
              Case "&Help"
                   hHelp = h
       End Select
    End If
    h = GetWindow(h, GW_HWNDNEXT)
  Loop While h <> 0
  OldProc = GetWindowLong(hMsg, GWL_WNDPROC)
  SetWindowLong hMsg, GWL_WNDPROC, AddressOf BtnProc
End Sub

Public Function BtnProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  Select Case wMsg
     Case WM_CLOSE
          BtnProc = CallWindowProc(OldProc, hwnd, wMsg, wParam, lParam)
          SetWindowLong hMsg, GWL_WNDPROC, OldProc
          Exit Function
     Case WM_COMMAND
          If lParam = hOK Then bOK = True
          If lParam = hCancel Then bCancel = True
  End Select
  BtnProc = CallWindowProc(OldProc, hwnd, wMsg, wParam, lParam)
End Function

'---Form code---
Private Sub Command1_Click()
 Dim sTemp As String
 SetTimer hwnd, NV_INPUTBOX, 10, AddressOf TimerProc
 bOK = False: bCancel = False
 sTemp = InputBox("Enter your value or press Cancel")
 If bOK Then MsgBox "You pressed OK"
 If bCancel Then MsgBox "You pressed Cancel"
 If Not bOK And Not bCancel Then MsgBox "You closed InputBox using [x]"
End Sub

' Of course, it's much more simply to make own InputBox instead of "double subclassing" - but take a look - it works :-))

Cheers
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 2703132
Seeing all this code i like to run awayyyyyyyyyyyyyy.............
0
 
LVL 27

Expert Comment

by:Ark
ID: 2705624
Hi
I don't offer to use this code, I just want to show that it's possible <smile>.
Cheers
0
 

Author Comment

by:dekoay
ID: 2706170
Dear Ark,

Thanks for replying and show us some of this superb code with VB. I really appreciate it.

Thank You


Cheers
Dekoay
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now