Solved

VB Implicit Conversion

Posted on 2010-09-16
3
370 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 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

719 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