# problem in converting !

Page 1 of 1

## 6 Replies - 893 Views - Last Post: 21 September 2011 - 07:40 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=247946&amp;s=346228bfd1a315e86896054ee1e84701&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 el - general

Reputation: 0
• Posts: 51
• Joined: 10-July 11

# problem in converting !

Posted 20 September 2011 - 04:38 PM

Hi every one

Now I have this code

```
Function AddErad(ByVal namee As String, ByVal Pricecourse As Integer, ByVal PriceCd As Integer, ByVal PriceCerti As Integer, ByVal Pricecard As Integer, ByVal Priceother As Integer, ByVal Priceother2 As Integer, ByVal dateofregist As String, ByVal notese As String, ByVal free As String) As Boolean

Dim SqlString As String
SqlString = "Insert into Erad (namee,Pricecourse,PriceCd,PriceCerti,Pricecard,Priceother,Priceother2,dateofregist,notese,free)Values " & _
" ('" & namee & "'," & Pricecourse & "," & PriceCd & "," & PriceCerti & "," & Pricecard & "," & Priceother & "," & Priceother2 & " ,  '" & dateofregist & "', ' " & notese & "',  ' " & free & "' )"

```

some of variables are integer

now how i can convert it in this code

```  AddErad(TextBox35.Text, TextBox20.Text, TextBox37.Text, TextBox39.Text, TextBox41.Text, TextBox38.Text, TextBox40.Text, TextBox36.Text, TextBox42.Text, TextBox43.Text)

```

when I try to convert the texts boxes to

ex:
```Cint(textbox20.text)
```

i have problem shown to me

say that : ( Conversion from string "" to type 'Integer' is not valid. )

what can i do ?

This post has been edited by el - general: 20 September 2011 - 04:42 PM

Is This A Good Question/Topic? 0

## Replies To: problem in converting !

### #2 tlhIn`toq

• Xamarin Cert. Dev.

Reputation: 6532
• Posts: 14,447
• Joined: 02-June 10

## Re: problem in converting !

Posted 20 September 2011 - 06:13 PM

For now, just work on the lessons. Do a self-teaching book from cover to cover. Then consider writing a program.

Don't try to create a useful working program to fit a need of yours (or a for-pay contract) as your introduction to coding project. When you are learning to code you don't know enough to code a program, let alone know how to engineer the architecture of a program. It would be like saying "I don't know how to read sheet music, or play an instrument. I think I'll write a 3act opera as my first learning experience."

I don't say this to be mean. We've seen lots of new coders take this approach and we know it doesn't work. Trying to design your own programs before you understand the basics of the code language you've chosen just leads to problems, frustrations, and 'swiss-cheese' education (lots of holes).

Resources, references and suggestions for new programmers. - Updated Sep 2011
Spoiler

### #3 el - general

Reputation: 0
• Posts: 51
• Joined: 10-July 11

## Re: problem in converting !

Posted 20 September 2011 - 06:16 PM

you are right

### #4 tlhIn`toq

• Xamarin Cert. Dev.

Reputation: 6532
• Posts: 14,447
• Joined: 02-June 10

## Re: problem in converting !

Posted 20 September 2011 - 06:17 PM

1st - No method should ever take that many parameters. Its just ugly. Maybe consider making a class that contains these things and send an instance of the class. This gives you the opportunity later to adjust the contents of the class without having to re-write all your methods.

2nd - Please tell me you didn't really make a form with over 40 textboxes that you never renamed to something meaningful.

3rd - You can't send text in place of integers. When you get the text from a textbox it is a string. You are retrieving "5" not 5. So at minumum a conversion needs to take place to make sure someone doesn't type in "yogi bear" instead of 123. But it would be better to use a control like a NumericUpDown that doesn't allow for non-numeric input.

### #5 el - general

Reputation: 0
• Posts: 51
• Joined: 10-July 11

## Re: problem in converting !

Posted 20 September 2011 - 06:24 PM

how can i do this :

to make sure someone doesn't type in "yogi bear" instead of 123. But it would be better to use a control like a NumericUpDown that doesn't allow for non-numeric input.

### #6 tlhIn`toq

• Xamarin Cert. Dev.

Reputation: 6532
• Posts: 14,447
• Joined: 02-June 10

## Re: problem in converting !

Posted 21 September 2011 - 07:03 AM

There are a couple ways:

You can make a custom textbox that reacts to the KeyPress event and looks at the key being pressed. If its not a number, throw it away.

You can let them type whatever they want. Then when you need to use the value, you can try to convert it to a number. If the parse false, throw up a warning and make them re-enter it.

Or like I suggested, just replace those TextBoxes with NumericUpDown controls and use the .Value property.

• MrCupOfT

Reputation: 2298
• Posts: 9,535
• Joined: 29-May 08

## Re: problem in converting !

Posted 21 September 2011 - 07:40 AM

If you are using VS2010, simply import the following NuGet Package - NumbersOnly

Exension Manager -> NuGet Package Manager
Solution Explorer -> Manage NuGet Packages
In the search online box enter NumbersOnly
Click Install
Now you have a NumbersOnly "TextBox" in your toolbox.