Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 13th, 2005, 9:17 PM   #1
Clotters
Programmer
 
Join Date: May 2005
Posts: 60
Rep Power: 4 Clotters is on a distinguished road
Smile Got another problem for you :)

I'm beginning to advance with VB6 and when I have more time, instead of asking for help from you guys, I plan to try to figure out these problems myslef, but for now I have no time to waste.

Basically, I've made a few applications, but I just want to spruce them up a bit and be more professional.

If for an integer value someone decides it would be funny to enter a string, how can I create a msgbox or inputbox that will pop-up if someone enters the wrong data type?

For now, I can control it if someone enters a bad value such as a number less than 1,000 or more than 10,000 (supposing the input needed in the text box is an integer), but if someone enters a string, the application breaks down.

I tried using the NOT statement but it still didn't work for me when a string was entered when an integer was need.

How can I fix this?

Thanks in advance.
Clotters is offline   Reply With Quote
Old Jun 13th, 2005, 9:22 PM   #2
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Read it in as a String variable, and use the Int(Val(myString)) to convert it to an integer.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Jun 13th, 2005, 10:12 PM   #3
Clotters
Programmer
 
Join Date: May 2005
Posts: 60
Rep Power: 4 Clotters is on a distinguished road
I'm not far enough into the book I'm using to have understood what the Int() does exactly. This is what I'd guess you mean doing.

DIM strnumber AS STRING

Int(Val(strnumber))

I don't see how this would affect anything though and I'm not sure what you mean to be put in for the "Val".

Is there any other method I could go about doing it or could you explain further?
Clotters is offline   Reply With Quote
Old Jun 14th, 2005, 12:30 AM   #4
Clotters
Programmer
 
Join Date: May 2005
Posts: 60
Rep Power: 4 Clotters is on a distinguished road
Actually, I think I may have just cracked it. This should work right?

Private Sub Command1_Click()

On Error GoTo errh:

Dim X As Integer

sof:
X = InputBox(relevant stuff)

Exit Sub

errh:
MsgBox(relevant stuff)
GoTo sof:

End Sub
Clotters is offline   Reply With Quote
Old Jun 14th, 2005, 1:04 AM   #5
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 6 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
GOTO's are the devil. do this...

On Error Resume Next
Dim x as integer
Dim xstr as string
Dim error as boolean
error = true

While error
    xstr = InputBox("Please enter a positive integer: ", "")
    If int(val(xstr)) <= 0 then
        MsgBox("You are a moron, how hard is this...? Let's try again!")
    else
        error = false
        x = int(val(xstr))
    end if
Wend
__________________

tempest is offline   Reply With Quote
Old Jun 14th, 2005, 1:16 AM   #6
uman
Expert Programmer
 
Join Date: Dec 2004
Posts: 794
Rep Power: 4 uman is on a distinguished road
I thought Bill Gates was the devil.
uman is offline   Reply With Quote
Old Jun 14th, 2005, 3:36 AM   #7
Berto
Programming Guru
 
Join Date: Aug 2004
Posts: 1,022
Rep Power: 6 Berto is on a distinguished road
Send a message via AIM to Berto Send a message via MSN to Berto
no Just goto's Bill Gates gives lots of money to charity...
__________________
"Put your hand on a hot stove for a minute, and it seems like an hour. Sit with a pretty girl for an hour, and it seems like a minute. THAT'S relativity."

- Albert Einstein
Berto is offline   Reply With Quote
Old Jun 14th, 2005, 9:43 AM   #8
Clotters
Programmer
 
Join Date: May 2005
Posts: 60
Rep Power: 4 Clotters is on a distinguished road
Okay thanks for that help, I'll probably try that method for great ease in code reading. Loops are the one real things that I'm struggling to grasp though, but this one isn't too taxing.

The project I'm working on is ambitious, but is now starting to take shape. I'm slightly limitted at the moment as I haven't learned about creating databases yet, and my simulation will be one HUGE databse.

Still, I'm getting there and you guys have helped a lot. Thanks.
Clotters is offline   Reply With Quote
Old Jun 14th, 2005, 3:53 PM   #9
Rory
Expert Programmer
 
Rory's Avatar
 
Join Date: Jan 2005
Location: London
Posts: 542
Rep Power: 4 Rory is on a distinguished road
Send a message via MSN to Rory
Huh? On error goto bleh meh fortran urghh!
What's wrong with IsNumeric() ?
Rory is offline   Reply With Quote
Old Jun 14th, 2005, 4:06 PM   #10
big_k105
PFO Founder

 
big_k105's Avatar
 
Join Date: Mar 2004
Location: Fargo, ND
Posts: 1,667
Rep Power: 10 big_k105 is on a distinguished road
Send a message via AIM to big_k105 Send a message via MSN to big_k105 Send a message via Yahoo to big_k105
I personally use IsNumeric() like rory mentioned it works great for me
__________________
BIG K aka Kyle
Programming Forums
Kyle K Online

Please do not PM or email me programming questions. Post them in the forums instead.
big_k105 is online now   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:44 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC