having trouble doing error trapping in VB

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 11 November 2003   #1
having trouble doing error trapping in VB

Aighty day, so I have a VB6 form with a bunch of entry fields and an output picture box for the entry fields to be printed to. How do I set it such that if they have incomplete entry fields (text boxes), that they get an error message and the program does not continue to the next sub program to print the text fields? I got the error message to work just fine using:

If txtFirstName.Text=" " Then
msgBox "Sorry, you must enter your first name." , , "Input Error!"
Else
Call ProcessData

However, even if there is an error, after it comes up, the program continues running to do the rest of the program to print into the picture box. Any ideas? I was trying to do a do while loop or until loop but I wasn't all too sure how to approach that. Any other ideas?
 
Old 11 November 2003   #2
On error resume next

It tells the sub routine or function that you'll handle the error handleing.

You'll have to use error checking though. For instance for your picture box it would be a good idea to check and make sure there is no error before loading it.
__________________
"Game developers are like simple chemicals. (No, not because they're cheap and smelly.) In the right combination, they can make miracles. Screw up the mix, and you can blow up a city." - How to Screw Up a Perfectly Good Game Company in Ten Easy Steps, www.gamedev.net
 
Old 11 November 2003   #3
On Error Resume Next? Ehr... hahaha. Not exactly sure how to implement that. We haven't gotten there yet. And actually, I should make a correction, this is a field validation thing, not error trapping. I had no idea they meant two totally different things. In anycase, here is what I have so far:

Private Sub cmdProcessData_Click()
If txtInput1.Text="" Then
MsgBox "You have left a field blank", ,"Input Error!"
Exit Sub
EndIf
End Sub

However, the actual code block is pretty long, about 5x longer than this because there are 5 input fields. It works great actually, so the next issue is compressing it down! It's too large. I originally had a separate sub to handle the blank fields but it got strange because I couldn't figure out how to make it perform the Exit Sub without continuing on the rest of the program to print the display and record the data to file. And I might add, there is also a Sub cmdProcessData2_Click() so that above is in there twice; that's why having a separate sub to handle the field validation would be nice. But yeah, OC, did you ever get the email I sent you? If you did, erase it. I totally changed the program around so it's not anywhere near the same anymore. Lots have changed.
 
Old 11 November 2003   #4
Originally posted by singularity2006
On Error Resume Next? Ehr... hahaha. Not exactly sure how to implement that. We haven't gotten there yet. And actually, I should make a correction, this is a field validation thing, not error trapping. I had no idea they meant two totally different things. In anycase, here is what I have so far:

Private Sub cmdProcessData_Click()
If txtInput1.Text="" Then
MsgBox "You have left a field blank", ,"Input Error!"
Exit Sub
EndIf
End Sub

However, the actual code block is pretty long, about 5x longer than this because there are 5 input fields. It works great actually, so the next issue is compressing it down! It's too large. I originally had a separate sub to handle the blank fields but it got strange because I couldn't figure out how to make it perform the Exit Sub without continuing on the rest of the program to print the display and record the data to file. And I might add, there is also a Sub cmdProcessData2_Click() so that above is in there twice; that's why having a separate sub to handle the field validation would be nice. But yeah, OC, did you ever get the email I sent you? If you did, erase it. I totally changed the program around so it's not anywhere near the same anymore. Lots have changed.


No sorry I don't recall getting the email. I probably deleted by mistake when I was deleting all the spam. I'm so sick of the make *insert body part* *select bigger or smaller* emails. We need a national don't email list like the phone calls.

if you want a field validation function you need to decide what is illegal and what isn't. Will numeric digits be allowed, spaces? Once you know what you don't want to have in the string then make a fucntion similar to this.

PHP Code:
 public function funcCheckText(txtField as string) as boolean

    funcCheckText 
true

    
'insert your string function here. Left or mid or InStr should do the trick

   if err.number<>0 then
      funcCheckText=false
  end if

end function 
__________________
"Game developers are like simple chemicals. (No, not because they're cheap and smelly.) In the right combination, they can make miracles. Screw up the mix, and you can blow up a city." - How to Screw Up a Perfectly Good Game Company in Ten Easy Steps, www.gamedev.net
 
Old 11 November 2003   #5
yup, I tried that. Here's the problem I'm running into:

Private Sub cmdCheckOut
Call ErrorChecking
Call CheckOut
End Sub

