Alright so i've done this in some of my recent programs with option strict on and for some reason When i debug and select the option from the combo box, it crashes and gives me a 'Input String was not in the correct format' error. Ive tried declaring the variables as strings and converting the textbox to integer from there and still get the same thing. I'm just trying to get a value to store it in that variable so i can use it for later calculations. Theres a lot more to it, but considering i'm getting this so early i don't wanna continue until i get it right. -
Option Strict On
-
Option Explicit On
-
-
Public Class Form1
-
-
Private Sub cboCommute_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboCommute.SelectedIndexChanged
-
-
Dim intCommuteChoice As Integer
-
intCommuteChoice = Me.cboCommute.SelectedIndex
-
Select Case intCommuteChoice
-
Case 0
-
CarCommute()
-
-
End Select
-
-
End Sub
-
-
-
Private Sub CarCommute()
-
Me.GroupBox1.Visible = True
-
-
Dim intlabel1 As Integer
-
Dim intlabel2 As Integer
-
-
intlabel1 = Convert.ToInt32(Me.Label1.Text)
-
intlabel2 = Convert.ToInt32(Me.Label2.Text)
-
-
End Sub
-
-
End Class
-
7 1751
Which line throws the error?
25. I guess ill just declare variables as strings and take the input from the message boxes and convert them to integers when doing the calculations. Just wondering what the syntax is to force a textbox to accept an integer value instead of string.
Hi,
Try This : -
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
-
If InStr("0123456789", e.KeyChar.ToString) <= 0 Then
-
e.Handled = True
-
End If
-
End Sub
-
Regards
Veena
Hi,
If you are getting error on 25 and 26th line, you can just use the "Val" function like this..: -
intlabel1 = Val(Me.Label1.Text)
-
intlabel2 = Val(Me.Label2.Text)
-
Regards
Veena
Assuming it's still available in your version (I use VB6) I'd recommend using the Masked Edit control rather than a textbox. It allows much better control over what is input.
what i've found easier is using CType(Var, Type) to make all the type changes you need while using Option Strict (yeah, the easy way out).
Generally speaking though, I think it's better practice to restrict user input to what is acceptable, rather than waiting until they've entered something then complaining about it.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Nikola |
last post by:
Hi all,
I have a problem converting datetime to integer (and than back to
datetime).
Depending whether the time is AM or PM, same date is converted to two
different integer representations,...
|
by: Cyde Weys |
last post by:
I'm currently working on converting a simulator program from Visual
Basic 6.0 to Visual C++ .NET. I've figured out most of the stuff, but
there's still one thing I haven't gotten to and I've never...
|
by: Asbjørn Ulsberg |
last post by:
Hi.
I'm trying to convert Brady Hegberg's great RTF2HTML VB 6.0
module to C#. I've managed to convert the VB code to VB.NET,
which gave me the following code:
Option Strict On
Option...
|
by: Mark Allen |
last post by:
Hello,
I am creating an RTF document server side for a report.
However I am having problems converting images into the required RTF
format.
I am converting the image into a string (binary)...
|
by: Paraic Gallagher |
last post by:
Hi,
This is my first post to the list, I hope somebody can help me with this
problem. Apologies if it has been posted before but I have been internet
searching to no avail.
What I am trying...
|
by: Terry |
last post by:
I am converting (attempting) some vb6 code that makes vast use of interfaces.
One of the major uses is to be able to split out Read-only access to an
obect. Let me give you a simple (contrived)...
|
by: Alex Buell |
last post by:
Is there an elegant way of converting strings containing digits
between different number bases in C++?
I.e.:
10 (base 2) = 2 (base 10)
FF (base 16) = 256 (base 10)
F (base 16) = 1111 (base 2)...
|
by: Dilip |
last post by:
Recently in our code, I ran into a situation where were stuffing a
float inside a double. The precision was extended automatically
because of that. To make a long story short, this caused...
|
by: ling2000 |
last post by:
Hello all,
I'm trying to upgrade a VB6 project into VB.net, and the problem I had is in converting 'address of' to 'delegate'.
I had the error "Value of type 'DelegateIDccManSink_OnLogIpAddr'...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |