|
-
May 14th, 2000, 02:38 PM
#1
Thread Starter
Hyperactive Member
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
-
May 14th, 2000, 02:52 PM
#2
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
-
May 14th, 2000, 08:22 PM
#3
Fanatic Member
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!)
-
May 14th, 2000, 08:53 PM
#4
Thread Starter
Hyperactive Member
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
-
May 14th, 2000, 09:09 PM
#5
Frenzied Member
Looks like a VB Bug, Try the API and Check MSDN for a bugfix.
-
May 14th, 2000, 09:29 PM
#6
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")
-
May 14th, 2000, 11:12 PM
#7
Addicted Member
[/code]
Actually, your problem may be that you have a ton of trailing spaces after the 2nd line. Trim it and see what happens.
-
May 15th, 2000, 02:07 PM
#8
Thread Starter
Hyperactive Member
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
-
May 15th, 2000, 05:28 PM
#9
Frenzied Member
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."
-
May 15th, 2000, 08:34 PM
#10
Thread Starter
Hyperactive Member
-
May 16th, 2000, 04:06 PM
#11
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|