Private Sub ErrorChecking
If txtFirstNameInput.Text = "" Then
MsgBox "Sorry, you must enter your first name." , , "Input Error!"
End Sub
End If
End Sub

My problem is that as cmdCheckOut calls ErrorChecking, and if ErrorChecking finds errors and stops, the remainder of cmdCheckOut still continues to run. The only thing I could think of to correct this was to just include Call CheckOut as an "Else" statement in order to get things to work correctly. However, I have two buttons, one for check in and one for check out. This means that each one must have the field validation routine. I was hoping to have the routine in its own sub as opposed to in both cmdCheckIn and cmdCheckOut.
 
Old 11 November 2003   #6
Originally posted by singularity2006
yup, I tried that. Here's the problem I'm running into:

Private Sub cmdCheckOut
Call ErrorChecking
Call CheckOut
End Sub

Private Sub ErrorChecking
If txtFirstNameInput.Text = "" Then
MsgBox "Sorry, you must enter your first name." , , "Input Error!"
End Sub
End If
End Sub

My problem is that as cmdCheckOut calls ErrorChecking, and if ErrorChecking finds errors and stops, the remainder of cmdCheckOut still continues to run. The only thing I could think of to correct this was to just include Call CheckOut as an "Else" statement in order to get things to work correctly. However, I have two buttons, one for check in and one for check out. This means that each one must have the field validation routine. I was hoping to have the routine in its own sub as opposed to in both cmdCheckIn and cmdCheckOut.


Oh ok. Thats a simple fix. Error checking needs to be a function so that the second part of checkout is only run based on the outcome of error checking. Heres the basic concept. Also End subs, exits, and gotos are considered sloppy coding. They lead to having spaghetti code.

PHP Code:
 Dim result As Long

Private Sub cmdCheckOut
     result 
ErrorChecking()
     if 
result=False then
          Call CheckOut
     end 
if
End Sub

Private function ErrorChecking() as boolean
     ErrorChecking
=False
     
If txtFirstNameInput.Text "" Then
          MsgBox 
"Sorry, you must enter your first name." , , "Input Error!"
          
ErrorChecking=True
     End 
If
End Sub 

Edit: about the email was it actual email or a private message? If its a private message how do I get to it?
__________________
"Game developers are like simple chemicals. (No, not because they're cheap and smelly.) In the right combination, they can make miracles. Screw up the mix, and you can blow up a city." - How to Screw Up a Perfectly Good Game Company in Ten Easy Steps, www.gamedev.net

Last edited by OC-NightHawk : 11 November 2003 at 11:30 PM.
 
Old 11 November 2003   #7
ah wow, that's definitely cool! Thanks for the info! I had no idea you could manipulate the boolean test like that. Man, that is awesome! I'm definitely gonna program that in, super cool, much thanks!

Anyhow, I think it was an email. But it was sent through the CGTalk server so I'm not sure how that all works out. Anyhow, to access private messages, just click on the link at the top of the CGTalk menu that says "Profile" and somewhere in there is a thing for messages.

And to continue, there's also another thing I've run into problems with. I have two subs that print out stuff to screen. They print exactly the same thing except for the last few lines that say: "equipment checked out" and "equipment checked in"

So currently cmdCheckOut_Click calls a bunch of stuff, error checking, etc etc etc. then continues to CheckOut(). But if cmdCheckIn_Click is clicked, it goes to CheckIn() instead. However, the only difference is that CheckOut() prints, among other things, "Equipment Checked Out." CheckIn() prints, "Equipment Checked In." Is there a way to combine the two subs that do the printing, CheckIn() and CheckOut() so I don't have to have the redundant code in each yet have the distinction of printing "item checked out" or "item checked in?"

<---edit--->

Actually, scratch that. I find a way of doing it, though it's not as elegant as I want. I'll send you some samples when I have it programmed.

Last edited by singularity2006 : 11 November 2003 at 08:12 AM.
 
Old 11 November 2003   #8
I finished for the most part, what needs to be done in the program. I'm gonna go through a few more times over to clean up code and document the thing. But that won't happen anytime soon. If you could give me some input on what I should change, that'd be good. Here's a zip file for the source code and all (no documentation yet). If anyone could make any recommendations about cleaning it up, that'd be good, thanks.

