Results 1 to 25 of 25

Thread: This is irritating.

  1. #1

    Thread Starter
    Hyperactive Member Troy Lundin's Avatar
    Join Date
    May 2006
    Posts
    489

    Angry This is irritating.

    I am about as irritated as I can get with this project. I have posted questions about it before and have tried every suggestion thrown my way. But, the program still refuses to work.

    I have attached the source files. If somebody could please take the time to look at my project and find out why it doesn't work.

    Here is what you do to test the program. Make sure Notepad is open, then start my program. Clicking on the top button is supposed to write a value at a certain address but instead it does nothing and if you look at the immediate window it shows the error. Click the Debug button will show you info about the process.

    If you can get it to work then please attach a copy of the working source. I have a feeling that if just the corrections are posted and I try to implement them it still won't work.

    I have no idea why this is not working. I just hope it isn't my computer. Thank you to anybody that helps.
    Last edited by Troy Lundin; May 22nd, 2007 at 07:50 PM.
    Prefix has no suffix, but suffix has a prefix.

  2. #2
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: This is irritating.

    For starters.

    You should use Option Explicit in the form

    And This: (causes error)

    For Each Form In Forms
    If Not Form Is Me Then Unload (Form)
    Next Form

    Should be this:

    Dim i as Integer
    For i = Forms.Count - 1 To 1 Step -1
    Unload Forms(i)
    Next
    Last edited by rory; May 31st, 2006 at 02:04 AM.

  3. #3

    Thread Starter
    Hyperactive Member Troy Lundin's Avatar
    Join Date
    May 2006
    Posts
    489

    Re: This is irritating.

    Thank you for that tip rory. The unload code was actually suggested by a member of these here forums.

    Did you get a look at the 487 error?
    Prefix has no suffix, but suffix has a prefix.

  4. #4
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: This is irritating.

    yeah checking that now ..

    note the Dim i above i'd forgotten ..

  5. #5
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: This is irritating.

    Quote Originally Posted by rory
    And This: (causes error)

    For Each Form In Forms
    If Not Form Is Me Then Unload (Form)
    Next Form

    Should be this:

    Dim i as Integer
    For i = Forms.Count - 1 To 1 Step -1
    Unload Forms(i)
    Next
    Why would it cause any error? I have been using this code for years now. Is there any specific reason why we shouldn't be using this code?
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  6. #6
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: This is irritating.

    Quote Originally Posted by Shuja Ali
    Why would it cause any error? I have been using this code for years now. Is there any specific reason why we shouldn't be using this code?
    Can do, just in his case Form is not Declared.
    The way i listed is the method suggested by MS.

  7. #7
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: This is irritating.

    Quote Originally Posted by rory
    The way i listed is the method suggested by MS.
    Got a link for that?

    Most of the people here will be using the For...Each loop (with the form object correctly declared)

    You may end up trying to unload a form that no longer exists if you use the method you've suggested.

  8. #8
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: This is irritating.

    Quote Originally Posted by bushmobile
    Got a link for that?

    Most of the people here will be using the For...Each loop (with the form object correctly declared)

    You may end up trying to unload a form that no longer exists if you use the method you've suggested.
    Just use MS Application Wizard .. also works in apps I have with many forms loaded or unloaded ...

  9. #9
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: This is irritating.

    Anyways back to the topic ..

    Error 487:
    Attempt to access invalid address.

    Are you setting the correct address to write to?
    Last edited by rory; May 31st, 2006 at 02:49 AM.

  10. #10
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: This is irritating.

    Quote Originally Posted by rory
    Can do, just in his case Form is not Declared.
    The way i listed is the method suggested by MS.
    While looping through a collection MS has always recommended using For Each Loop. As Forms is basically a collection so using a For Each loop will be way better that using For i=0 to something loop.

    My question was are there any drawbacks of using For Each loop to unload the Forms?
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  11. #11
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: This is irritating.

    Quote Originally Posted by Shuja Ali
    While looping through a collection MS has always recommended using For Each Loop. As Forms is basically a collection so using a For Each loop will be way better that using For i=0 to something loop.

    My question was are there any drawbacks of using For Each loop to unload the Forms?
    Dont think there is, but like I said, thats what Microsoft uses in their VB6 application Wizard so thats what I use.

  12. #12
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: This is irritating.

    MS Application Wizard <> Best Programming practice

    If one of the forms you unload from the For i = 0 to... loop unloads an, as yet, unloaded form, then the number of items in the forms collection will not match the number in the loop and you'll get a subscript out of range error.

    that doesn't happen with a for each loop

  13. #13
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: This is irritating.

    Quote Originally Posted by bushmobile
    MS Application Wizard <> Best Programming practice

    If one of the forms you unload from the For i = 0 to... loop unloads an, as yet, unloaded form, then the number of items in the forms collection will not match the number in the loop and you'll get a subscript out of range error.

    that doesn't happen with a for each loop

    You would get the error with this:

    For i = o To Forms.Count
    Unload Forms(i)
    Next

    But not this:

    For i = Forms.Count - 1 To 1 Step -1
    Unload Forms(i)
    Next

    see attached example ...
    Last edited by rory; May 31st, 2006 at 03:04 AM.

  14. #14
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: This is irritating.

    Quote Originally Posted by rory
    Dont think there is, but like I said, thats what Microsoft uses in their VB6 application Wizard so thats what I use.
    Anyways, so the suggestion from my side is that you should be using a For Each loop when dealing with collections (not just Forms collections, an collection for that matter). It is quicker and safer.
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  15. #15
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: This is irritating.

    Add three forms:
    VB Code:
    1. ' In Form1
    2. Option Explicit
    3.  
    4. Private Sub Form_Load()
    5.     Form2.Show
    6.     Form3.Show
    7. End Sub
    8.  
    9. Private Sub Form_Unload(Cancel As Integer)
    10.     Dim i As Integer
    11.     For i = Forms.Count - 1 To 1 Step -1
    12.         Unload Forms(i)
    13.     Next
    14. End Sub
    15.  
    16. ' In Form3:
    17. Private Sub Form_Unload(Cancel As Integer)
    18.     Unload Form2
    19. End Sub
    Run the code and close Form1

  16. #16

    Thread Starter
    Hyperactive Member Troy Lundin's Avatar
    Join Date
    May 2006
    Posts
    489

    Re: This is irritating.

    It seems like we are getting ouselves a tangent here.

    Now, my question had nothing to do with the method I use to unload my form (of which I only have 1 at the moment), it has to do with the error I am getting (error 487). Why am I getting it? And, how can I get this program to work?

    Thank you.
    Prefix has no suffix, but suffix has a prefix.

  17. #17
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: This is irritating.

    Quote Originally Posted by bushmobile
    Run the code and close Form1
    Yep your'e right there .. oh well ..i never unload forms like that so didnt know .. Im emailing MS right now those ...Uhumm ..

    But doesnt appear to need that Is me part ..?

    VB Code:
    1. Do Until Forms.Count = 1
    2.     Unload Forms(Forms.Count - 1)
    3. Loop
    4.  
    5. Or ..
    6.  
    7. Dim Form
    8. For Each Form In Forms
    9.     Unload (Form)
    10. Next Form



    back to the topic .. how are you getting the address .. the error is the Address is Invalid ..

  18. #18
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    266

    Re: This is irritating.

    i have executed ur program and find rcvd no error and in immediate window it is displaying 87...........either i couldn't understand it ir something else is there

  19. #19

    Thread Starter
    Hyperactive Member Troy Lundin's Avatar
    Join Date
    May 2006
    Posts
    489

    Re: This is irritating.

    I got the address using a program called TSearch which let's me search a process and find offsets of interest. The address is actually for a game called Oasis, but even if you change the address to any value it gives that same error.

    Believe it or not I actually had this program working about a week ago. I didn't even change much and all of the sudden it doesn't work. There has to be a reason.

    By the way, the error is error 487, not 87, noshaba.
    Prefix has no suffix, but suffix has a prefix.

  20. #20
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: This is irritating.

    Try, I haven't looked at your program, but are you trying to access memory owned by another process?
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  21. #21

    Thread Starter
    Hyperactive Member Troy Lundin's Avatar
    Join Date
    May 2006
    Posts
    489

    Re: This is irritating.

    Yes the memory I am accessing belongs to a game. The thing is that I had this working and the buttons did what they were supposed (as fas as changing the values of the offsets). All the sudden it stopped working. And I have no idea why.
    Prefix has no suffix, but suffix has a prefix.

  22. #22
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: This is irritating.

    wouldnt the memory address change from one PC to the next?
    I Dont know much about memory allocation, just curious ..

    Also, wouldnt the address you have for the game be different for Notepad?

  23. #23
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: This is irritating.

    I think that the problem is that the memory address you are trying to access is locked to you. You are not guaranteed that any arbitrary memory address is accessable. Does it give you the same error when you try it on the game?

    if you try to read the memory do you get the correct values?

    One way to test your reading and writing routines is to allocate some memory in the other process first then read to and write from it.

    See post #30 in this thread for an example that gets listview items from external programs by allocating memory in the external process space, writing to that memory, sending a Get item text message and then reading from the external space to retrieve the values returned by the message. This is necessary becaue listview messages are not marshalled by the operating system between processes.

    http://www.vbforums.com/showthread.p...0&page=1&pp=40

  24. #24

    Thread Starter
    Hyperactive Member Troy Lundin's Avatar
    Join Date
    May 2006
    Posts
    489

    Re: This is irritating.

    Ok, I ran the program in your post(#30) and entered the window handle of the game window into the textbox and clicked the button. A msgbox came up that said: 0 (&H0): The operation competed successfully.

    Then i click ok button and the debugger comes up with the following line highlighted:
    VB Code:
    1. 'send the get the item message
    2.     strLength = SendMessage(hWindow, LVM_GETITEMTEXT, iItem, ByVal pMyItemMemory)
    3.     If strLength = 0 Then
    4.         MsgBox GetAPIErrorText(Err.LastDllError)
    5.         Stop '<-- this line is highlighted
    6.     End If

    When i continue the program a msgbox pops up with no message.
    Does this mean that writing to the process was successful?
    Prefix has no suffix, but suffix has a prefix.

  25. #25

    Thread Starter
    Hyperactive Member Troy Lundin's Avatar
    Join Date
    May 2006
    Posts
    489

    Re: This is irritating.

    Ok, this takes the cake.

    I have attached another project. It is the bones on which I based my program. And get this: It works!

    Now, can somebody tell me why this one works but mine doesn't.
    Last edited by Troy Lundin; May 22nd, 2007 at 07:50 PM.
    Prefix has no suffix, but suffix has a prefix.

Posting Permissions

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



Click Here to Expand Forum to Full Width