Results 1 to 12 of 12

Thread: VB6 Crashing problem

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2009
    Posts
    137

    VB6 Crashing problem

    Hi, yesturday i added alot of code to my project, after a while, it started crashing VB saying "has stopped responding". if i compile the project and run the exe, it does it also.

    I have commented out alot of the code that it could be, and alot of the stuff i had added, but it still does it.

    How can i "debug" the application to find out what it doesnt like?

    thanks.
    Thanks for all your help here!
    I will do my best to add you to the credits of my new apps.

  2. #2
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: VB6 Crashing problem

    Are you doing some subclassing or anything of that stuff?
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Feb 2009
    Posts
    137

    Re: VB6 Crashing problem

    hmm, well, i think its happening when i use a "LineAfter" function that someone wrote me from here.

    it worked find before tho, but happens when that is called at a particuar point in the poker game.

    Code:
    Private Function LineAfter(ByRef Expression As String, _
    ByRef Find As String, _
    Optional ByVal CompareMethod As VbCompareMethod = vbBinaryCompare) As String
    
    On Error Resume Next
    Dim lonStart As Long, lonEnd As Long
    lonStart = InStr(1, Expression, Find, CompareMethod)
    If lonStart > 0 Then
    lonStart = lonStart + Len(Find) + 2 'Length of vbCrLf
    lonEnd = InStr(lonStart, Expression, vbCrLf)
    If lonEnd = 0 Then lonEnd = Len(Expression)
    LineAfter = Mid$(Expression, lonStart, lonEnd - lonStart + 1)
    End If
    End Function

    and i do have some VERY ugly code here...
    This is what i use to get the last 3 lines of a richtextbox, and put them on PokerLast.text.

    (dont kill me!)

    Code:
    Private Function GetLastLine(ByVal textBox As String)
    Dim lngCount As Long 'The number of lines
    Dim lngLineIndex As Long 'The index number for the line
    Dim lngLength As Long 'The length of the string in the line
    Dim strBuffer As String 'The string to hold what we're after
    Dim lngCount2 As Long 'The number of lines
    Dim lngLineIndex2 As Long 'The index number for the line
    Dim lngLength2 As Long 'The length of the string in the line
    Dim strBuffer2 As String 'The string to hold what we're after
    Dim lngCount3 As Long 'The number of lines
    Dim lngLineIndex3 As Long 'The index number for the line
    Dim lngLength3 As Long 'The length of the string in the line
    Dim strBuffer3 As String 'The string to hold what we're after
    Dim lngCount4 As Long 'The number of lines
    Dim lngLineIndex4 As Long 'The index number for the line
    Dim lngLength4 As Long 'The length of the string in the line
    Dim strBuffer4 As String 'The string to hold what we're after
    Dim i As Integer
    
    'Get the total line count (minus 1 to make it begin at zero)
    lngCount = SendMessage(Poker.hWnd, EM_GETLINECOUNT, 0, 0) - 1
    'Get the total line count (minus 1 to make it begin at zero)
    lngCount2 = SendMessage(Poker.hWnd, EM_GETLINECOUNT, 0, 0) - 2
    'Get the total line count (minus 1 to make it begin at zero)
    lngCount3 = SendMessage(Poker.hWnd, EM_GETLINECOUNT, 0, 0) - 3
    
    
    
    'Get the index for the last line (which is lngCount)
    lngLineIndex = SendMessage(Poker.hWnd, EM_LINEINDEX, lngCount, 0)
    'Get the index for the last line (which is lngCount)
    lngLineIndex2 = SendMessage(Poker.hWnd, EM_LINEINDEX, lngCount2, 0)
    'Get the index for the last line (which is lngCount)
    lngLineIndex3 = SendMessage(Poker.hWnd, EM_LINEINDEX, lngCount3, 0)
    
    
    'Get the length of the line at our index
    lngLength = SendMessage(Poker.hWnd, EM_LINELENGTH, lngLineIndex, 0)
    'Get the length of the line at our index
    lngLength2 = SendMessage(Poker.hWnd, EM_LINELENGTH, lngLineIndex2, 0)
    'Get the length of the line at our index
    lngLength3 = SendMessage(Poker.hWnd, EM_LINELENGTH, lngLineIndex3, 0)
    
    
    'Make a fixed length string, using the length of the string at the index
    strBuffer = Space(lngLength)
    'Make a fixed length string, using the length of the string at the index
    strBuffer2 = Space(lngLength2)
    'Make a fixed length string, using the length of the string at the index
    strBuffer3 = Space(lngLength3)
    
    
    'Put the last line of the text into the fixed length string
    Call SendMessageStr(Poker.hWnd, EM_GETLINE, lngCount, ByVal strBuffer)
    Call SendMessageStr(Poker.hWnd, EM_GETLINE, lngCount2, ByVal strBuffer2)
    Call SendMessageStr(Poker.hWnd, EM_GETLINE, lngCount3, ByVal strBuffer3)
    
    
    PokerLast.Text = strBuffer3 & vbNewLine & strBuffer2 & vbNewLine & strBuffer  'Display output
    End Function
    Thanks for all your help here!
    I will do my best to add you to the credits of my new apps.

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: VB6 Crashing problem

    I think your crashes are from the SendMessage calls that use EM_GETLINE. It is beng used incorrectly and strBuffer is not built correctly. The 1st 4 bytes of the passed string must contain the length of the string per MSDN documentation.

    Here is a function I have used that works every time for multiline textboxes. It should work for richtextboxes too, but won't copy RTF formatting.
    Pass your line index to the function and it will return the string. I remarked out some code that is used for unicode windows, which I don't think applies to your situation.
    Code:
    Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByRef lParam As Any) As Long
    
    
    
    Private Function GetTextFromLine(Optional ByVal LineIndex As Long = -1&) As String
        ' returns the text for an entire line
        ' Passing -1 will retrieve the value for the line having the cursor (SelStart)
        Dim lValue As Long, rtnString As String
        Const EM_GETLINE As Long = &HC4
        Const EM_LINEFROMCHAR As Long = &HC9
        Const EM_LINEINDEX As Long = &HBB
        Const EM_LINELENGTH As Long = &HC1
        
        If LineIndex = -1 Then LineIndex = SendMessage(RTB.hWnd, EM_LINEFROMCHAR, LineIndex, ByVal 0&)
        lValue = SendMessage(RTB.hWnd, EM_LINEINDEX, LineIndex, ByVal 0&)
        
        If lValue > -1 Then
            lValue = SendMessage(RTB.hWnd, EM_LINELENGTH, lValue, ByVal 0&)
            If lValue Then
    '            If m_xComm.UnicodeWindow Then
    '                GetTextFromLine = String$(lValue, 0)
    '                CopyMemory ByVal StrPtr(GetTextFromLine), lValue, 4&
    '                SendMessage rtb.hwnd,EM_GETLINE, LineIndex, byval StrPtr(GetTextFromLine)
    '                If lValue = 1 Then GetTextFromLine = Left$(GetTextFromLine, 1)
    '            Else
                    If lValue < 4 Then
                        rtnString = String$(4, vbNullChar)
                    Else
                        rtnString = String$(lValue, vbNullChar)
                    End If
                    Mid$(rtnString, 1, 1) = Chr$(lValue And &HFF)
                    Mid$(rtnString, 2, 1) = Chr$((lValue \ &H100) And &HFF)
                    Mid$(rtnString, 3, 1) = Chr$((lValue \ &H10000) And &HFF)
                    Mid$(rtnString, 4, 1) = Chr$(lValue \ &H1000000)
                    
                    SendMessage RTB.hWnd, EM_GETLINE, LineIndex, ByVal rtnString
                    If lValue < 4 Then
                        GetTextFromLine = Left$(rtnString, lValue)
                    Else
                        GetTextFromLine = rtnString
                    End If
    '            End If
            End If
        End If
    End Function
    
    Private Sub Command1_Click()
        Dim LinIndex As Long
        LineIndex = SendMessage(Poker.hWnd, EM_GETLINECOUNT, 0, ByVal 0) 
        PokerLast.Text = GetTextFromLine(LineIndex-3) & vbNewLine
        PokerLast.Text = PokerLast.Text & GetTextFromLine(LineIndex-2) & vbNewLine
        PokerLast.Text = PokerLast.Text & GetTextFromLine(LineIndex-1)
    End Sub
    Edited: Modified the above code so CopyMemory and array not needed for ANSI windows

    P.S. Change RTB.hWnd to your Poker.hWnd
    One more note. You should modify your logic just a bit should there be less than 3 lines of text returned from your EM_GETLINECOUNT call.

    Edited Again: When I pasted the updated code, I left in a test line of code that needed to be changed. Changed: If lValue > 0 Then To: If lValue > -1 Then
    Last edited by LaVolpe; Feb 14th, 2009 at 10:17 AM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Feb 2009
    Posts
    137

    Re: VB6 Crashing problem

    That seems to be working. ill test it for crashes..
    Thanks for all your help here!
    I will do my best to add you to the credits of my new apps.

  6. #6
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: VB6 Crashing problem

    It should work. Note the changes I made since you last looked. Read the Edited comments. Hope all goes well.

    FYI: Why was it crashing. By filling the buffer with Spaces. You were telling the RTB control that it can copy up to 538976288 characters to your string.
    Most people do not use EM_GETLINE correctly. It is a common mistake not to populate the 1st 4 bytes with the correct string length. Just a simple matter of reading documentation on things one is not familiar with.
    Last edited by LaVolpe; Feb 14th, 2009 at 10:26 AM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Feb 2009
    Posts
    137

    Re: VB6 Crashing problem

    Well it looks like its not going to crash anymore! thanks very much..

    just a quick thing (saves posting new thread).

    Dim PicCard As Control
    PicCard = Card(Index)
    CardPic(Index).Picture = frmCards.PicCard.Picture

    gives error.
    i have 52 picture boxes on frmCards. eg Card2s, Card8h etc.

    but it doesnt load the pictures form those
    Thanks for all your help here!
    I will do my best to add you to the credits of my new apps.

  8. #8
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: VB6 Crashing problem

    What is the range of your control names? Card2s, Card2h, what is etc? The code you posted should generate an error.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  9. #9
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: VB6 Crashing problem

    Joey

    Re those 52 PB's -- did you manually create them in design mode
    and give each it's own name, such as Card2s, Card8h? If so, then
    you can't use "Index" (which is typically a number), as the number
    won't match the given name of each (or any) PB. You'll need to
    write 52 lines of code and refer to each PB individually... a pain !!

    You might try placing PBcard(0) on the form in design mode, ie, just
    one PB manually placed, name it PBcard, and set the Index property
    from blank to 0. Then, in a loop you can Load 52 more if you want.
    Just a possible alternative approach, aka a control array.

    Spoo

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Feb 2009
    Posts
    137

    Re: VB6 Crashing problem

    they are picture boxes.

    i used to use LoadPicture(path) to load image to picture boxes.

    but that means the images have to be in a folder with the EXE.

    so i put all the images in pictureboxes on frmCards.frm so i can load them from the picture boxes there. (faster and less error prone).



    each card is labled Card<value><suit>.picture
    2 of diamonds is Card2d.picture
    King of spades is CardKs.picture

    and so on.

    Card(index) will contain a card number, like "2d", "Ks", "Ah"
    Thanks for all your help here!
    I will do my best to add you to the credits of my new apps.

  11. #11
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: VB6 Crashing problem

    A control array would have been my choice, but it is possible as you have it by using the Controls collection, eg:
    Code:
    Dim PicCard As Control
    Set PicCard = frmCards.Controls("Card" & Index)
    CardPic.Picture = PicCard.Picture
    or just:
    Code:
    CardPic.Picture = frmCards.Controls("Card" & Index).Picture

  12. #12
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: VB6 Crashing problem

    You can also use a Resource file to store those images if you don't want them in a folder. As such you can load then anytime you want without dependency to external files.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

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