Solved

VB Implicit Conversion

Posted on 2010-09-16
3
363 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
Comment Utility
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
Comment Utility
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
Comment Utility
Problem solved.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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 …
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now