Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
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
?
159 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
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month11 days, 4 hours left to enroll

572 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