Solved

InputBox

Posted on 2000-04-10
11
555 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]
Comment Utility
You can't.
You need to implement your own InputBox
0
 
LVL 5

Expert Comment

by:Voodooman
Comment Utility
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
Comment Utility
If the user clicks Cancel, the function returns a zero-length string ("").
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
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
Comment Utility
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 50 total points
Comment Utility
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
Comment Utility
AngelIII you are wright, I am wrong and dekoay has to make his own inputbox
0
 
LVL 27

Expert Comment

by:Ark
Comment Utility
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]
Comment Utility
Seeing all this code i like to run awayyyyyyyyyyyyyy.............
0
 
LVL 27

Expert Comment

by:Ark
Comment Utility
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
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

744 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

12 Experts available now in Live!

Get 1:1 Help Now