Beginner VB

Moderators: None (Apply to moderate this forum)
Number of threads: 1233
Number of posts: 2978

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
problem in programming Posted by satsoc on 24 Apr 2002 at 2:14 PM
in the following code i can't reveal q's value on the Label1.Also i have no run time errors,so i don't know what is the problem.
------------------------------------------------------------------------
dim q as variant

If (CDec(Text1.Text) > 0 And CDec(Text2.Text) > 0 And CDec(Text3.Text)> 0 And CDec(Text4.Text) > 0 Then

q = CDec((Val(Text1.Text) * Val(Text2.Text)) / (Val(Text1.Text) + Val(Text2.Text)) + (Val(Text3.Text) * Val(Text4.Text)) / (Val(Text4.Text) + Val(Text3.Text)))
Label1.Caption = q
------------------------------------------------------------------------
after that Label1.Caption remains null
Have you got any idea what the problem might be?

Report
Re: problem in programming Posted by goaty on 24 Apr 2002 at 8:48 PM
: in the following code i can't reveal q's value on the Label1.Also i have no run time errors,so i don't know what is the problem.
: ------------------------------------------------------------------------
: dim q as variant
:
: If (CDec(Text1.Text) > 0 And CDec(Text2.Text) > 0 And CDec(Text3.Text)> 0 And CDec(Text4.Text) > 0 Then
:
: q = CDec((Val(Text1.Text) * Val(Text2.Text)) / (Val(Text1.Text) + Val(Text2.Text)) + (Val(Text3.Text) * Val(Text4.Text)) / (Val(Text4.Text) + Val(Text3.Text)))
: Label1.Caption = q
: ------------------------------------------------------------------------
: after that Label1.Caption remains null
: Have you got any idea what the problem might be?
:
:
I'm taking a fly on this one,but i think that maybe you are trying to do a mathematical equation ,but you are using characters aswell as numbers?.Try to change the 'q' variable to "dim q as integer"

I hope i have helped u in anyway.

thnx goat

ps. E-mail me the program and i will have a look at it

Goatslasher@mweb.co.za


Report
Re: problem in programming Posted by KDivad Leahcim on 25 Apr 2002 at 5:55 AM
: Try to change the 'q' variable to "dim q as integer"

q must be variant to accept a Decimal value. That part's correct.

Is the math part ever evaluated? Or does the If statement always jump over it?
Report
Re: problem in programming Posted by satsoq on 26 Apr 2002 at 7:41 AM
well you see we don't care about the evaluation part.q might be everything >0 or <0.the main problem is that i don't want q to be an integer.decimals are very important for the result.
Report
Re: problem in programming Posted by KDivad Leahcim on 27 Apr 2002 at 11:47 AM
: well you see we don't care about the evaluation part.q might be everything >0 or <0.the main problem is that i don't want q to be an integer.decimals are very important for the result.
:

I dunno, it works perfectly for me once I remove the first ( in the If line.
Report
Re: problem in programming Posted by KDivad Leahcim on 27 Apr 2002 at 11:56 AM
: : well you see we don't care about the evaluation part.q might be everything >0 or <0.the main problem is that i don't want q to be an integer.decimals are very important for the result.
: :
:
: I dunno, it works perfectly for me once I remove the first ( in the If line.
:

Just out of curiousity, do you need the precision of the Decimal data type? You say that decimals are very important, but how many places do you need?

Single (single-precision floating-point)
-3.402823E38 to -1.401298E-45 for negative values;
1.401298E-45 to 3.402823E38 for positive values

Double (double-precision floating-point)
-1.79769313486232E308 to -4.94065645841247E-324 for negative values;
4.94065645841247E-324 to 1.79769313486232E308 for positive values

Currency (scaled integer)
-922,337,203,685,477.5808 to 922,337,203,685,477.5807

Any of them are going to be faster than working with the Decimal data type due to conversion and Variant overhead. Decimal is more accurate (28 places), but I rarely hear of a need for that precision...
Report
Re: problem in programming Posted by satsoq on 28 Apr 2002 at 4:09 AM
well man i am a newbie in visual basic,i don't need all the 28 decimal places just three of them,so i thought to use a function which is called round(a,b).i just need four decimals but that's way i said that i don't need val(),but cdec(),or cdbl(most probably).
Report
Re: problem in programming Posted by KDivad Leahcim on 28 Apr 2002 at 5:54 AM
: well man i am a newbie in visual basic,i don't need all the 28 decimal places just three of them,so i thought to use a function which is called round(a,b).i just need four decimals but that's way i said that i don't need val(),but cdec(),or cdbl(most probably).
:

Personally, I would do something like the following:
On Error Resume Next
    Label1.Caption = Val(...) ........ 'calculations here
    If Err.Number <> 0 Then
        'Error occured, bad values most likely
        MsgBox "Bad values!"
    Else
        'no error
    End If
On Error Goto 0

That might eliminate the need for any type-casting and retain plenty of decimal places.
Report
Re: problem in programming Posted by satsoq on 12 May 2002 at 12:26 PM
well i wrote this but i doesn't seem to work.

Private Sub Combo1_Click()

On Error Resume Next

Text3.Text = Val(Salary(Combo1.ListIndex))
If Err.Number <> 0 Then

'Error occured, bad values most likely

MsgBox "Bad values!"

Else

'no error

End If

On Error GoTo 0

End Sub

Private Sub Form_Load()
Dim I ' Declare variable.
AutoSize = True

Player(0) = "n&#937;"
Player(1) = "&#956;&#937;"
Player(2) = "m&#937;"
Player(3) = "&#937;"
Player(4) = "&#922;&#937;"
Player(5) = "&#924;&#937;"
Player(6) = "G&#937;"
For I = 0 To 6 ' Add names to list.
Combo1.AddItem Player(I)
Next I
Combo1.ListIndex = 4 ' Display first item in list.




If IsNumeric(Text1.Text) = True Then

Salary(0) = CDbl(Val(Text1) / 1000000000)
Salary(1) = CDbl(Val(Text1) / 1000000)
Salary(2) = CDbl(Val(Text1) / 1000)
Salary(3) = CDbl(Val(Text1))
Salary(4) = CDbl(Val(Text1) * 1000)
Salary(5) = CDbl(Val(Text1) * 1000000)
Salary(6) = CDbl(Val(Text1) * 1000000000)
For I = 0 To 6 ' Add names to list.
Combo1.AddItem Player(I)
Next I
Combo1.ListIndex = 4 ' Display first item in list.
End If

If (CDec(Text1.Text) > 0 And CDec(Text4.Text) > 0 And CDec(Text5.Text) > 0 And CDec(Text6.Text) > 0 And CDec(Text12.Text) > 0) Then
If IsNumeric(Text21.Text) = True And IsNumeric(Text22.Text) = True And IsNumeric(Text18.Text) = True And IsNumeric(Text19.Text) = True And IsNumeric(Text3.Text) = True Then 'And IsNumeric(txt_Result1.Text) = True And IsNumeric(txt_Result2.Text) = True Then

a = CDec(Val(Text21.Text) * Val(Text22.Text)) / (CDec(Val(Text21.Text) + Val(Text22.Text))) + CDec(Val(Text20.Text) * Val(Text3.Text)) / (CDec(Val(Text3.Text) + Val(Text20.Text)))
b = CDec(Val(Text21.Text) * Val(Text18.Text)) / (CDec(Val(Text21.Text) + Val(Text22.Text))) - CDec(Val(Text20.Text) * Val(Text18.Text)) / (CDec(Val(Text3.Text) + Val(Text20.Text)))
txt_Result1 = CDec(Val(Text19.Text) * b) / (CDec(Val(Text19.Text) + a))
txt_Result2 = CDec(Val(txt_Result1)) / CDec(Val(Text19.Text))
Label6.Caption = Val(txt_Result1)
Label7.Caption = Val(txt_Result2)

this doesn't show the values either.(there are many combo boxes like the Salary one,so don't be surprised by the other texts that appears)

any other ideas please???
Report
Re: problem in programming Posted by KDivad Leahcim on 15 May 2002 at 7:04 AM
: this doesn't show the values either.(there are many combo boxes like the Salary one,so don't be surprised by the other texts that appears)
:
: any other ideas please???
:

I'm lost. I don't see where a problem might be occuring in that code. Have you gone through it step by step to see what values are being used and make sure each statement is executing as you expect it to?



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.