|
Hello,
I am using http to get a request from a server. The server has been setup to receive a customer ID and return the balance.
However, I am getting an error message with the code I am using below: "Invalid URI: The URI scheme is not valid."
From what I can make out by using wireshark is that the server expects a customerID and the balance will be returned. I am not sure that the data is another parameter that the server expects.
So how can I write the URL that expects a parameter like the customer ID?
Many thanks for any extra help,
<br />
private void btnGetBalance_Click(object sender, EventArgs e) <br />
{ <br />
try <br />
{ <br />
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("000.000.00.00:8080/billing/servlet/comm.billing.GetBalance?Date=17:54:24&CustomerID=8057"); <br />
HttpWebResponse res = (HttpWebResponse)wr.GetResponse(); <br />
StreamReader sr = new StreamReader(res.GetResponseStream()); <br />
string balance = sr.ReadToEnd(); <br />
} <br />
catch(UriFormatException ex) <br />
{ <br />
MessageBox.Show(ex.Message); <br />
} <br />
catch(Exception ex) <br />
{ <br />
MessageBox.Show(ex.Message); <br />
} <br />
} <br />
|
|
|
|
|
Problem solved.
I missed of the http://
|
|
|
|
|
Subtle, but it happens
|
|
|
|
|
Hi.
I'm currently creating a game that contains a lot of characters. I'm now facing the problem of getting a very high complexity in my application because of the high number of characters.
I wanted to make a CharacterHandler that creates instances of the characters (Need to be a factory patteren of a kind, character creations need to take game difficulty into accound etc.)
this is some code from a character:
public class Bananas : NormalBrush, ILevelObject, IPointObject
{
private readonly int _collisionGroup;
private readonly float _mass;
private Body _body;
private Geom _geom;
public Bananas(Vector2 position, int collisionGroup, float mass, float scale, ContentManager contentManager)
: base(Color.White, position, contentManager.Load<texture2d>("Content/Objects/Fruits/Bananas"))
{
_collisionGroup = collisionGroup;
_mass = mass;
base.Scale = scale;
}
}
Is there a way that i can change the inheritance of the objects to simplify the creation of the characters or maybe use C# generics to do the job?
Any improvements are welcome.
EDIT: To sum it up.
Instead of doing:
CharacterHandler.CreateBananas(position);
CharacterHandler.CreateOrange(position);
CharacterHandler.CreateApple(position);
I could do something like this:
CharacterHandler<bananas>.CreateCharacter(position);
and so on.
|
|
|
|
|
Hi,
I have a usercontrol inside a form.
The form has one toolStripButton.
I want change toolStripButton visibility from the usercontrol.
How can i do that?
I don´t want to open a new form!!!
In Form_Main:
public bool _visibility_form
{
set { ToolStripLabel_Username.Visible = value; }
}
In UserControl_Login:
private void button1_Click(object sender, EventArgs e)
{
Form_Main frm = new Form_Main();
frm._visibility_form = _visibility_usercontrol;
frm.Show();
}
bool visibilty = false;
public bool _visibility_usercontrol
{
get { return visibilty; }
}
|
|
|
|
|
You will need to give the UserControl a reference to the Form that contains it. You could then set that reference in the Form loaded event and use it in the button click handler.
|
|
|
|
|
Think about how any other control you have on your form call methods in your form... they raise events that you listen for. So, create an event / delegate in your user control then you can subscribe to it in your form and react accordingly.
Dave
|
|
|
|
|
Hi,
I am new to C# and currently using C# 2.0. I have
public struct event
{
public static int w_hr;
}
public struct day
{
public static event mon;
}
can I access day.mon.w_hr = 5; How do I accomplish this.
Thanks.
|
|
|
|
|
To start with, you probably don't want to call it "event" it is a reseved word. If you use the notation that all class and struct names are Pascal cased (the start of each word in the name starts with a capital letter) then you won't have a problem there.
brigates wrote: can I access day.mon.w_hr = 5; How do I accomplish this.
Other than the fact you are using a reserved word, that should otherwise work fine.
Sorry - I missed the fact that w_hr is also static. See Guffa's response. It is correct.
modified on Tuesday, July 15, 2008 7:53 PM
|
|
|
|
|
brigates wrote: can I access day.mon.w_hr = 5; How do I accomplish this.
No, you can't access it that way.
The w_hr property can only be accessed using event.w_hr as it is a static member.
brigates wrote: I am new to C#
Then you should not use structs, as they are trickier to implement correctly. Use classes.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
I have a struct that holds a value up to UInt64 . Depending on the value it could potentially be held in another Type .
I've got a function that whos return value is Type , which is the minimum required to hold the value.
From this returned Type , how do I create an object of that Type?
Dave
|
|
|
|
|
Have a look in the System.Reflection namespace for Activator (I think)
|
|
|
|
|
System.Activator Hmm... a little work to do to figure this one out!
Thanks Colin
Dave
|
|
|
|
|
The answer would be reflection. Whenever that's the answer, you are either doing something pretty complicated, or something wrong.
What is it that you are trying to accomplish, really? Usually there is an object oriented way to solve it.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
A member variable in my struct is a UInt64. (I'm only using unsigned types here!)
1. Assume that the member variable's value is 8 : The smallest Type that could have that value is a Byte so my method returns Type Byte.
From this Type returned by the struct I want to create a variable of Type Byte.
2. Assume that the member variable's value is 256 : The smallest Type that could have that value is a UInt16 so my method returns Type UInt16.
From this Type returned by the struct I want to create a variable of Type UInt16.
3. UInt32...
4. UInt64...
Dave
|
|
|
|
|
Yes, I got it so far, but what is the point? What do you plan to do with the data?
If you create data of different types, the data has to be boxed in an object. To then use the data, you have to unbox it to the actual type.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Depending on the type, the data needs to be handled differently.
I suppose I could box the variable to object inside the method and make it return Object then something like
if (returnedObject is Byte)
{
Byte x = 0;
}
else if(returnedObject is UInt16)
{
UInt16 x = 0;
} but I was ideally wanting to return a Type as the value itself is not needed so there seems no point in returning it - only the type. Also, this way I have to stay within each if block or x is out of scope.
Dave
|
|
|
|
|
This works and will suffice if it can't be done by returning Type
object x = new object();
if (returnedObject is Byte)
{
x = (Byte)returnedObject;
}
else if(returnedObject is UInt16)
{
x = (UInt16)returnedObject;
}
Dave
|
|
|
|
|
DaveyM69 wrote: This works and will suffice if it can't be done by returning Type
object x = new object();
if (returnedObject is Byte)
{
x = (Byte)returnedObject;
}
else if(returnedObject is UInt16)
{
x = (UInt16)returnedObject;
}
That code only unboxes the value and boxes it again. You can just copy the reference and get the same result:
object x = returnedObject
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Got it!
var x = Activator.CreateInstance(returnedType); It was simple after all
Dave
modified on Wednesday, July 16, 2008 4:21 AM
|
|
|
|
|
That's misuse of the var keyword. It should look like this:
object x = Activator.CreateInstance(returnedType);
It's still pretty useless. You can't really do anything with the data without checking the type and unboxing it. What is it that you are trying to accomplish?
[edit]
Actually, it's totally useless. You have created an instance of a value type without a value, and as it's boxed, you can't set the value of the instance.
Despite everything, the person most likely to be fooling you next is yourself.
modified on Wednesday, July 16, 2008 8:52 AM
|
|
|
|
|
Yeah - I figured that trying to apply it! Returning a new initialized instance of the correct type instead of just the type and checking using is on return is working, I've just had to restructure the code a little. Just seemed a little messy though but problem solved. Thanks for your help.
Dave
|
|
|
|
|
Hi All,
I'm looking to create a set of stats from a DataTable and I'm currently having a bit of trouble working out the best way to do it. There are a few columns in the table that I'm interested in with an unknown number of possible values in each of these columns. I have defined a Statistic type like:
public class Statistic
{
public string StatNameTag { get; set; }
public string Description { get; set; }
public int Value { get; set; }
public double Percentage { get; set; }
public Statistic()
{
}
}
Which are in turn held in:
public static ObservableCollection<statistic> StatsCollection = new ObservableCollection<statistic>();</statistic></statistic>
Currently I'm thinking that a foreach loop over the table is the way forward. Each time a new value in a given table column is found I'll create a new Statistic object to hold the information in and give it a StatTagName that includes the value in the name which will provide a way to find out if its a new value or not. If its not a new value increment the value on the current Statistic object already in the collection.
Am I going in the right direction with this, or would it make more sense to use the .Compute() method or something else altogether? Or should I skip this altogether and execute a series of ExecuteScalar() commands directly on the database after performing a distinct select on each column i'm interested in?
I'm struggling with the best way to go with this. Everything else seems a bit expensive compared to a foreach loop over an already loaded DataTable object.
Any input would be great. TIA,
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
Hmmm - rather than using a DataTable, why not take a look at using Linq to do this? It would look something like:
var p1 = from p in dataContext
group p by p.Name
into MyGroup
select new { MyGroup.Description, MyGroup.Group.Sum(x=>x.Percentage), MyGroup.Group.Sum(y=>y.Value), MyGroup.Description }; I'm typing this blind, so it might not be 100% accurate, but you should get the idea.
|
|
|
|
|
That does look interesting indeed!! I'll have a play around with this method. Thanks Pete.
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|