?
Solved

When compiled, the program gives an error

Posted on 2003-03-12
41
Medium Priority
?
266 Views
Last Modified: 2008-02-01
Having the following wierd (at least to me :) problem.

When running the program in visual studio, everything is fine, it runs and does what it's supposed to do.
When i compile the thing, and run the exe, i get a run-time error "13" , "Type mismatch"

Any suggestions?, i'm also willing to send the code

thx
0
Comment
Question by:LaMoS
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 17
  • 9
  • 7
  • +5
41 Comments
 
LVL 43

Expert Comment

by:TimCottee
ID: 8118186
Hi LaMoS,

Please do include some of your code, especially the section which generates the error and any calling procedure as appropriate. Without this it will be pure guesswork to find a solution for you.

Tim Cottee MCSD, MCDBA, CPIM
http://www.timcottee.tk 

Brainbench MVP for Visual Basic
http://www.brainbench.com

Experts-Exchange Advisory Board Member
0
 

Author Comment

by:LaMoS
ID: 8118217
Yeah, TimCoffee, that's my problem, it only gives an error when compiled, so i can't see any code of it, i also wouldn't know where the error comes from. I can send you the code, (email)?
0
 

Author Comment

by:LaMoS
ID: 8118258
Yeah, TimCoffee, that's my problem, it only gives an error when compiled, so i can't see any code of it, i also wouldn't know where the error comes from. I can send you the code, (email)?
0
Technology Partners: 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!

 
LVL 8

Expert Comment

by:drydenhogg
ID: 8118293
Tim's right in that its pure guesswork.

When ive seen this kind of problem before it was due to the reference to the scripting library in the project. But in that instance the compiled exe was being run on a different machine with an older scripting runtime. It didn't occur on the same machine.

Do you know which routine is causing the error? if so as archaic as it sounds, line number that routine and use erl to output the line number the error occured on, that will at least give you a better idea of whats causing it.

ADH.
0
 

Author Comment

by:LaMoS
ID: 8118361
sorry, i do know when it occurs, because in the form_load it loads up another form, that one doesn't even show
but i would have no idea what could generate that type mismatch...

i can send the code if you'd like
0
 
LVL 1

Expert Comment

by:rafsalman
ID: 8118480
You could check that when you are running your code that you are breaking on the right type of errors to detect it

e.g. try breaking on all errors and tracing through the same part of the application that gives you the mismatch error.

0
 
LVL 2

Expert Comment

by:uncle_med
ID: 8118481
This is a bit of a guesswork, so do send the code. Can't you just copy and paste it here?
My advice is to always have error traps in your programs. Take a look at this little example below. It generates an error 13, just like yours but if you trap the error, you'd know where to go looking for the problem.


Private Sub SubName()
    Dim x As Long
   
    On Error GoTo ErrHandler
   
    x = 1
    x = 2
    x = 3
    x = ""
    Exit Sub
ErrHandler:
   
    MsgBox "Error in procedure [SubName] " & Err.Number & ". " & Err.Description
   

End Sub


Med
0
 

Author Comment

by:LaMoS
ID: 8118524
all the way at the end, the .show of frmPasswordBox doesn't occur :S

thx for the help :)

----code----

Private Sub Form_Load()

txtSendCMDOutput.Width = (frmMain.Width - 90) / 2
txtReadDataOutput.Width = (frmMain.Width - 90) / 2

txtSendCMDOutput.Left = 0
txtReadDataOutput.Left = txtSendCMDOutput.Width

txtSendCMDOutput.Height = frmMain.Height - 6345
txtReadDataOutput.Height = frmMain.Height - 6345

lblReadDataOutput.Left = txtReadDataOutput.Left + 240

frmMain.Caption = "SpaceChecker Universal Messenger ver. " & App.Major & "." & App.Minor

'Create an instance of the WinHTTPRequest ActiveX object.
Set WinHttpReq = New WinHttpRequest

'Reading the User TEMP directory
strBuffer = String$(255, 0)
lngReturn = GetTempPath(Len(strBuffer), strBuffer)
userTempPath = Left$(strBuffer, lngReturn)

'Read preferences
file3 = FreeFile
Open "preferences.dat" For Random As #file3
Get #file3, 1, record
lblLogin.Caption = Trim(record)
Get #file3, 2, record
lblGatewayURL.Caption = Trim(record)
Get #file3, 3, record
lblBMDO.Caption = Trim(record)

login = lblLogin.Caption
serverPath = lblGatewayURL.Caption
bmdo = lblBMDO.Caption

