Solved

VB Implicit Conversion

Posted on 2010-09-16
3
368 Views
Last Modified: 2013-12-25
I'm currently in school and we are concentrating in VB for the most part, so I wanted to mess around and create a calculator. Everything was going smooth until I ran into this problem.

"Option Strict On disallows implicit conversions from 'string' to 'double'. (Line 18)

From what I see in my code, why in the world would it even be trying to convert to double? I'm saying the text from the textbox, which is a string equals value from the textbox plus the value one, but I'm using the ToString() method. So why is it trying to make an implicit conversion to double? I even tried to use the CDbl method to convert intOne to double just to see what it would do, but this is not the answer. It is clear that intOne is declared as an Integer data type. I know this is really easy, but I just can't figure it out.
Private Sub btnOne_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOne.Click
        Dim intOne As Integer = 1
        If txtDisplay.Text = "0" Then
            txtDisplay.Text = String.Empty
            txtDisplay.Text += intOne.ToString()
        Else
            txtDisplay.Text += intOne.ToString()
        End If

        If obj.AddBtn = True Then
            txtDisplay.Text = String.Empty
            txtDisplay.Text += intOne.ToString()
            obj.AddBtn = False
        End If

        If obj.SubBtn = True Then
            txtDisplay.Text = String.Empty
            txtDisplay.Text -= intOne.ToString()
            obj.SubBtn = False
        End If
    End Sub

Open in new window

0
Comment
Question by:Keith1985
  • 2
3 Comments
 
LVL 58

Accepted Solution

by:
cyberkiwi earned 50 total points
ID: 33697706
It is because while you can concatenate strings using +, you cannot take away using -

            txtDisplay.Text -= intOne.ToString()

You are trying to use -=?
Or is that a mistype?
0
 

Author Comment

by:Keith1985
ID: 33697845
Okay I see, so what I need to do is something like:

intResult -= intOne
txtDisplay.Text = intResult.ToString()

Is this correct?
0
 

Author Closing Comment

by:Keith1985
ID: 33701859
Problem solved.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question