|
nik121 wrote: Yea characterClass was the string for the Constructor in the class CharClasses. But the characterClass says that it doesn't exist in the current context.
WOW! I am not sure how can I explain this to you. All you can do is to get a book and learn the basics.
When you write code like CharClasses Class = new CharClasses(characterClass) , compiler is expecting the variable characterClass to be presented in the scope. Here you don't have characterClass declared. You need to declare the variable first before using it. Something like
string characterClass = "Warrior";<br />
CharClasses Class = new CharClasses(characterClass);
|
|
|
|
|
If I understand your question, Leveling should inherit CharClasses and use the base constructor characterClass , as follows:
Leveling lvl = new Leveling("Warrior");
public class CharClasses
{
public int healthPoints = 0;
public int manaPoints = 0;
public int strength = 0;
public int dexterity = 0;
public int speed = 0;
public int intelligence = 0;
public CharClasses(string characterClass)
{
if(characterClass == "Warrior")
{
healthPoints = 100;
manaPoints = 10;
strength = 10;
dexterity = 5;
speed = 3;
intelligence = 0;
}
if(characterClass == "Archer")
{
healthPoints = 75;
manaPoints = 10;
strength = 3;
dexterity = 10;
speed = 5;
intelligence = 0;
}
if(characterClass == "Assassin")
{
healthPoints = 75;
manaPoints = 10;
strength = 5;
dexterity = 3;
speed = 10;
intelligence = 0;
}
if(characterClass == "Mage")
{
healthPoints = 50;
manaPoints = 50;
strength = 0;
dexterity = 5;
speed = 3;
intelligence = 10;
}
}
}
public class Leveling : CharClasses
{
public int level = 1;
public int experience = 0;
public Leveling(string characterClass)
: base(characterClass)
{
if(experience == ((experience + 100) * 1.5))
{
level++;
}
}
}
If you use inheritance, and don't need to instantiate CharClasses directly, you may want to change you your access modifiers from all public to protected , etc.
Regards,
Gary
|
|
|
|
|
Hello I am trying to read several different integers from a data file and then store each integer into a different variable.Does anyone know how to do this?
This is my program so far:
class Program
{
static void Main(string[] args)
{
string fileName, num;
int temp;
Console.Write("ENTer filename: ");
fileName = Console.ReadLine();
StreamReader inputFile = new StreamReader(fileName);
num = inputFile.ReadLine();
while (num != null)
{
temp= Convert.ToInt32(inputFile.Read());
Console.WriteLine(num);
num =inputFile.ReadLine();
}
Console.WriteLine("Press enter to end Program");
Console.ReadLine();
}
}
|
|
|
|
|
Use a List<int> and add the value each time in the loop.
|
|
|
|
|
Thank you.Where in the program am i suppose to place List<int>?
|
|
|
|
|
Hi, everyone, i am a new member of this website. i encounted a problem in my GUI.
Right now i want to create a progressbar with pencentage done status running beside it. Can someone give me a hand? i appreciate it.
Peishen
|
|
|
|
|
Welcome!
There is a progress bar control available. You have to calculate the progress percentage and set that to Value[^] property of progress bar.
|
|
|
|
|
|
Try searching the articles - there must be 6+ articles on PBs
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
We have an existing application (so I can't make wholescale changes) that has a number of user controls that are displayed as follows:
Call a method (MyUserControl.ShowVaseline(Control parentControl) which
1. Creates a bitmap from the parentControl.
2. 'Grayscales' the bitmap
3. Creates an empty usercontrol with this bitmap as the background
4. Docks this newly created user control within the parentControl (so it LOOKS as if the parent control is disabled, whereas in fact it is invisible, hidden behind the newly created control)
4. Positions MyUserControl centrally within this newly created user control
The effect is that MyUserControl is shown on top of the parent control, will move with the parent control, and the parent control is disabled and appears 'greyed out'
In most cases this is fine and dandy for its purposes - which is essentially a desire to be able to access some top-level controls on the parent form at all times, while maintaining workflow through apparent modality of dialogs).
But when shown like this it is not 'Modal' in the Windows sense of the word - ie the code following MyUserControl.ShowVaseline(parentControl) is executed without waiting for MyUserControl to complete.
So the 'closing' of the user control is handled by it events which are handled by the parent :
...
MyUserControl.Close += MyUserControlClosed;
MyUserControl.ShowVaseline(Control parentControl);
}
private void MyUserControlClosed(Dialogresult dialogResult)
{
if (DialogResult.OK)
{
SoSomeStuff();
}
}
I would dearly like the ability to treat the control just like a modal dialog form, in some cases - so the LOOK would be the same (centered on an apparently disabled background) but I could do something like
DialogResult dialogResult = MyControl.ShowVaselineModal(parentControl);
if (dialogresult == DialogResult.Ok)
{
DoSomeStuff();
}
I don't really understand, technically, how a dialog form 'works' so don't really know where to begin.
I can think of having my main program enter a loop, checking the user control for a modal result
MyControl.ShowVaselineModal(parentControl);
while (MyControl.DialogResult == DialogResult.None)
{
Application.ProcessMessages();
}
if (MyControl.Dialogresult == DialogResult.Ok)
{
DoSomeStuff();
}
But surely there's something clever I'm missing?
Incidentally, the reason I want to do this is for the occasional situation where, for example, I am iterating a collection, and want to open a 'dialog' for (possibly) several items in the collection - with a true dialog I can just put the code in the loop - but using the existing Vaseline stuff, I have to faff about keeping references to where I am in the collection and/or what has been handled so I can continually reprocess the collection until I have done. It's not so much hard as annoying.
All help gratefully appreciated.
___________________________________________
.\\axxx
(That's an 'M')
|
|
|
|
|
Wow - what dogs breakfast to you have to go through to disable a form. Why not just walk the forms control tree and disable/grey the controls, you could even replace the vaseline (what a horrible name, brings back memo... oops) with a UC to do the disabling.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Yes - it is a dog's breakfast. But they didn't want the controls disabled because some of them became all but illegible in their default disabled state (due to particularly horrible colour schemes and the idiosyncrasies of the GUI (because some 3rd party controls look different when disabled to their windows counterparts, some user controls behaved differently etc.)
Initially all this faffing about was done using a series of helper classes (bizzarro world here, I tell you!) I at lewast put the functionality in the base class (so you can just say 'control.ShowVaseline' without worrying about what's going on behind). And you would still need some method of positioning the user control on top of the rest of the controls...
It actually looks quite nice - if you like that sort of thing.
The name stems from photography, where Vaseline is used to 'blur' an image, I believe, and not from any, ahem, medicinal usage, of which you appear to be over familiar
___________________________________________
.\\axxx
(That's an 'M')
|
|
|
|
|
can't you do something like set a flag in the UC (dialogresult ) and make the main form wait till the flag is reset before allowing progress. or possibly have the parent subscribe to an event on the UC.
Can the UC be changed to a borderless form - and therefore a real dialogresult can be used.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi,
i am using IE objects. i am getting one IHTMLElement "textarea".
manually in browser if we click on this text area then some javascript code runs. and i get captch. if i see the page source then i am getting... likke this...
;
so what i have to do is, i have to click on textarea by IE automation using microsoft.mstml classes.
Thanks for reply.....
<div class="ForumSig">yogesh</div>
|
|
|
|
|
Hello,
here is a libary you searching for. I foud this some time ago. With this libary you have full control
of the internet explorer here is the link:
http://watin.sourceforge.net/[^]
i hope this helps you
|
|
|
|
|
I've been battling this for a few hours so now I need help!
I'm converting a 64bit fixed point timestamp (32bit integer part, 32bit fractional part) to a DateTime by converting it to a TimeSpan adding that to an epoch, as the timestamp represents the number of seconds since the epoch.
The problem is I'm losing precision (I assume because of the cast to/from double and UInt64 - see code), so converting back from DateTime to timestamp gets a different value.
Any ideas?
using System;
class Program
{
static void Main(string[] args)
{
UInt64 timestampA = 14844064336383267476;
Console.WriteLine("TimestampA: {0}", timestampA);
DateTime dateTime = NTPConversion.TimestampToDateTime(timestampA);
Console.WriteLine("DateTime: {0}", dateTime);
UInt64 timestampB = NTPConversion.DateTimeToTimestamp(dateTime);
Console.WriteLine("TimestampB: {0}", timestampB);
Console.WriteLine("Discrepancy: {0}", timestampB - timestampA);
Console.ReadKey();
}
}
public static class NTPConversion
{
public static readonly DateTime Epoch = new DateTime(1900, 1, 1);
public static DateTime TimestampToDateTime(UInt64 timestamp)
{
TimeSpan timeSpan = TimeSpan.FromSeconds((double)timestamp / 4294967296);
DateTime dateTime = Epoch + timeSpan;
return dateTime;
}
public static UInt64 DateTimeToTimestamp(DateTime dateTime)
{
TimeSpan timeSpan = dateTime - Epoch;
UInt64 timestamp = (UInt64)((timeSpan.TotalSeconds * 4294967296d));
return timestamp;
}
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Hi Dave,
the problem is here: (double)timestamp
uint64 (aka long) has a 63-bit resolution, whereas double only has some 52 bits of mantissa, the remaining bits required to hold the exponent.
You'll have to smarten up your TimestampToDateTime() method by splitting the uint64 in two parts, and adding them separately to get the DateTime. Example:
long hipart=timestamp&0xFFFF0000;
long lopart=timestamp&0x0000FFFF;
DateTime dt=TimeSpan.FromSeconds(hipart*...);
dt.AddSeconds(lopart*...);
I strongly suggest you don''t use those magic numbers of yours either; they are incromprehensible; what I would do is write them as a formula, the compiler will multiply them for you, and better yet also make them named constants so their name indicates their meaning.
Cheers.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
|
Dave, I have just tried something for your TimestampToDateTime method and I got 09/07/2009 18:30:53 (dd/mm/yyyy), is that what you were hoping for?
If so I will post it for you.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi Henry,
Happy to look at anything, some fresh eyes/new perspective is always good!
I can retrieve the same DateTime no problem when just looking down to the second, but it changes when using milli/micro/pico second precision. That isn't necessarily a problem, so long as I can get the Timestamp data consistant after going through the conversion processes - see my reply to Luc below.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Hi Dave,
I have investigated a bit more, and there is a fundamental problem: DateTime and TimeSpan basically count ticks, there are 10 million ticks per second.
Your timestamp has much higher accuracy (4 billion parts in one second), so the extra information is lost forever when you turn them into DateTime/TimeSpan structs.
To convince yourself, make discrepancy a signed number, and try several timestamp values (even small numbers will show the problem, I tried numbers from 0.2 to 2.0 milliseconds where
ulong Shift32 = 0x0000000100000000UL;
ulong msec = Shift32 / 1000;
or use Reflector to peek into the code for DateTime properties Ticks and Seconds, and its AddSeconds() method.
Furthermore your unit changes from a binary one to a decimal one, and back; which is bound to cause round-off problems, similar to float and double having trouble representing 1.0/3.0*3 and 1.0/7.0*7
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
modified on Thursday, July 9, 2009 8:02 PM
|
|
|
|
|
Thanks Luc, I figured that there would be problems with the internal resolution of DateTime vs the timestamp
Unfortunately, that is probably not solvable, as the Timestamp format is not one of my own, but part of the NTP/SNTP[^].
I think my best solution is to round any timestamps to the acheivable precision of DateTime so I can at least get consistant data. The level of precision provided in the protocol is for the most part unecessary IMO.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Further to my earlier reply, and after a little more thought, accuracy of less than 1ms is probably not required so I only need 40 of the 64 bits - the 32 integer bits, and 8 fractional ones. This should make it a little easier I hope.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Sure. Due to the different bases (1 in 1000 and 1 in 2^32) you still are bound to encounter some odd values that get modified when applying a round-trip conversion.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
I think I've sorted it Luc. Part of the problem was TimeSpan.FromSeconds and FromMilliseconds are only accurate to 1 millisecond so it was bound to do wierd stuff!
The answer to that was to use TimeSpan.FromTicks, in combination with Math.Round(), and now I appear get 1 picosecond 10 nanosecond precision. [Edit] The resolution of Ticks per second [/Edit]
Obviously the first pass results in a different timestamp still - but it's acceptably close. I just run it through a TimestampRound method first so future comparisons are made against that.
public static class NTPConversion
{
public static readonly DateTime Epoch = new DateTime(1900, 1, 1);
public static UInt64 TimestampRound(UInt64 timestamp)
{
long ticks = (long)(Math.Round(
(double)timestamp / 0x100000000, 7, MidpointRounding.AwayFromZero)
* TimeSpan.TicksPerSecond);
UInt64 newTimestamp = (UInt64)(((double)ticks / TimeSpan.TicksPerSecond) * 0x100000000);
return newTimestamp;
}
public static DateTime TimestampToDateTime(UInt64 timestamp)
{
long ticks = (long)(Math.Round(
(double)timestamp / 0x100000000, 7, MidpointRounding.AwayFromZero)
* TimeSpan.TicksPerSecond);
TimeSpan timeSpan = TimeSpan.FromTicks(ticks);
DateTime dateTime = Epoch + timeSpan;
return dateTime;
}
public static UInt64 DateTimeToTimestamp(DateTime dateTime)
{
TimeSpan timeSpan = dateTime - Epoch;
long ticks = timeSpan.Ticks;
UInt64 timestamp = (UInt64)(((double)ticks / TimeSpan.TicksPerSecond) * 0x100000000);
return timestamp;
}
} Thanks for your help! If you see any obvious flaws in this - let me know!
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
modified on Friday, July 10, 2009 2:48 PM
|
|
|
|
|