2 Replies - 1090 Views - Last Post: 26 September 2014 - 07:27 AM Rate Topic: -----

#1 mstruzinski   User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 37
  • Joined: 05-September 14

Brainfart; Integer.TryParse

Posted 26 September 2014 - 07:22 AM

I totally forgot how to use the TryParse method for data validation; shows how much VB syntax I retained over the summer >.< this semester has not been fun

Anyway, here my program will open an input box and have the user enter how many spools are currently in stock in order to calculate an order. I need to have it so the program knows not to attempt to calculate anything that isn't an integer. I also need it to return an error if the integer is less than 1. I'm sure I could figure that out, but I really don't remember how to make it so it will figure out if the user entered an integer in the first place (instead of a letter, spaces, word, etc.).

 Function GetInStock() As Integer
        intSpoolsInStock = CInt(InputBox("Enter the number of spools in stock.", "Spools In Stock"))
        Return intSpoolsInStock
    End Function



Thank you in advance. Youtube tutorials and other documents have not been a great help.

Wait, I got it. Please kill this thread. I used a Try Catch in the btnCalculate which keeps the program from crashing from bad input. Then an If Then statement to tell it if intSpoolsInStock < 1 then Error.

Is This A Good Question/Topic? 1
  • +

Replies To: Brainfart; Integer.TryParse

#2 andrewsw   User is offline

  • never lube your breaks
  • member icon

Reputation: 6819
  • View blog
  • Posts: 28,255
  • Joined: 12-December 12

Re: Brainfart; Integer.TryParse

Posted 26 September 2014 - 07:26 AM

The best place for a reminder is the docs and their examples:

Int32.TryParse Method

the InputBox returns a string so you should store that value first, then see if it is also an integer.

View Postmstruzinski, on 26 September 2014 - 02:22 PM, said:

Wait, I got it. Please kill this thread.

Topics aren't closed, but glad you sorted.
Was This Post Helpful? 0
  • +
  • -

#3 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15329
  • View blog
  • Posts: 61,442
  • Joined: 12-June 08

Re: Brainfart; Integer.TryParse

Posted 26 September 2014 - 07:27 AM

... or, you know, use Integer's TryParse.

Remember - those MSDN docs explain what functions do, inputs, outputs, errors, and examples.

(Ah! Scooped by andrewsw)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1