?
Solved

VB Implicit Conversion

Posted on 2010-09-16
3
Medium Priority
?
371 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 58

Accepted Solution

by:
cyberkiwi earned 200 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

765 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