If not1stTime = False Then
    start = True
    not1stTime = True
End If

cmbInterval.Clear
cmbInterval.AddItem (5)
cmbInterval.AddItem (10)
cmbInterval.AddItem (15)
cmbInterval.AddItem (30)
cmbInterval.AddItem (60)
cmbInterval.Text = 30

file1 = FreeFile
Open "binairymessages.dat" For Random As #file1

Y = 0
For i = 1 To 65535
    Get #file1, i, record2
    txtTemp.Text = Trim(record2.naam)
    If txtTemp.Text = "" Then
        Y = i - 1
        Exit For
    End If
Next i

For i = 1 To Y
    Get #file1, i, record2
    cmbPBM.AddItem (Trim(record2.naam))
Next i

file6 = FreeFile
Open "codifiedmessages.dat" For Random As #file6

Y = 0
For i = 1 To 65535
    Get #file6, i, record3
    txtTemp.Text = Trim(record3.naam)
    If txtTemp.Text = "" Then
        Y = i - 1
        Exit For
    End If
Next i

For i = 1 To Y
    Get #file6, i, record3
    cmbPCM.AddItem (Trim(record3.naam))
Next i

frmPasswordBox.Show

End Sub
0
 

Author Comment

by:LaMoS
ID: 8118570
btw, how can you break on all errors?
0
 
LVL 8

Expert Comment

by:drydenhogg
ID: 8118572
Given no error handling visible I get the feeling you have made an assumption that line contains the error because the form doesnt show.

The error could easily be originating from the code within the load event of the form. (As well as a few other events fired before show goes thru)

Post the code from that frmPasswordBox (if any exists.) I suspect the error is originating in there and is totally unhandled, is dropping out and vb is just displaying its default tiny msgbox Type Mismatch with no additional details like procedure etc.

ADH.


0
 
LVL 8

Expert Comment

by:drydenhogg
ID: 8118576
Given no error handling visible I get the feeling you have made an assumption that line contains the error because the form doesnt show.

The error could easily be originating from the code within the load event of the form. (As well as a few other events fired before show goes thru)

Post the code from that frmPasswordBox (if any exists.) I suspect the error is originating in there and is totally unhandled, is dropping out and vb is just displaying its default tiny msgbox Type Mismatch with no additional details like procedure etc.

ADH.


0
 

Author Comment

by:LaMoS
ID: 8118588
ok, here's the code of frmPasswordBox

---code---
Option Explicit
Dim change As Boolean


Private Sub cmdCancel_Click()

change = False
frmMain.populate = False
Unload Me

End Sub

Private Sub cmdOk_Click()

frmMain.lblPassword.Caption = txtPasswordBox.Text
Unload Me

End Sub

Private Sub Form_Load()

change = False
frmMain.populate = False

End Sub

Private Sub Form_Unload(Cancel As Integer)

If change = False Then
    MsgBox "No password has been entered, the program wil not be able to execute", vbOKOnly + vbExclamation, "No password"
End If

End Sub

Private Sub txtPasswordBox_Change()

If txtPasswordBox.Text = "" Then
    change = False
    frmMain.populate = False
    Else
        change = True
        frmMain.populate = True
End If

End Sub

Private Sub txtPasswordBox_KeyPress(KeyAscii As Integer)

If KeyAscii = 13 Then 'when ENTER is pressed
    If Len(txtPasswordBox.Text) <> 0 Then
        change = True
        frmMain.populate = True
    End If
    frmMain.lblPassword.Caption = txtPasswordBox.Text
    Unload Me
End If

End Sub
0
 
LVL 1

Expert Comment

by:rafsalman
ID: 8118593
to break on all errors, right click on your form window and select Toggle|break on All Errors
0
 

Author Comment

by:LaMoS
ID: 8118611
sor rafsalman, but it doesn't show a toggle option, only view code, menu editor, lock controls, paste, properties and update usercontrols
0
 
LVL 8

Expert Comment

by:drydenhogg
ID: 8118640
Raf meant right click on your code window for the form, not the form itself, that has a toggle menu option
0
 
LVL 1

Expert Comment

by:rafsalman
ID: 8118654
yes sorry :)
0
 

Author Comment

by:LaMoS
ID: 8118659
ow, like that :)

but, still, doesn't give any errors...
0
 
LVL 8

Expert Comment

by:drydenhogg
ID: 8118675
Following the trail, post the code for frmmain.populate, have you got it as a public variable, or a property with code within it?

ADH.
0
 

Author Comment

by:LaMoS
ID: 8118694
in the general:

