Results 1 to 11 of 11

Thread: Weird MsgBox Behavior

  1. #1

    Thread Starter
    Hyperactive Member onerrorgoto's Avatar
    Join Date
    Aug 1999
    Location
    Sweden
    Posts
    330

    Angry

    I hope that someone can explain this for me.

    I use an MsgBox to alert the user that the system is not responding with this code.
    Code:
    Dim pMsg As String * 80
    dim InitSioxErrMess as string
    pMsg = Space(80)
    'initialize the system
    PortNr = InitSioxBus(strComPort, intBaudrate)
    InitSioxBusErrorMsg PortNr, pMsg    'pMsg returns error mess if the system is not responding, pMsg is a string*80 and when I'm testing it returns "The device is not open"
    
    'trim of the returned error mess
    InitSioxErrMess = Mid(pMsg, 1, Len(Trim(pMsg)))
    MsgBox "The system could not get contact with the com-port" & vbCrLf & "Sioxerror : " & InitSioxErrMess & vbCrLf & "The program will close down!", vbOKOnly + vbCritical, "No contact with the com-port!"
    End  Close the program
    this code gives me the following msgbox:
    *************
    The system could not get contact with the com-port
    Sioxerror : " & InitSioxErrMess
    Critical icon & OK-button
    *************

    What I don't get is the third line:
    The program will close down!

    If I try this in a new project with this code:
    Code:
    Private Sub Command1_Click()
    Dim InitSioxErrMess As String
    InitSioxErrMess = "The device is not open"
    MsgBox "The system could not get contact with the com-port" & vbCrLf & "Sioxerror : " & InitSioxErrMess & vbCrLf & "The program will close down!", vbOKOnly + vbCritical, "No contact with the com-port!"
    End Sub
    then I get the following msgbox:
    ******************
    The system could not get contact with the com-port
    Sioxerror : " & InitSioxErrMess
    The program will close down!
    Critical icon & OK-button
    ******************

    This is the three lines of information I want.
    Why does not my app give me three lines in the messagebox?
    First I used pMsg in the msgbox but got only two lines of info, that's when I added the InitSioxErrMess-variable,
    because I thougt the string exeeded the maximum length
    for a msgbox. But with no result.

    I hope someone has an idea.

    [Edited by onerrorgoto on 05-15-2000 at 09:57 AM]
    Onerrorgoto

    Dont be to optimistic, the light at the end of the tunnel might be a train

  2. #2
    Guest
    Why not using a API call for the msgbox, I love API's..

    Code:
    Private Declare Function MessageBox Lib "user32" Alias _
      "MessageBoxA" (ByVal hwnd As Long, ByVal lpText As _
      String, ByVal lpCaption As String, ByVal wType As Long) As Long
    
    Private Sub cmdMsgTest_Click()
      
      Const MB_OKCANCEL = &H1
      Const MB_ICONERROR = &H10
      Const MB_DEFBUTTON1 = &H0
      
      Call MessageBox(Me.hwnd, "Test 1" _
        & Chr(13) & "Test 2" & Space(65) _
        & Chr(13) & "Test 3" & Space(65) _
        & Chr(13) & "Test 4" & Space(65), "Testers", MB_OKCANCEL Or MB_ICONERROR _
        Or MB_DEFBUTTON1)
    
    End Sub

  3. #3
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840
    Well,

    I can't read your error messages but I think I see the problem.

    try:

    Code:
    Call MsgBox( "Systemet kunde inte f$B!&(Bkontakt med Com-porten" & vbCrLf & "Sioxerror : " & InitSioxErrMess & vbCrLf & "Programmet kommer att avslutas!", vbOKOnly + vbCritical, "Ingen kontakt med Comporten!")
    or
    Code:
    dim ReturnVal as integer
    
    ReturnVal =  MsgBox("Systemet kunde inte f$B!&(Bkontakt med Com-porten" & vbCrLf & "Sioxerror : " & InitSioxErrMess & vbCrLf & "Programmet kommer att avslutas!", vbOKOnly + vbCritical, "Ingen kontakt med Comporten!")
    You have to either call the sub as a multi-parameter sub with the CALL keyword or call it as a function with a return value.

    But then I can't read you're errors so I might be wrong

    [Edited by Paul282 on 05-15-2000 at 09:22 AM]
    Paul Dwyer
    Network Engineer
    Aussie In Tokyo

    Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)

  4. #4

    Thread Starter
    Hyperactive Member onerrorgoto's Avatar
    Join Date
    Aug 1999
    Location
    Sweden
    Posts
    330
    Sorry
    It was early in the morning when I wrote my Q

    I dont get any error message with my call.
    What I'm asking is,
    Why doesn't my app write all three lines in the msgbox.

    If you read the code you will see that there is two "vbcrlf" in the first section.

    That should give me a msgbox looking like this
    Line 1
    Line 2
    Line 3

    but my app only gives me line 1 and 2,but if I paste the code into a new project and run it from a commandbutton.
    Then I get all three lines in the messagebox.

    I have edited the original mess to English so Hopefully everyone can read it. Sorry about that.




    Onerrorgoto

    Dont be to optimistic, the light at the end of the tunnel might be a train

  5. #5
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    Looks like a VB Bug, Try the API and Check MSDN for a bugfix.

  6. #6
    Guest
    You can always try to use a function for it.

    Code:
    Private Function MyMsg(InitSioxErrMess As String)
      
      MsgBox "The system could not get contact with the com-port" _
        & vbCrLf & "Sioxerror : " & InitSioxErrMess & vbCrLf & _
        "The program will close down!", vbOKOnly + vbCritical, _
        "No contact with the com-port!"
    
    End Function
    And call the function.
    Code:
      Call MyMsg("The device is not open")

  7. #7
    Addicted Member
    Join Date
    Mar 2000
    Location
    Gainesville, FL
    Posts
    131
    [/code]
    Actually, your problem may be that you have a ton of trailing spaces after the 2nd line. Trim it and see what happens.

  8. #8

    Thread Starter
    Hyperactive Member onerrorgoto's Avatar
    Join Date
    Aug 1999
    Location
    Sweden
    Posts
    330
    Originally posted by Raydr
    [/code]
    Actually, your problem may be that you have a ton of trailing spaces after the 2nd line. Trim it and see what happens.


    So what you are saying is that I cant have two spaces in the second line?
    So "Sioxerror : " should look like "Sioxerror:"??

    Or are talking about this:
    Code:
    Dim pMsg As String * 80
    dim InitSioxErrMess as string
    '*************
    pMsg = Space(80)      'Many trailing spaces
    '**************
    'initialize the system
    PortNr = InitSioxBus(strComPort, intBaudrate)
    InitSioxBusErrorMsg PortNr, pMsg    'pMsg returns error mess if the system is not responding, pMsg is a string*80 and when I'm testing it returns "The device is not open"
    
    'trim of the returned error mess
    '**************
    InitSioxErrMess = Mid(pMsg, 1, Len(Trim(pMsg)))   'No trailing spaces
    '*****************
    MsgBox "The system could not get contact with the com-port" & vbCrLf & "Sioxerror : " & InitSioxErrMess & vbCrLf & "The program will close down!", vbOKOnly + vbCritical, "No contact with the com-port!"
    End  Close the program
    If this is what you are talking about,then it doesn't make any difference. If not please explain more.

    Onerrorgoto

    Dont be to optimistic, the light at the end of the tunnel might be a train

  9. #9
    Frenzied Member Buzby's Avatar
    Join Date
    Jan 1999
    Location
    UK
    Posts
    1,670
    Personally I think you'll find that the error message ends with a load of NULLS (CHR(0)) - this would mean anything following it would be lost.

    Try this;

    Dim NullFind as Integer
    NullFind=Instr(pMsg,Chr(0))
    If NullFind>0 Then
    InitSioxErrMess = Left(pMsg,NullFind-1)
    Else
    InitSioxErrMess = pMsg
    Endif

    InitSioxErrMess=Trim(InitSioxErrMess)
    MsgBox "The system could not get contact with the com-port" & vbCrLf & "Sioxerror : " & InitSioxErrMess & vbCrLf & "The program will close down!", vbOKOnly + vbCritical, "No contact with the com-port!"

    Nulls are NOT TRIMmed by the TRIM command. It's happened to me a while back when I tried retrieving info from a strange accounts package...

    [Edited by Buzby on 05-16-2000 at 11:28 AM]
    'Buzby'
    Visual Basic Developer
    "I'm moving to Theory. Everything works there."

  10. #10

    Thread Starter
    Hyperactive Member onerrorgoto's Avatar
    Join Date
    Aug 1999
    Location
    Sweden
    Posts
    330

    Talking Thank you

    Buzby, you are the man!!!

    I love you.
    And all the rest of you who have taken your
    time to try to help me.

    Your code worked, now I get all three line in my
    msgbox.
    I had no idea that null were not removed with Trim.
    MSDN does not say anything about it.

    Thanks again to all
    Onerrorgoto

    Dont be to optimistic, the light at the end of the tunnel might be a train

  11. #11
    Frenzied Member Buzby's Avatar
    Join Date
    Jan 1999
    Location
    UK
    Posts
    1,670
    TRIM doesn't clear NULLS -it's a pain in the neck!
    Glad I could help!

    'Buzby'
    Visual Basic Developer
    "I'm moving to Theory. Everything works there."

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