home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Ask a Tech Support Question (free)!

Critique this method

Reply
Get bargains at  »  Dealighted.com
 
Thread Tools Search this Thread
Currently Active Users: 1289
Discussions: 200,929, Posts: 2,379,145, Members: 246,296
Old September 30th, 2002, 03:04 AM   Digg it!   #1 (permalink)
Member
 
Join Date: Sep 2002
Posts: 364
Critique this method

This is in C#. The concept would apply to VB.Net or any other OO language such as Java though.

I have a form that displays data in combo boxes and text boxes from a data base. It lets the user navigate via the combo boxes. Based on the statistics of the records, it performs an algorithm to come up with a score.

Anyways, thats the main form the user uses. I have another form to add more records. The statistics for the new records are all generated radomly except one field. On this form, I have a button to genereate a new set of random stats if they don't like the ones they have been given. But I only give them 3 chances to go with what they want.

This is my problem: I need my program to remember how many times a user has generated new random statistics. If they've done it more than 3 times, they will have to close out the program and re-open it to 'cheat.'

This is some rough pseudocode of what happens (intCount keeps track of how many times a user has re-generated random stats):

On Create Reocrd Click:
--->Open frmCreate modally
------>Enter/Save new Records
------>On frmCreate.Closing
--------->Cancel closing
--------->Hide frmCreate
--->Add intCount from frmCreate to intCount on frmMain
--->Destroy frmCreate
--->Requery for new records on frmMain
End


When frmCreate is hidden, it allows frmMain to go on with its process, the first of which is adjusting the intCount figure so I can keep track of it for the duration of the program. If I would have not cancelled frmCreate's closing, then I would have lost frmCreate's intCount.

This works great, but....I am thinking there should be a better method for this. When frmMain is once again the visible form, you can see the form being repainted from the top to the bottom, kind of like a java applet.

Before I was keeping track of and letting users create an infinate number of random stats, when frmCreate would close, frmMain would be on the screen without that 'repainting' effect.\

Its a minor thing, and I can live with it, but I was just wondering if anyone had any ideas.


Last edited by Creosote : September 30th, 2002 at 03:08 AM.
Creosote is offline   Reply With Quote
Old September 30th, 2002, 03:36 AM     #2 (permalink)
Not Really a Member
 
Join Date: Oct 2001
Posts: 25,384
maybe keep a static int variable in the click procedure where the form is opened?
__________________
Helicopters don't fly; they vibrate so much and make so much noise that the earth rejects them.
vass0922 is offline   Reply With Quote
Old September 30th, 2002, 03:45 AM     #3 (permalink)
Member
 
Join Date: Sep 2002
Posts: 364
But I may or may not be wanting to add to my intCount. For example, is someone opens up the frmCreate, and closes it right away, then they've wasted one chance.

If they re-generate the stats while in frmCreate, then they've wasted 2 chances.

I would need a way to reference frmMain from frmCreate, but that's impossible. It would would if I was destroying frmMain when I was open frmCreate, then on closing frmCreate, making a new frmMain, but I don't want to do that either.
Creosote is offline   Reply With Quote
Old September 30th, 2002, 03:54 AM     #4 (permalink)
Not Really a Member
 
Join Date: Oct 2001
Posts: 25,384
maybe put the int in a module (not sure what they are in C#) and make it public so both forms can modify it on the fly?
ok, believe C would use a class .. could make it a property that you could set/retrieve?
vass0922 is offline   Reply With Quote
Old September 30th, 2002, 04:03 AM     #5 (permalink)
Member
 
Join Date: Sep 2002
Posts: 364
I know what you're saying. If it was VB6, I would have used a module, and the every other form would know that modules variables.

I do not think, or I haven't found, anything similar in C#. This program does have non-form classes that I've made to do algorithims and return values based on those algorithms. However, you have to create an instance of each class.

Example:

Class1 c1 = new Class1();
c1.setMethod(arguements);
variable = c1.getMethod();


But say I made a new instance of a varible-keeping class in frmMain. I don't know how I would access that same instance in frmCreate.

I'm not even sure if VB.Net has modules anymore.
Creosote is offline   Reply With Quote
Old September 30th, 2002, 04:26 AM     #6 (permalink)
Not Really a Member
 
Join Date: Oct 2001
Posts: 25,384
yup, still has modules

hmmm
maybe make a public int in the first form?
or you could pass the object as a param *shrug*
vass0922 is offline   Reply With Quote
Old September 30th, 2002, 08:29 PM     #7 (permalink)
Member
 
Join Date: Sep 2002
Posts: 364
Actually, I read somewhere on another forum, and I think you're right. Making a static variable might not make you need to create an instance of a class. I'm gonna try it out.

Thanks
Creosote is offline   Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Most Active Discussions
Is It Just Me? (2867)
Obama the Muslim (14)
Is the PSU I received dead? (10)
windows vista security holes (9)
HIS HD5770 graphic card question (15)
Print spooler problem (13)
Foreign voltage (10)
Install XP pro and a Vista laptop ?.. (10)
Dept. of HS: NSA 'Helped' Develop V.. (15)
A good PSU? (10)
Ideal cheap graph card for PC-Gamin.. (16)
New Computer wont recognize XP disc (7)
EVGA 9800 gtx help with finding a g.. (8)
Modern Warfare 2: Who Bought It? (61)
Recent Discussions
solutions for virtical white lines on.. (0)
Ideal cheap graph card for PC-Gaming? (16)
Regular Build (2)
Graphics Card Upgrade Question (0)
Fire in DVD (2)
Modern Warfare For the PC (33)
radeon x850xt platinum & shader 3 (3)
Have you switched yet? (84)
Install XP pro and a Vista laptop ?? (10)
Wireless Router+Cable Modems and Much.. (0)
Optical Audio A-B Switch (1)
windows vista security holes (9)
The NTDVM CPU has encountered an ille.. (24)
[F@H SPAM 11/16/09] ! 1/2 months to r.. (34)
Wireless speakers for PC? (11)
Print spooler problem (13)
Help getting around port 80 for camer.. (2)
Display shows 3x5 inch in middle of s.. (3)
monitor will not turn on at all, (1)
World's largest Monopoly Game using G.. (331)
Foreign voltage (10)
FiOS modem/router interfering with ne.. (7)
Browsers wont load websites (2)
Virus Doctor Popup? (1)
Dept. of HS: NSA 'Helped' Develop Vis.. (15)


All times are GMT -4. The time now is 03:41 AM.
TechIMO Copyright 2009 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28