A Conversation for The H2G2 Programmers' Corner
VB InputBox
Lakeman Started conversation Mar 31, 2003
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
Peet (the Pedantic Punctuation Policeman, Muse of Lateral Programming Ideas, Eggcups-Spurtle-and-Spoonswinner, BBC Cheese Namer & Zaphodista) Posted Mar 31, 2003
VB InputBox
DoctorMO (Keeper of the Computer, Guru, Community Artist) Posted Mar 31, 2003
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
Lakeman Posted Mar 31, 2003
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
DoctorMO (Keeper of the Computer, Guru, Community Artist) Posted Mar 31, 2003
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
Peet (the Pedantic Punctuation Policeman, Muse of Lateral Programming Ideas, Eggcups-Spurtle-and-Spoonswinner, BBC Cheese Namer & Zaphodista) Posted Mar 31, 2003
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. ,erm>
VB InputBox
DoctorMO (Keeper of the Computer, Guru, Community Artist) Posted Mar 31, 2003
Tecnicaly that would work, but it's a messy way to deal with a number from a string input.
-- DoctorMO --
VB InputBox
Peet (the Pedantic Punctuation Policeman, Muse of Lateral Programming Ideas, Eggcups-Spurtle-and-Spoonswinner, BBC Cheese Namer & Zaphodista) Posted Mar 31, 2003
VB InputBox
Lakeman Posted Mar 31, 2003
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
Peet (the Pedantic Punctuation Policeman, Muse of Lateral Programming Ideas, Eggcups-Spurtle-and-Spoonswinner, BBC Cheese Namer & Zaphodista) Posted Mar 31, 2003
Don't worry, they're bound to make the calendar hexadecimal sometime in the next 8000 years or so...
VB InputBox
Lakeman Posted Mar 31, 2003
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
Jonny Posted Mar 31, 2003
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
VB InputBox
- 1: Lakeman (Mar 31, 2003)
- 2: Peet (the Pedantic Punctuation Policeman, Muse of Lateral Programming Ideas, Eggcups-Spurtle-and-Spoonswinner, BBC Cheese Namer & Zaphodista) (Mar 31, 2003)
- 3: DoctorMO (Keeper of the Computer, Guru, Community Artist) (Mar 31, 2003)
- 4: Lakeman (Mar 31, 2003)
- 5: DoctorMO (Keeper of the Computer, Guru, Community Artist) (Mar 31, 2003)
- 6: Peet (the Pedantic Punctuation Policeman, Muse of Lateral Programming Ideas, Eggcups-Spurtle-and-Spoonswinner, BBC Cheese Namer & Zaphodista) (Mar 31, 2003)
- 7: DoctorMO (Keeper of the Computer, Guru, Community Artist) (Mar 31, 2003)
- 8: Peet (the Pedantic Punctuation Policeman, Muse of Lateral Programming Ideas, Eggcups-Spurtle-and-Spoonswinner, BBC Cheese Namer & Zaphodista) (Mar 31, 2003)
- 9: Lakeman (Mar 31, 2003)
- 10: Peet (the Pedantic Punctuation Policeman, Muse of Lateral Programming Ideas, Eggcups-Spurtle-and-Spoonswinner, BBC Cheese Namer & Zaphodista) (Mar 31, 2003)
- 11: Lakeman (Mar 31, 2003)
- 12: Jonny (Mar 31, 2003)
More Conversations for The H2G2 Programmers' Corner
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."