Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Oct 2004
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Visual Basic , Help needed

    I am creatng this program that allows me to enter a students number o.k i have created the variable as an integer and now i cannot add text to it, because its an integer. but how do i get round this?

    here is the code

    ' Get Student Number & Name

    intStudentNumber = InputBox(" ")

    strStudentName = InputBox("Please Student Name Here")

    Cheers Chris

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    1,137
    Thanks
    0
    Thanked 0 Times in 0 Posts
    if this is visual basic, to delcare a varaible you use

    Dim varname as string

    will declare a string.

    scroots
    Spammers next time you spam me consider the implications:
    (1) that you will be persuaded by me(in a legitimate mannor)
    (2)It is worthless to you, when i have finished

  • #3
    Regular Coder
    Join Date
    Oct 2004
    Location
    In front of this computer. (Where else?)
    Posts
    442
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,
    First declare the variable as an integer.
    dim variablename as integer
    Then you need to convert the student number to an integer. This is because VB sees whatever is entered into the input box as a string. Use this code

    intStudentNumber = cint(InputBox(" "))

    Note - cint(value) converts value to an integer. But you have to be absolutely sure the students enter their number and nothing else or you'll get an error.
    Cheers
    Tomorrow is the first day of the rest of your life... What have you done today?
    Tutorials
    Web: w3schools, htmldog General tips: Hardware, Networking

  • #4
    New Coder
    Join Date
    Oct 2004
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    cheers people, yeah numbers are the only thing that is going to be entered in that input box.


    Chris

  • #5
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    I'd still do some checking with either a try...catch or some regex just because they are supposed to enter only numbers, doesn't mean that its always gonna happen.
    OracleGuy


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •