A Conversation for The H2G2 Programmers' Corner

VB InputBox

Post 1

Lakeman

I hope this isn't too simple for you all. In Visual Basic how can you tell when an InputBox has been returned without anything being entred into it. I've had a go with IsNull and IsEmpty, but with no success.

Thanks.


VB InputBox

Post 2

Peet (the Pedantic Punctuation Policeman, Muse of Lateral Programming Ideas, Eggcups-Spurtle-and-Spoonswinner, BBC Cheese Namer & Zaphodista)

Just guessing (I haven't used VB for about 8 years) but how about:

if myinput.value = "" then ...? smiley - geek


VB InputBox

Post 3

DoctorMO (Keeper of the Computer, Guru, Community Artist)

My understading of an Input Box, is a little one lines text box control.

Do you mean the File Input Save/Open Box that comes as a control?

There is two ways, set the cancel Error to true and use some error handling. or check for File = "", simple.

If you need some better code, I got a module so you don't have to include that silly control with your project.

-- DoctorMO --


VB InputBox

Post 4

Lakeman

Yes, I tried = "" and it didn't work.

This is what I have:

Dim Year
Year = InputBox ("Enter the Year")
x
If Year < 1700 Then GoTo Line3
If Year > 2299 Then GoTo Line2 Else GoTo Line1

I want something at x that says if Year = no value entred then go somewhere else.

What do you think?


VB InputBox

Post 5

DoctorMO (Keeper of the Computer, Guru, Community Artist)

You may want to convert Year to an Integer

Year = Int(InputBox("Enter the Year"))

If Year = 0 Then Goto NOTHING
If Year < 1700 Then GoTo Line3
If Year > 2299 Then GoTo Line2 Else GoTo Line1

Try that.

-- DoctorMO --


VB InputBox

Post 6

Peet (the Pedantic Punctuation Policeman, Muse of Lateral Programming Ideas, Eggcups-Spurtle-and-Spoonswinner, BBC Cheese Namer & Zaphodista)

Again, working from memory, you could modify it to:

Dim Year as string*4
Year = InputBox ("Enter the Year")
x
If eval(Year) < 1700 Then GoTo Line3
If eval(Year) > 2299 Then GoTo Line2 Else GoTo Line1

and after that testing against "" should work. smiley - geek,erm>


VB InputBox

Post 7

DoctorMO (Keeper of the Computer, Guru, Community Artist)

Tecnicaly that would work, but it's a messy way to deal with a number from a string input.

-- DoctorMO --


VB InputBox

Post 8

Peet (the Pedantic Punctuation Policeman, Muse of Lateral Programming Ideas, Eggcups-Spurtle-and-Spoonswinner, BBC Cheese Namer & Zaphodista)

Well, I'm not entirely certain that INT of a null value will evaluate to 0.... smiley - nahnah


VB InputBox

Post 9

Lakeman

I tried making the year an integer and it nearly worked. But, when nothing is typed, is is not seen as zero. Typing in 0 gives the desired result but not just leaving it blank.

At the moment when nothing is typed I think it is seen as > 2299. Infinity perhaps?

I think making the year a string may cause problems when a year is entered with 5 digits.


VB InputBox

Post 10

Peet (the Pedantic Punctuation Policeman, Muse of Lateral Programming Ideas, Eggcups-Spurtle-and-Spoonswinner, BBC Cheese Namer & Zaphodista)

Don't worry, they're bound to make the calendar hexadecimal sometime in the next 8000 years or so... smiley - biggrin


VB InputBox

Post 11

Lakeman

Thanks for the help. I think I'll just wait for hexidecimalisation. It wasn't anything important. I was messing with an Excel Macro that I got off h2g2. It's to calculate the date of Easter. You can find it if you search for Easter up there. It's worth a look. I can't take credit for any of the clever stuff though.

Bye for now.


VB InputBox

Post 12

Jonny

you could try seeing what the string is first.

So for example:

Dim theyear As String
theyear = InputBox("Enter the year")
If theyear = "" Then GoTo noyear
Dim a As Integer
a = theyear
MsgBox "a is " & a
Exit Sub
noyear:
MsgBox "No Year"

I've just tried it and that works.

Jonny


Key: Complain about this post

Write an Entry

"The Hitchhiker's Guide to the Galaxy is a wholly remarkable book. It has been compiled and recompiled many times and under many different editorships. It contains contributions from countless numbers of travellers and researchers."

Write an entry
Read more