-
Oct 20th, 2013, 10:52 PM
#1
Thread Starter
Lively Member
VB6 Calculation
Hai..I'am using VB6..I want do some calculations..If the weight is 1.2 then X = 2..my code looks like this:
nilai = $10.00
If txtWeight.Text > 1 Then x = 2
If txtWeight.Text > 2 Then x = 3
If txtWeight.Text > 3 Then x = 4
If txtWeight.Text > 4 Then x = 5
If txtWeight.Text > 5 Then x = 6
If txtWeight.Text > 6 Then x = 7
.
.
.
.
If txtWeight.Text > 100 Then x = 1001
lblPos.Caption = FormatCurrency(nilai * x, 2, vbTrue, vbTrue, vbTrue)
How can I make the code as simple as possible?
-
Oct 20th, 2013, 11:06 PM
#2
Re: VB6 Calculation
You could do something along these lines.
Code:
Option Explicit
Dim nilai As Currency, x As Integer
Private Sub Command1_Click()
nilai = 10#
Select Case txtWeight.Text
Case 1
x = 2
Case 2
x = 3
Case 3
x = 4
Case 4
x = 5
Case 5
x = 6
Case 6
x = 7
End Select
If txtWeight.Text = x Then x = txtWeight.Text + 1
End Sub
Private Sub txtWeight_Validate(Cancel As Boolean)
If Not IsNumeric(txtWeight.Text) Then MsgBox "Please number only numbers!"
End Sub
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Oct 20th, 2013, 11:49 PM
#3
Thread Starter
Lively Member
Re: VB6 Calculation
if txtWeight.text > 100 so I have to do until case is 100? Wow it's too long again if the value is 1 then X still 1 but if the value is 1.01 then X will become 2.
Last edited by mdtam; Oct 21st, 2013 at 12:19 AM.
-
Oct 21st, 2013, 01:37 AM
#4
Re: VB6 Calculation
Originally Posted by mdtam
Code:
lblPos.Caption = FormatCurrency(nilai * x, 2, vbTrue, vbTrue, vbTrue)
How can I make the code as simple as possible?
Code:
lblPos.Caption = FormatCurrency(nilai * -Int(-CDbl(txtWeight.Text)), 2&, vbTrue, vbTrue, vbTrue)
See Rounding Up section in How To Implement Custom Rounding Procedures for more details.
On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)
-
Oct 21st, 2013, 07:38 AM
#5
Re: VB6 Calculation
another way that could work would be to check for the decimal point and if present drop it and add 1
Code:
x=instr(txtweight.text)
If x>0 then
Weight=Cint(left$(txtweight.text,x-1))+1
Else
Weight=Cint(txtWeight.Text)
End If
Assuming of course that you are not going to have an entry of x.00
-
Oct 21st, 2013, 07:55 AM
#6
Thread Starter
Lively Member
Re: VB6 Calculation
Thanks Bonnie West..the code works perfectly..awesome
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
|