View Full Version : Visual Basic , Help needed
11-02-2004, 09:37 PM
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?:confused:
here is the code
' Get Student Number & Name
intStudentNumber = InputBox(" ")
strStudentName = InputBox("Please Student Name Here")
11-02-2004, 11:33 PM
if this is visual basic, to delcare a varaible you use
Dim varname as string
will declare a string.
11-03-2004, 11:19 AM
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.
11-03-2004, 12:40 PM
cheers people, yeah numbers are the only thing that is going to be entered in that input box.
11-03-2004, 06:59 PM
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.
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.