Public populate As Boolean

then in the form_activate

Private Sub Form_Activate()

Randomize
formStart

End Sub

and the formStart:

Private Sub formStart()

login = lblLogin.Caption
password = lblPassword.Caption
serverPath = lblGatewayURL.Caption
bmdo = lblBMDO.Caption

If start = True Then
    exitFlag = False
    checkLogin
    frmPasswordBox.Refresh
    frmPasswordBox.SetFocus
    start = False
    If exitFlag = True Then
        Exit Sub
    End If
End If

If lblLogin.Caption <> "" Then
    login = lblLogin.Caption
End If
If lblPassword.Caption <> "" Then
    password = lblPassword.Caption
End If
If lblGatewayURL.Caption <> "" Then
    serverPath = lblGatewayURL.Caption
End If

If populate = True Then
    populate = False
    populateComboBox
End If

End Sub


and the populateComboBox

Private Sub populateComboBox()

varStartMessage = "Polulating combobox with ModemID's"
startMessage

'Assemble an HTTP Request.
scriptPath = serverPath & "listModems?login=" & login & "&password=" & password

varHttpMessage = "Request for listModems"
varFileName = "listmodems.xml"
sendHttpLoadXml

Set docRoot = doc.documentElement
For Each docElement In docRoot.childNodes
    Set objAttributes = docElement.Attributes
    Set objAttributeNode = objAttributes.getNamedItem("modemID")
    cmbModemID.AddItem (objAttributeNode.Text)
Next

frmMain.MousePointer = 0
txtSendCMDOutput.Text = txtSendCMDOutput.Text & vbCrLf & "Combobox ModemID populated"
txtSendCMDOutput.Text = txtSendCMDOutput.Text & vbCrLf & "------------------------------------------------"
txtSendCMDOutput.SelStart = Len(txtSendCMDOutput.Text)

End Sub


