?
Solved

Problem with global module - could anyone let me know if this code runs on your system?

Posted on 2003-03-27
5
Medium Priority
?
158 Views
Last Modified: 2010-05-01
In VB 6.0 I tried to run the code below but get a File not found: User
errror with

ListHwnd = GetFocus()

highlighted.


GetFocus() is declared but perhaps there is something wrong with the
module it is in? It should be a global module. I have a normal module in the Modules folder under
Project1. Can GetFocus() not be seen if its' declaration is placed in a module?

Thanks,
           Liglin


Could anyone let me know if this code runs on your system? I suspect the code is ok, maybe I am just overlooking something.

The code is from:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;80187
   

   
   '     ============== Form1.frm ==================

Private Sub Form_Load()

End Sub

   Sub List1_DragDrop(Source As Control, X As Single, Y As Single)

      'get the first visible index in the list box
      List1.SetFocus
      ListHwnd = GetFocus()
      topi& = SendMessage(ListHwnd, LB_GETTOPINDEX, 0&, 0&)
      ColumnHeight = TextHeight("A ")
      inserti& = Y \ ColumnHeight
      If inserti& <= List1.ListCount Then
         ' Enter the following two lines on one, single line:
         List1.AddItem "This is inserted @" + format$(inserti& + topi&,"0"), inserti& + topi&
      Else
         List1.AddItem "This is inserted"
      End If

   End Sub



   '============= Global.Bas ===============
   'NOTE: Enter the following Declare statement as one, single line:
   Declare Function sendmessage& Lib "User" (ByVal hWnd%, ByVal wMsg%,ByVal wParam%, lParam As Any)
   Declare Function GetFocus Lib "User" () As Integer
   Global Const LB_GETTOPINDEX = &H400 + 15

 
 THanks,
               Liglin



0
Comment
Question by:liglin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 5

Expert Comment

by:avya2k
ID: 8223405
Try changing module like this
'============= Global.Bas ===============
  'NOTE: Enter the following Declare statement as one, single line:
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Function GetFocus Lib "user32" Alias "GetFocus" () As Long

public  Const LB_GETTOPINDEX = &H400 + 15


0
 
LVL 5

Expert Comment

by:Cimperiali
ID: 8224451
You can also qualify it fully:
ListHwnd = ModuleName.GetFocus()
But I guess matter is not in how you call it.
Is your module a Bas module? Then, is it inside same project where the call is? As the Bas modules are publics throughout the project, but not across different projects (ie: if you have a bas module of a dll, it will not be seen by a standard exe or by anothre dll project...)
By the way: as avyak already pointed out (if matter is here, give him points!), you have an old declare of Getfous:
Change the "Integer" to "Long"
Private Declare Function GetFocus Lib "user32" () As Long
0
 

Expert Comment

by:CleanupPing
ID: 8531452
Hi liglin,
This old question (QID 20565973) needs to be finalized -- accept an answer, split points, or get a refund.  Please see http://www.cityofangels.com/Experts/Closing.htm for information and options.
0
 
LVL 6

Expert Comment

by:GPrentice00
ID: 9440858
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

 -->PAQ - no points refunded

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER

GPrentice00
Cleanup Volunteer
0
 

Accepted Solution

by:
YensidMod earned 0 total points
ID: 9495560
This question is PAQed and no points refunded (of 250)

YensidMod
Expert Exchange Moderator
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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 …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

777 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