6 Replies - 447 Views - Last Post: 21 September 2011 - 07:40 AM Rate Topic: -----

#1 el - general  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • 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  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5572
  • View blog
  • Posts: 11,911
  • 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

Was This Post Helpful? 2
  • +
  • -

#3 el - general  Icon User is offline

  • D.I.C Head

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

Re: problem in converting !

Posted 20 September 2011 - 06:16 PM

you are right

thanks for your advice
Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5572
  • View blog
  • Posts: 11,911
  • 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.
Was This Post Helpful? 1
  • +
  • -

#5 el - general  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

#6 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5572
  • View blog
  • Posts: 11,911
  • 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.
Was This Post Helpful? 0
  • +
  • -

#7 AdamSpeight2008  Icon User is online

  • MrCupOfT
  • member icon


Reputation: 2267
  • View blog
  • Posts: 9,480
  • 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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1