http://staff.esuhsd.org/~ih-govt/dr...TermProject.zip
http://staff.esuhsd.org/~ih-govt/drop_box/roster.exe (here's the compiled executable).

And by the way, I've removed the majority of the original input fields. They are automatically filled upon login. This program will actually be used by my students so by entering their password, which is pre-programmed in, it will auto fill the necessary data. The login password is "begin."

And guys, go easy! This is only week 8 of my first programming class. I wonder if I'll be ready to take on C in a quarter or two. -.-"

Last edited by singularity2006 : 11 November 2003 at 09:57 PM.
 
Old 11 November 2003   #9
Looks good so far. One suggestion in regards to the passwords. Instead of hardwiring them in why not make a simple text file in notpad and type in a list of passwords with a carriage return seperating them? Then you can have the program read the password list and assign the strings into the password array you have set up. That way down the road you could even have it set up easily to allow them to create their own passwords on the fly. You may also want to look into the binary write format for the password file to make it a little more difficult to crack. If you still have time these little things would really make your project that much better.
__________________
"Game developers are like simple chemicals. (No, not because they're cheap and smelly.) In the right combination, they can make miracles. Screw up the mix, and you can blow up a city." - How to Screw Up a Perfectly Good Game Company in Ten Easy Steps, www.gamedev.net
 
Old 11 November 2003   #10
yeah, i was considering that. Most definitely. But that issue w/ security of the file itself was what bothered me. Can you explain what a binary write format is and how it works?
 
Old 12 December 2003   #11
Originally posted by singularity2006
yeah, i was considering that. Most definitely. But that issue w/ security of the file itself was what bothered me. Can you explain what a binary write format is and how it works?


To use a binary file you type in

Open FileName for Binary as # FileNum

The difference with this is that its random access so you can now read and write to the file.

You'll want to strip out any characters with an ASCII code greater than 127 because it doesn't give a hoot for special characters.

Other than that its just like before.
__________________
"Game developers are like simple chemicals. (No, not because they're cheap and smelly.) In the right combination, they can make miracles. Screw up the mix, and you can blow up a city." - How to Screw Up a Perfectly Good Game Company in Ten Easy Steps, www.gamedev.net
 
Old 12 December 2003   #12
wh0a, that's pretty cool. So the output file is just a bunch of jibberish if someone tried to read it?
 
Old 12 December 2003   #13
Yeah, the file will not be readable for people. However using straight binary can be cracked somewhat easily if someone knew how to do it. To make it slightly more diffrucult to be cracked you could create a cryptogram object set.

A Sub routine that takes all 126 ASCII characters and swaps the values around before the file is written. Then another sub that uses those values and sets them to where they should be for the program to work right before the file is read. You could also make it even harder to crack by having a set number of sets of keys and adding a number to the start of the file corrosponding to which key to use.
__________________
"Game developers are like simple chemicals. (No, not because they're cheap and smelly.) In the right combination, they can make miracles. Screw up the mix, and you can blow up a city." - How to Screw Up a Perfectly Good Game Company in Ten Easy Steps, www.gamedev.net
 
Old 12 December 2003   #14
dang, that sounds fun. I was actually tempted to write my own encryption script to mess around with coding and decoding strings of text. Hah, I might just do that right now. I'm @ work @ the moment and don't have my memory key w/ my term project on it.
 
Old 12 December 2003   #15
Work? I'm on winter break between quarters at college. I have no car, so I have no way to get to a job. So I'm in for a very crappy winter break.

I figure if I'm stuck home for winter I might as well get my Final 2 project under way since I already know what I'm going to do with it. So by the time class starts I can trickle in the work while working on new stuff. That way if I run into a day or two maybe a week where I need to do nothing and just chill I'll still have something to show. I'm busy cooking up some models for 4 street racing cars, a track, and props. I hope to get the content done before class starts back up and use 8 of the ten weeks to upgrade the graphics engine to use normal maps and shaders. When its done I want something that almost looks prerendered but in real time.I don't know how close I'll get to the goal but I shooting for it. I guess the extra 5 weeks won't hurt.
__________________
"Game developers are like simple chemicals. (No, not because they're cheap and smelly.) In the right combination, they can make miracles. Screw up the mix, and you can blow up a city." - How to Screw Up a Perfectly Good Game Company in Ten Easy Steps, www.gamedev.net
 
Thread Closed share thread



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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 05:23 AM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.