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
Solved

VB Implicit Conversion

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…
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…

839 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