a programming error

Talk about anything you want.

Moderator: paula

Post Reply
kevin_100
Bear Protector
Posts: 53
Joined: February 11, 2004, 6:18 pm

a programming error

Post by kevin_100 »

Return Me.NumberOfPizzas + " Pizzas @ 8.99 " _
+ Me.NumberOfPizzas * 8.99 _
+ Me.NumberOfCokes + " Cokes @ $.99: " _
+ Me.NumberOfCokes * 8.99 _
+ " Order Amount: " + Me.getOrderAmount _
+ " Sales Tax: " _
+ Me.PRICONSTSALESTAX * Me.getOrderAmount _
+ " Amount Due: " + Me.getTotalAmount _
+ " Amount Paid: " _
+ Me.CustomerMoney(pridblCustomerMoney) _
+ " Change Due: " _
+ Me.changeDue(pridblCustomerMoney)


There is the code. The code is VB .NET. I am getting the following error:
Option Strict On disallows implicit conversion

The line that is giving the error is " Pizzas @ 8.99 ". Does anyone know
why I am getting this error? The method that this code is in is
Public Overrides Function toString() As String

Thanks!
User avatar
Paco103
Single White Admin
Posts: 629
Joined: January 15, 2004, 9:22 pm
Location: Right Here
Contact:

Post by Paco103 »

I'm not a VB expert - but what I see is Me.NumberOfPizzas is an integer, and you're trying to concatenate it into a string. Usually these will convert to a string type automatically, but it is the first variable in the function, so the compiler is probably thinking that it's an add function, not a concatenation.

Things to check:
Is + the proper concatenator in VB.Net? I know in ASP when using VB it's the & operator.
The option explicit message sounds like perhaps you have to manually define the conversion from an integer to a string?
Other thing to try would be to start the return function with an empty string, so that the first operand is the type you're trying to return. Just thoughts - as I said I'm not a VB expert.
kevin_100
Bear Protector
Posts: 53
Joined: February 11, 2004, 6:18 pm

Post by kevin_100 »

Thanks for the suggestions! I think you are right. I'll try the
things you mentioned right now.

Thanks!

Kevin
kevin_100
Bear Protector
Posts: 53
Joined: February 11, 2004, 6:18 pm

Post by kevin_100 »

What you said fixed my problem. Thanks.


In VB .NET, you can use the (+) to concatenate, but like you said,
the first thing that I typed after the return statement was a
function that returned an integer variable, so by using the
(+) VB .NET thought I was wanting to add and when it got
to the string, VB .NET didn't know how to add an integer
number to "Pizzas @ 8.99".

But, also in VB .NET, you can use the (&) to concatenate which
really is supposed to be use for concatenation all the time,
but if you are returning a bunch of methods that return strings,
I found that the (+) will concatenate, but in this instance it did
not work.

Thanks again,

Kevin
Post Reply