|
I need to use Context API in one of my application to InvalidCastException.
The requirement is to create Context API, Activate it and then deactivate.
Can any one give me code snippet which deals with this Context API.
Thanks:
Rakesh
|
|
|
|
|
Not very sure about what you exactly need, but this[^] may be of some help.
SkyWalker
|
|
|
|
|
Hi,
I've bound link buttons in grid column.The columns are template fields. But its not align properly in the column. I've given the condition as follows
if (DataControlRowType.Header == Name)
{
// binding the data in the selected column
}
can any one of you give me the solution for solve this problem?
Thanks in advance.
Babu
|
|
|
|
|
Hi folks,
I am new to clipper and dbf format database.I need to access the dbf files through my windows services. Now i have using OLedb connection object to read the dbf file. here i have face the difficulty to access the memo field and lengthy columns( above 244 char length). In this case the oledb read only 244 char so i the data loss was happend. So i need to access the dbf file directly through binary level. Anybody having the knowladge in this problem please share with me.
advance wishes.
regards,
ranandbe
|
|
|
|
|
Hi
In my 'virtual roulette' table I need to increment the amount of times each random number has occured for any given amount of spins of the wheel. Each label (0-36) has another blank label next to it that will contain these occurances.
If for 3 spins the random numbers are 3,14 and 17. Blank labels 3,14 and 17 should now have the value 1.
Instead of typing IF RanNum = 1 the add 1 to lab1
IF RanNum = 2 the add 1 to lab2
IF RanNum = 3 the add 1 to lab3 etc.............
How do I use.....
STRING labNum = "lab" + RanNum
to then access the corresponding Label on the page?
FindControl is looking good but does that not just tell me if it is there or not?
Any help for this newbie would be great.
Harvey
|
|
|
|
|
Hello,
You could hold the instances in a Hashtable and use the number as a the key.
All the best,
Martin
|
|
|
|
|
Thought of that or an Array, what if I had a million spins though, how many instances can I have?
Thanks for the quick reply
|
|
|
|
|
imnotso# wrote: Thought of that or an Array, what if I had a million spins though, how many instances can I have?
What has the numbr of spinns todo with the number of labels?
I would think, that there only are your 32*2 instances, which are always hold in the hashtable.
Or have I missed something?
All the best,
Martin
|
|
|
|
|
You will still only have one hashtable (or array). This would be created once, and you would only be incrementing values in it. Here's a sample for an ArrayList:
private ArrayList _list;
public void SetupArray(int maxRows)
{
_list = new ArrayList();
for (int i = 0; i < maxRows; i++)
{
_list.Add(0);
}
}
public void RoleDice()
{
int val = ValueFromDiceRole();
Convert.ToInt64(_list[val])++;
}
Now, go ahead and call RoleDice one million times. Call it 10 million. The memory footprint won't go up that much.
-- modified at 8:20 Tuesday 30th January, 2007
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Construct an array that keeps your 37 labels in numerical order, whatever their names are.
Luc Pattyn
|
|
|
|
|
Would I then still not have to move the values from the array or table one by one (ie 37 times) to the labes on the screen?
I thought there might be some way of using a contructed STRING (Lab + RandonNumber) and then attach that to the corresponding Label on the screen using some function I don't know about !!
Cheers for the replies so far.
|
|
|
|
|
imnotso# wrote: Would I then still not have to move the values from the array or table one by one (ie 37 times) to the labes on the screen?
Ohhhh, here is the misunderstanding!!!!
in youre array or hashtable you hold just the reference to the lables on the form. So if you change a property in your Hashtablelabel[x].Text it will be shown also in the Form.
Hope that helps.
All the best,
Martin
|
|
|
|
|
It does help, thanks Martin. Good on ya.
|
|
|
|
|
Ok,
I just whant to get you a little more help, to make your code alittle more dynamic.
What I would do, is to create my one labelclass which inherits from System.Windows.Forms.Label.
This class has just one member per default: Number (which is integer).
Like this:
using System;
using System.ComponentModel;
using System.Collections;
using System.Diagnostics;
namespace WindowsApplication1
{
public class CasinoLabel : System.Windows.Forms.Label
{
private System.ComponentModel.Container components = null;
public CasinoLabel()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
private int _number;
[Browsable(true), Category("Casino")]
public int Number
{
get
{
return _number;
}
set
{
_number = value;
}
}
}
}
Now you can do much more fancy stuff with this class (I'm sure you will have a lot of ideas.)
Than place your new labels on your Form and set the Number Property over the designer.
In the Forms constructor you just have to search for your special Labels now and add them to a hashtable.
Like this:
private Hashtable CasinoLabels = new Hashtable();
public Form1()
{
InitializeComponent();
foreach(Control c in this.Controls)
{
CasinoLabel actlabel = c as CasinoLabel;
if(actlabel != null)
{
CasinoLabels.Add(actlabel.Number, actlabel);
}
}
}
If you then whant to set youre text property over a random number just do this:
CasinoLabel randomLabel = CasinoLabels[randomnumber] as CasinoLabel;
randomLabel.Text = "1";
I just wanted to play around a little!
All the best,
Martin
|
|
|
|
|
Top notch stuff Martin, thanks.
|
|
|
|
|
|
Labels are reference types, putting an existing label in an array (or some other collection)
is just an administrative operation, it does not change your label, nor does it create
a new one. It does provide a structured way to access one or more labels afterwards, as in:
Label[] myLabels=new Label[37];
for (int i=0; i<=36; i++) {
Label label=new Label();
label.Text="number "+i;
myForm.Controls.Add(label);
myLabels[i]=label;
}
myLabels[7].Text="I was here";
This snippet shows run-time actions to create labels and to add them to the form.
It does not include the code to take care of size, font, and location !
You could add these at will.
-- modified at 9:02 Tuesday 30th January, 2007
Luc Pattyn
|
|
|
|
|
The way this is usually done is to create an array of 37 ints... one for each number 0 to 36. Then in each cell of the array, you store the number of times that spot has been hit.
There are many ways to display the reports after each spin. I would say, just keep your 37 controls in an array, and match up the values. So, after a roll, you would have something like this:
<br />
hits[spot]++;
labels[spot].Text = rolls[spot].ToString();
There's some much more elegant solutions to this, but this is pretty straightforward.
|
|
|
|
|
I've eventually worked out how to hold the values in an array for any given amount of spins. The next part would be to get these values onto the page.
Do I need to have the labels in a Array as you suggest? Can't I now match the existing lables lb0,lb1,lb2lb3 etc on the screen to my new 0-36 array (arHitArray) with the 'hits' as values in?
sort of .....
for (int a=0; a < 37; a++)
{
lb(n).text = arHitArrary(n).value
}
otherwise it's just ........
lb0.Text = arNumArray[0].ToString();
lb1.Text = arNumArray[1].ToString();
lb2.Text = arNumArray[2].ToString();
lb3.Text = arNumArray[3].ToString();
which is ok but not very cool.
Thanks for so far though
-- modified at 12:28 Tuesday 30th January, 2007
|
|
|
|
|
You can do the former using reflection, but it makes the code significantly more complex and error prone since a typo won't be found at compile time. An array of labels is by far the easier solution.
--
Rules of thumb should not be taken for the whole hand.
|
|
|
|
|
Is this for a web application or what?
There's a lot of questions here, but the overall application should be extremely simple. No reflection or any of that junk needs to be done here, it's a simple roulette application. Using a bunch of Label controls for the UI isn't the best option, but it's viable.
Anyway, at the beginning of the program, you put all the Labels into one array and you create an array of integers to match. Probably just do this with 37 lines of code, that way, you can rename things later if you want, and you aren't depending on some majick naming scheme to make your app work.
Now, ideally, you are only going to represent one roulette spin each time... so you only have to update one Label and one integer each time... the one you hit. Follow me now? No loops or anything, just a simple event handler that generates your random number and updates a single element of the interface, and a single element of the integer array. C# is strongly typed, so you'll have to convert your int to string...
<br />
int num = (some random number);<br />
spots[num]++;<br />
(labels[num]).Text = spots[num].ToString();<br />
So your initialization is tricky, but then your operational phase is elegant and simple. This is ok as long as it enables a straightforward approach. Think about this in terms of M-V-C...
http://en.wikipedia.org/wiki/Model-view-controller[^]
M = array of integers representing the history of spins (you could also add other simple elements, like maybe a single integer representing the most recent roll)
V = array of Labels (and all the built-in crap that makes them work)
C = Buttons and such on the interface, and your event-handler function
|
|
|
|
|
I'm surprised people actually suggested a hash table for this... wtf???
|
|
|
|
|
Yeah, the hash table threw me a bit, I've got this simple little App working thanks to all the advice given. The bit stumping me was transfering the 'results' onto the corresponding lables on the page.
Thanks though, this forum really works !
|
|
|
|
|
the c# code:
public delegate void SchedulerEventDelegate(SchedulerEventType type, string scheduleName);
static public event SchedulerEventDelegate OnSchedulerEvent;
if (OnSchedulerEvent != null)
how can I convert this to VB?
more detail:
I have a code in c# from http://www.codeproject.com/csharp/eventscheduler.asp
My boss ask me to convert it to vb.net
currently I have a problem with this line:
Code:
if (OnSchedulerEvent != null) (in c#)
when i convert it to
visual basic code:--------------------------------------------------------------------------------If Not OnSchedulerEvent Is Nothing Then--------------------------------------------------------------------------------
the error I'll get:
Public Shared Event OnSchedulerEvent(type As SchedulerEventType, StrScheduleName As String)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.
what can I'll do????
C# code
Code:
public delegate void SchedulerEventDelegate(SchedulerEventType type, string scheduleName);
static public event SchedulerEventDelegate OnSchedulerEvent;
if (OnSchedulerEvent != null)
Vb.net code
visual basic code:--------------------------------------------------------------------------------Public Delegate Sub SchedulerEventDelegate(ByVal type As SchedulerEventType, ByVal StrScheduleName As String)
Public Shared Event OnSchedulerEvent As SchedulerEventDelegate--------------------------------------------------------------------------------
|
|
|
|
|
I dont think you need to do the check in VB. The VB RaiseEvent Should take care of this for you.
All you need should be:
RaiseEvent OnSchedulerEvent(...)
|
|
|
|