|
-
Jun 9th, 2006, 09:23 AM
#1
Thread Starter
New Member
VB6 code Help
Hi all
VB Code:
Public Sub convert(AA, OBUF)
' A small routine to convert fractional hrs to hrs:min
' Pass 0 into output if time is < 0
If (AA < 0) Or (AA > 24) Then
OBUF(1) = 99
OBUF(2) = 99
Else
' Pass hrs into OBUF(1) and mins into OBUF(2)
OBUF(1) = Int(AA)
OBUF(2) = Int(60 * (AA - CDbl(OBUF(1))))
End If
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
-
Jun 9th, 2006, 09:29 AM
#2
Hyperactive Member
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.
-
Jun 9th, 2006, 01:14 PM
#3
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.
-
Jun 9th, 2006, 01:15 PM
#4
Re: VB6 code Help
adding to Dmitri K,
VB Code:
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|