![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Programmer
Join Date: May 2005
Posts: 60
Rep Power: 4
![]() |
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. |
|
|
|
|
|
#2 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Read it in as a String variable, and use the Int(Val(myString)) to convert it to an integer.
|
|
|
|
|
|
#3 |
|
Programmer
Join Date: May 2005
Posts: 60
Rep Power: 4
![]() |
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? |
|
|
|
|
|
#4 |
|
Programmer
Join Date: May 2005
Posts: 60
Rep Power: 4
![]() |
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 |
|
|
|
|
|
#5 |
|
Programming Guru
![]() |
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
__________________
|
|
|
|
|
|
#6 |
|
Expert Programmer
Join Date: Dec 2004
Posts: 794
Rep Power: 4
![]() |
I thought Bill Gates was the devil.
|
|
|
|
|
|
#7 |
|
Programming Guru
![]() |
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 |
|
|
|
|
|
#8 |
|
Programmer
Join Date: May 2005
Posts: 60
Rep Power: 4
![]() |
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. |
|
|
|
|
|
#9 |
|
Expert Programmer
|
Huh? On error goto bleh meh fortran urghh!
What's wrong with IsNumeric() ? |
|
|
|
|
|
#10 |
|
PFO Founder
![]() ![]() |
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. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|