View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# [VB] Uncertain why this isn't working

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

### #1Xooch  Members

Posted 10 July 2013 - 05:03 PM

Hey,

I've just written this code, unfortunately the 'price' & 'price2' variables always returns as 0 when I print it, and I'm really confused why as it should, also instead of it adding the value to price during the if statements, it just goes straight to the last Else which prints out that I should enter a correct numeric value


Dim theHeight As String = heightEntry.Text
Dim theWidth As String = widthEntry.Text
Dim price As Integer
Dim price2 As Integer

If IsNumeric(theWidth) >= 1800 Then
price = 1444

ElseIf IsNumeric(theWidth) >= 1801 And IsNumeric(theWidth) <= 2000 Then
price = 1458

ElseIf IsNumeric(theWidth) >= 2001 And IsNumeric(theWidth) <= 2200 Then
price = 1479

ElseIf IsNumeric(theWidth) >= 2201 And IsNumeric(theWidth) <= 2400 Then
price = 1580

ElseIf IsNumeric(theWidth) >= 2401 And IsNumeric(theWidth) <= 2600 Then
price = 1606

ElseIf IsNumeric(theWidth) >= 2601 And IsNumeric(theWidth) <= 2800 Then
price = 1630

ElseIf IsNumeric(theWidth) >= 2801 And IsNumeric(theWidth) <= 3000 Then
price = 2185

ElseIf IsNumeric(theWidth) >= 3001 And IsNumeric(theWidth) <= 3200 Then
price = 2204

ElseIf IsNumeric(theWidth) >= 3201 And IsNumeric(theWidth) <= 3400 Then
price = 2259
Else
Output("Please Enter Numbers Between 1800 to 3400")
End If

If IsNumeric(theHeight) > 2100 Then
price2 = price * 1.05
Else
price2 = price
End If

Output("Value is: " + price2.ToString)

End Sub



Any help would be greatly appreciated, thanks!

### #2SiCrane  Moderators

Posted 10 July 2013 - 05:17 PM

IsNumeric() doesn't convert its argument to a number, it only tells you if the argument is a valid number or not. Depending on exactly which version of VB you're using and what you want to convert the argument to then you might want to try CInt(), CLng(), CDbl() or similar functions instead.

Posted 10 July 2013 - 05:22 PM

Can't you just use theWidth as a number anyway in VB? (as long as IsNumeric is true)

So

If IsNumeric(theWidth) Then

' do all that stuff you already doing, but you don't need IsNumeric any more

Else

Output("Please Enter Numbers Between 1800 to 3400")

Endif

Otherwise I think you can do

Dim price as Integer = theWidth

as well?

(Disclaimer: I hate VB and the syntax sucks so I could be wrong)

EDIT: And I haven't tried any .NET VB stuff, last time I did VB was VB6, so it may have changed completely now!

Edited by Paradigm Shifter, 10 July 2013 - 05:24 PM.

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

### #4Xooch  Members

Posted 10 July 2013 - 05:35 PM

Thanks SiCrane, worked like a charm!

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.