happy reading :) (really don't want me to send the whole project)?
0
 
LVL 2

Expert Comment

by:uncle_med
ID: 8118695
Send your declarations (Record, login, bmdo,...) please? Is Record a string type? The error is more likely to be in assigning a wrong type to a variable.

While the experts are looking at your program, you might trying putting some message boxes in your form load event.

example

Private Sub Form_Load()
   msgbox "form loading"
   txtSendCMDOutput.Width = (frmMain.Widt ...
   .... code ....
   .... code ....
   .... code ....
   Msgbox "About to open file"
   Open "preferences.dat" For Random As #file3
   .... code ....
   .... code ....
   .... code ....


 and so on. Once you've done that, compile and make .exe. Run to see how far it goes.

0
 

Author Comment

by:LaMoS
ID: 8118707
Option Explicit

Dim d() As Byte
Dim WinHttpReq As WinHttp.WinHttpRequest
Dim scriptPath As String
Dim serverPath As String
Dim login, password As String
Dim epochTime, serverTime As Long 'both in epoch format
Dim midnightEpoch, nextPoll As Long
Dim serverNow As String 'in CET date & time
Dim delay As Integer
Dim codifiedMessage As Long
Dim binaryMessage As String
Dim userTempPath As String
Dim tempFilePath As String
Dim file1, file2, file3, file6, i, j, nummer, Y As Integer
Dim counter As Integer
Dim rest As Integer
Dim timeStamp As String
Dim lngReturn As Long
Dim strBuffer As String
Dim record As String * 128
Dim start As Boolean
Dim not1stTime As Boolean
Dim modemID As String
Dim days, hours, minutes, seconds As Long
Dim svrYear As String * 4 'Current Server Date
Dim svrMonth, svrDay As String * 2
Dim pcDay, pcHour, pcMinute, pcSecond As Integer 'Current Pc Time & Date
Dim clcDay, clcHour, clcMinute, clcSecond As String * 2 'Result of calculations
Dim interval As Integer 'in seconds
Dim exitFlag, whileFlag As Boolean
Dim varStartMessage, varHttpMessage, varFileName, varEndMessage As String
Dim doc As New DOMDocument30
Dim message As String
Dim errorCode As String
Dim random As String
Dim forListenInterval, forListenTimeslot As Integer
Dim mode As Byte
Dim box As Byte
Dim bmdo As Integer

Private Type bin
    naam As String * 50
    code As String * 40
End Type
Dim record2 As bin
Dim noe As String
Private Type bin2
    naam As String * 50
    code As String * 5
End Type
Dim record3 As bin2
Dim cm As String

Public populate As Boolean

Dim docRoot As IXMLDOMElement
Dim docElement As IXMLDOMElement
Dim objAttributes As IXMLDOMNamedNodeMap
Dim objAttributeNode As IXMLDOMNode

Private Declare Function GetTempPath _
               Lib "kernel32" _
               Alias "GetTempPathA" _
               (ByVal nBufferLength As Long, _
               ByVal lpBuffer As String) As Long
0
 
LVL 8

Expert Comment

by:drydenhogg
ID: 8118725
Side comment :
Dim X,Y as integer does not produce 2 integer variables.

X will be variant, default value of empty
Y will be integer, default value of 0

Most of your variable declarations look to be incorrect.

ADH.
0
 

Author Comment

by:LaMoS
ID: 8118737
drydenhogg, what do you mean by variant?, never heard of it :)
uncle_med: thx for the tip i've found the wrong line:

bmdo = lblBMDO.Caption

it's in the form_load, i've changed it to bmdo = CInt(lblBMDO.Caption), since bmdo is declared as an integer, but still no go
0
 
LVL 8

Expert Comment

by:drydenhogg
ID: 8118768
Any variable that is not declared with a type
like

dim myvar

defaults to a data type called variant. Its a catch-all data type that can contain pretty much any type of information, from string to objects.
There are large discussions over the use of variants, some people consider them bad, some good.

There are two ways you can avoid getting a variant.
Declare the variable with a type i.e.
dim myvar as string
or alter the default datatype using something lik
devstr [a-z]   (I've never seen anyone actually do this option, and I wouldnt recommend its, its very lazy coding imho.)

VB requires that all variables are declared with type individually, thus
Dim X as integer, Y as integer
will produce 2 integer variables,
Dim X,Y as integer
will produce 1 variant, 1 integer.

This is easy to see in practise, since the default values change, in a blank project write

dim X,Y as integer
msgbox X
msgbox Y

First msgbox will show a blank msgbox (the value is a special value in vb called empty.)
The second will show the msg '0' since that is the default value of an integer.

Repeat the test with

Dim X as integer, Y as integer
msgbox X
msgbox Y

and both msgboxes will show '0' as the message.

Taken from your code
Dim clcDay, clcHour, clcMinute, clcSecond As String * 2 'Result of calculations

In this declaration only clcSecond is a string of length 2.
clcDay, clcHour, clcMinute are all variant.

I hope this makes it slightly clearer

ADH.







0
 

Author Comment

by:LaMoS
ID: 8118801
thx for the info drydenhogg, very interesting

my declarations have been adjusted, but stil nothing for that error
0
 
LVL 8

Expert Comment

by:drydenhogg
ID: 8118832
I would still definately recommend adding error handling to the application, in every procedure.

function somefunction(byval some param etc)

on error goto errhandler

'code here

exit function

errhandler:

  msgbox "Error in somefunction." & vbcrlf & _
    "description : " & err.description & _
    "source : " & err.source & _
    "line : " & erl

end function

The erl will only work if you line number your code but for this kind of issue its worth the few mins to do it. (There are automatic line numbering programs available, its common to line number code after testing, just before release, you dont tend to code with it during dev phase, would be too much hassle.)
Only line number the executable lines of code as so

dim x as integer, y as integer  
dim z as double

1 x =0
2 y = 5
3 z = y / x
4 msgbox z

When this errors with a div by 0, erl will be 3. This will pinpoint the exact line the error has occured on.

ADH.

0
 
LVL 1

Expert Comment

by:rafsalman
ID: 8118870
Agreed. You may be able to avoid the majority of line numbering using the following around your code modules


On Error Goto ErrorHandler

 
 
 
Procedure_Exit:
  Exit Function
 
 
ErrorHandler:
  Select Case Err.Number
 
    Case Else
      GlobalErr Err.Number, Err.Description, "Name_of_form"
      Resume Procedure_Exit:
      Resume
 
  End Select
 
End Function/Sub


*******************************************

And adding the following module (bas)
*********************************************
Public Sub GlobalErr(lngErrNumber As Long, _
                     strErrDescription As String, _
                     Optional strErrLocation As String)
'***************************************************************************
'Purpose:     Control errors for all forms in the system.
'Parameters:  lngErrNumber      - The error number raised.
'             strErrDescription - The full description of the error.
'             strErrLocation    - The function that raised the error.
'Returns:     None.
'***************************************************************************
On Error GoTo ErrorHandler

Dim strMessage As String
Dim intSeverity As Integer
Dim strErrorType As String

  Select Case lngErrNumber


'list of error cases


If Not IsNothing(strErrLocation) Then
      strMessage = strMessage & " In: " & strErrLocation
    End If
 
  End Select
 
  MsgBox strMessage, vbOKOnly + intSeverity, strErrorType

Procedure_Exit:
  Exit Sub
   
ErrorHandler:
  Select Case Err.Number
 
    Case Else
      GlobalErr Err.Number, Err.Description, "GlobalErr"
      Resume Procedure_Exit
      Resume
 
  End Select

End Sub
0
 
LVL 8

Expert Comment

by:bukko
ID: 8118890

You can get more detail very simply by placing text at each point in the code.
Add the following to the start of every sub/function:

Const THIS_FUNCTION As String = "myFunction"
Dim strErrorHelp As String
On Error Goto eh_function

...then, at intervals in the code, add a description, e.g.:

strErrorHelp = "About to ... blah blah blah"

...and at the end of each sub/function, add

CleanUp:
    Exit Sub/Function
eh_function:
    Err.Raise Err.Number, _
              THIS_FUNCTION & ":" & Err.Source, _
              Err.Description & " (" & strErrorHelp & ")"
    Resume Cleanup

...This will help you accurately identify exactly where the problem is occuring, even when the compiled version is run.

Regards

bukko
0
 

Author Comment

by:LaMoS
ID: 8118968
ok, did that, used vbDevellopment Tools to generate the line numbers and placed the error handler in the form_load, it captures the error, on line 42700, but there is no line 42700 :S
0
 

Author Comment

by:LaMoS
ID: 8118977
thx bukko, but i know with the help of msgboxes where the thing goes wrong (see previous posts)
0
 

Author Comment

by:LaMoS
ID: 8119069
ok, using drydenhogg's solution, it now gives error @ line 934 (i now used another linenumbering program vbcoder...)

934     bmdo = CInt(lblBMDO.Caption)
0
 
LVL 2

Expert Comment

by:uncle_med
ID: 8119121
Well in that case


is line 934 in load event???
I think lblBMDO.Caption contains a value that can't be converted. I have a strong feeling, your program is trying to convert to integer something that can't be converted. It may be an empty string "".
0
 
LVL 2

Accepted Solution

by:
uncle_med earned 800 total points
ID: 8119134
LaMoS

replace line 934 with

If not isnumeric(lblBMDO.Caption) Then
   bmdo = 0
else
   bmdo = CInt(lblBMDO.Caption)
End If
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 8119218
Use  'on error resume next'
0
 
LVL 8

Expert Comment

by:drydenhogg
ID: 8119224
Looks like were getting closer, and I would agree with uncle_med, the cint is attempting to convert a non numeric value.
(A number too large should kick an overflow msg opposed to type mismatch.)

Its archaic, it sounds nuts, but the precision in tracking an error with line numbering is hard to beat.

ADH.




0
 
LVL 2

Expert Comment

by:uncle_med
ID: 8120092
LaMoS

replace line 934 with

If not isnumeric(lblBMDO.Caption) Then
   bmdo = 0
else
   bmdo = CInt(lblBMDO.Caption)
End If
0
 
LVL 2

Expert Comment

by:uncle_med
ID: 8120150
LaMoS

replace line 934 with

If not isnumeric(lblBMDO.Caption) Then
   bmdo = 0
else
   bmdo = CInt(lblBMDO.Caption)
End If
0
 
LVL 2

Expert Comment

by:uncle_med
ID: 8120183
Sorry  Gents
refreshed the page a couple of times, hence the duplicate comments!
0
 
LVL 1

Expert Comment

by:wolfrose
ID: 8122335
I like message boxes in error handling also myself.  Instead of the if statement, put:
msgbox lblBMDO.Caption

That way you know for sure if that is what the problem is
0
 

Author Comment

by:LaMoS
ID: 8134961
Thx for the support, i've found what it was, i solved it by replacing it with:

If lblBMDO.Caption = "" Then
    bmdo = 0
    Else
        bmdo = Cint(lblBMDO.Caption)
End if

thx for the help, and sorry for my late reply, but i was busy debugging other parts of the program :)

sorry uncle_med, i'll give the points to drydenhogg, with his errorhandler i've found it (damm, wished i could give points to multiple persons)
0
 

Author Comment

by:LaMoS
ID: 8134970
sorry again :(

i re-read everything again and the credit goes to uncle_med after all, i did found the problem with his message boxes and the error handler of drydenhogg just gave the same outcome.

His solution in the end was also correct (although i've found  the same solutions about the same time)
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

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…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses

762 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