Results 1 to 4 of 4

Thread: VB6 code Help

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2005
    Posts
    15

    VB6 code Help

    Hi all

    VB Code:
    1. Public Sub convert(AA, OBUF)
    2.  
    3. ' A small routine to convert fractional hrs to hrs:min
    4.  
    5. '  Pass 0 into output if time is < 0
    6.  
    7. If (AA < 0) Or (AA > 24) Then
    8.  
    9.   OBUF(1) = 99
    10.   OBUF(2) = 99
    11.  
    12. Else
    13.  
    14. '  Pass hrs into OBUF(1) and mins into OBUF(2)
    15.  
    16.  OBUF(1) = Int(AA)
    17.  OBUF(2) = Int(60 * (AA - CDbl(OBUF(1))))
    18.  
    19. End If
    20.  
    21. End Sub

    What I want this code to do is if AA < 0 Or AA > 24 then

    OBUF(1) to = "**" instead of 99
    OBUF(2) to = "**" instead of 99

    Any help appriciated.
    Ed

  2. #2
    Hyperactive Member Dmitri K's Avatar
    Join Date
    Sep 2002
    Location
    West Palm Beach, FL
    Posts
    444

    Re: VB6 code Help

    Declare all variables with proper types, do not leave them undeclared. Leaving them undeclared flags VB to declare all undeclared vars as variants, killing your memory and slowing down the code execution. This might be the source of your problem also. if OBUF is an array of integers, you will not be able to set an element of this array to "**" since ** is a string value. Once your types are fixed, just use OBUF(1) = "**" etc.

    P.S. To enable "undeclared variable check" in VB click on Tools > Options and under Editor tab check Require Variable Declaration. Doing so will automatically add option explicit to the top of every form/module, etc created so all undeclared vars will throw an error upon compilation.

  3. #3
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Re: VB6 code Help

    add option explicit to your module which are already created because checking the Require Variable Declaration option in Tools > Options and under Editor tab will not add option explict to existing modules.
    CS

  4. #4
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Re: VB6 code Help

    adding to Dmitri K,
    VB Code:
    1. Public Sub convert(AA, OBUF)
    Here AA and OBUF are variant datatypes. but in your code you are using it as integer types. so please declare with proper types.

    And also, check out this discussion about option explcit

    You will find other discussions too if you search the forum.
    Last edited by cssriraman; Jun 9th, 2006 at 01:22 PM.
    CS

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