Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2011
    Posts
    3

    Unanswered: Run-time error with VB6 calling a subroutine

    I am new to VB6 and trying to create an application for my project using VB6. I am having 3 problems in the code during run-time:
    1. If i press the calculate command button on my application i get a compile error: expected function or variable, when I call a sub procedure to another another sub procedure to input datas for numerical calculation.

    2. It gives a second compile error: run-time error 6: Overflow with some of the equations (anodlife, totanodmass, maxgrdresist) as stated below

    3. The third problem has to do with the link to the output form. If I press the calculate command button the output forms: frmcpcalculatedoutput, frmoffcalculatedoutput, will display :run-time error '91' : Object variable or with block variable not set. How can I link the output form to the mother form during compile time so that when I press the execute button on the child form it will cause the output to be displayed on the screen.

    Below are snippets of the code. An urgent help will be appreciated. Thanks
    'Gives me run-time error with the call subs. How do I get rid of it please
    ...
    'Calculate sacrificial Anode mass
    Sub sacranomass()
    Call totcurreq
    Dim totcurrequirement As Integer
    totcurrequirement = totcurreq
    Dim anodlife As Integer
    Dim sacranomass As Integer
    sacranomass = (anodlife * totcurrequirement) / (anodeweight * 49.3)
    End Sub
    Sub protareaanod()
    Call totsurf
    Call sacranomass
    totalsurfacearea = totsurf
    Dim protareaanod As Integer
    protareaanod = totalsurfacearea / sacranomass
    End Sub
    ....
    'Gives me overflow problems. I declared my variables with integer. I tried long but won't end the over flow problem. When do I use Double to declare a numeric data type considering an output less than zero

    'Calculation of anode life anodlife
    Dim anodlife As Integer
    anodlife = (anodeweight * energycapabilty * anoutizatfact) / (8760 * anoutputcurrent)

    'Calculation of anode mass
    Dim totanodmass As Integer
    Dim totcurreq As Integer
    Dim totcurrequirement As Integer
    'Call totcurreq
    totcurrequirement = totcurreq
    totanodmass = (anodlife * totcurrequirement) / (anodeweight * 1000)

    Dim maxgrdresist As Integer
    maxgrdresist = (roh * anodeshapefactor) / ((anoquant) * anodelength) + (roh * parallelingfactor) / (anodespacing)

    Thanks guys for helping out.

  2. #2
    Join Date
    Jul 2011
    Location
    Bandar Abbas - Iran
    Posts
    9

    Hi

    You can not assign a value to a Subroutine !!!
    Define them as Function like : Private Function ABC As Integer

    You are calling routine B in routine A and calling routine A in B !!!! that is why you are getting overflow

    Why your code is like that ?? i think it it basically wrong , what you wanna do ??

    tell me , all will write it for you

  3. #3
    Join Date
    Jul 2011
    Posts
    3

    Run-time error with VB6 calling a subroutine

    Got that figured out already mate. You can imagine how my code looks now.

  4. #4
    Join Date
    Jul 2011
    Posts
    3

    Run-time error with VB6 calling a subroutine

    The overflow problem was not actually due to the calling. It was due to the fact that some of the variables used in the equation were not assigned values and because i was using a sub instead of a function which would have assigned values were i needed them. So there is nothing wrong calling functions into other functions to return values for calculations.

Posting Permissions

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