Welcome to Dream.In.Code
Become a VB Expert!

Join 149,905 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 2,210 people online right now. Registration is fast and FREE... Join Now!




discount program in vb6

 
Reply to this topicStart new topic

discount program in vb6, need help in discounter program

Alexiel
19 Jan, 2008 - 03:26 AM
Post #1

New D.I.C Head
*

Joined: 19 Jan, 2008
Posts: 6

CODE
Private Sub Command1_Click()
Dim one, two, ans, ans2 As Integer

one = txt1.Text
two = txt2.Text

ans = Val(two) / 100

ans2 = Val(one) * Val(ans)

lbl1.Caption = ans2

lbl1.Caption = Format(ans2, "P 0.00")


End Sub

CODE

Private Sub Command2_Click()
Dim three, four, ans3 As Integer

three = lbl1.Caption
four = txt1.Text

ans3 = Val(four) - Val(three)

lbl2.Caption = ans3

lbl2.Caption = Format(ans3, "P 0.00")

End Sub


i have a problem when I try to use the second command button.

instead of subtracting the four and three it just displays four as the result.

what did I do wrong?

i'll send the program to anyone if interested.
User is offlineProfile CardPM
+Quote Post

Nayana
RE: Discount Program In Vb6
19 Jan, 2008 - 04:39 AM
Post #2

DIC Hawk - 나야나 नयन:
Group Icon

Joined: 14 Nov, 2007
Posts: 824



Thanked: 5 times
Dream Kudos: 175
My Contributions
Your problem is simple. after Command1 has been clicked, the value of lbl1.Caption is "P xxxx"

The P at the front prevents VB from reading the number. To solve this change the line of code where you read the number to skip the P, like so
CODE

three = mid(lbl1.Caption,2)


And then your problem will be fixed.

The mid function lets you choose a sub string, with the index starting at 1.

used like: mid(string, start index, count)
mid("abcdefg", 1) = "abcdefg"
mid("abcdefg", 2) = "bcdefg"
mid("abcdefg",3,1) = "c"
mid("abcdefg",3,2) = "cd"
User is offlineProfile CardPM
+Quote Post

Alexiel
RE: Discount Program In Vb6
19 Jan, 2008 - 05:04 AM
Post #3

New D.I.C Head
*

Joined: 19 Jan, 2008
Posts: 6

thank you Nayana for the answer

i was trying to format the result to appear like this P 0.00

thanks again
User is offlineProfile CardPM
+Quote Post

Nayana
RE: Discount Program In Vb6
19 Jan, 2008 - 05:24 AM
Post #4

DIC Hawk - 나야나 नयन:
Group Icon

Joined: 14 Nov, 2007
Posts: 824



Thanked: 5 times
Dream Kudos: 175
My Contributions
No worries
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 01:22PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month