-
Mar 4th, 2010, 08:15 AM
#1
Thread Starter
New Member
[RESOLVED] VB6 Compile error: expected expression
This is my code in VB 6:
Private Sub show_notes(change As Currency)
Dim notes100, notes50, notes20, notes10, notes5, remainder As Integer
notes = notes_change
notes100 = notes / 100
remainder = notes Mod 100
notes50 = remainder / 50
remainder = remainder Mod 50
notes20 = remainder / 20
remainder = remainder Mod 20
notes10 = remainder / 10
remainder = remainder Mod 10
notes5 = remainder / 5
output(' $100 * ', notes100)
output(' $50 * ', notes50)
output(' $20 * ', notes20)
output(' $10 * ', notes10)
output(' $5 * ', notes5)
End Sub
The error is from the output lines. I'm pretty sure it is:
print(' $100 * ', notes100)
but the error still exists.
Cheers, Shaun
-
Mar 4th, 2010, 08:22 AM
#2
Re: VB6 Compile error: expected expression
Welcome to the forums....
Do you have a sub/function with the name output ...???
Dim notes100, notes50, notes20, notes10, notes5, remainder As Integer
You have to use the datatype for each variable. In the above line:
Only remainder is Integer type. The rest of them are of Variant type ..
If my post was helpful to you, then express your gratitude using Rate this Post.
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Mar 4th, 2010, 08:35 AM
#3
Thread Starter
New Member
Re: VB6 Compile error: expected expression
Originally Posted by akhileshbc
Welcome to the forums....
Do you have a sub/function with the name output ...???
You have to use the datatype for each variable. In the above line:
Only remainder is Integer type. The rest of them are of Variant type ..
Thanks for your assistance akhileshbc but i've still got the same output errors.
Screenshot - http://flare.me/images/93964979256154062034.png
-
Mar 4th, 2010, 08:37 AM
#4
Re: VB6 Compile error: expected expression
What are you trying to do with those lines..???
If my post was helpful to you, then express your gratitude using Rate this Post.
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Mar 4th, 2010, 08:39 AM
#5
Thread Starter
New Member
Re: VB6 Compile error: expected expression
$100 * How Many $100 notes to Get, notes100
I'm not sure what the correct layout is though.
-
Mar 4th, 2010, 08:46 AM
#6
Re: VB6 Compile error: expected expression
Try this:
Code:
Print "$100 * " & notes100
Print "$50 * " & notes50
Print "$20 * " & notes20
Print "$10 * " & notes10
Print "$5 * " & notes5
If my post was helpful to you, then express your gratitude using Rate this Post.
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Mar 4th, 2010, 08:51 AM
#7
Thread Starter
New Member
Re: VB6 Compile error: expected expression
Thankyou akhileshbc! This has fixed the problem.
-
Mar 4th, 2010, 08:53 AM
#8
Re: VB6 Compile error: expected expression
Originally Posted by snoopinc
Thankyou akhileshbc! This has fixed the problem.
You are welcome...
If my post was helpful to you, then express your gratitude using Rate this Post.
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Mar 4th, 2010, 09:17 AM
#9
Re: [RESOLVED] VB6 Compile error: expected expression
On a side note.
If I understand your program correctly you wanted all the "change" listed at the end to sum up to the amount expected.
Thus if the change is to be 135 you want the resulting print out to add up to 135.
If I missunderstood it, please ignore my post.
The problem is that currently you get rounding issues.
If you have change of 135 for example you get (I replaced variable names with the value for clarification):
notes100 = 1 as 135 / 100 = 1.35 '-- This is OK
remainder = 35 as 135 MOD 100 = 35 '-- This is still OK
notes50 = 1 as 35 / 50 = 0.7 '-- This is not OK as it should be 0 ?
The result you would get for 135 change is:
$100 * 1
$50 * 1
$20 * 2
$10 * 2
$5 * 1
Those add up to 215 which I understood not to be the expected result ?
If you do get issues whereby the amounts do not add up to the expected change due to rounding issues, feel free to use the below:
Code:
notes100 = Round((notes / 100) - 0.5)
remainder = notes Mod 100
notes50 = Round((remainder / 50) - 0.5)
remainder = remainder Mod 50
notes20 = Round((remainder / 20) - 0.5)
remainder = remainder Mod 20
notes10 = Round((remainder / 10) - 0.5)
remainder = remainder Mod 10
notes5 = Round((remainder / 5) - 0.5)
Last edited by Optional; Mar 5th, 2010 at 08:43 AM.
Kind Regards,
Optional
If you feel this post has helped in answering your question please return the favour and Rate this post.
If your problem has been solved and your question has been answered mark the thread as [RESOLVED] by selecting the Thread Tools menu option at the top and clicking the Mark Thread Resolved menu item.
VB6 - (DataGrid) Get the Row selected with the right mouse button
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
|