|
Peter_in_2780 wrote: Convert your number to a string, then play with characters or substrings. Convert back at the end if you need to
Wow! Never even thought about doing it that way!
Thank you,
Stephen
|
|
|
|
|
You could do this with bitwise math if you also throw in a lot of divisions and multiplies by 10..
But it will be a mess.
Why are you working with decimal digits anyway?
What is the actual problem you're trying to solve, maybe it could be done with hex digits instead?
|
|
|
|
|
A uint is always the same size (32 bits).
What you're trying to do is string manipulation of a decimal number, quite a strange thing to do but probably best done on the string representation.
|
|
|
|
|
I'm not sure how do you want to get the second sample. In the first case, string manipulation is a way to go. Other, more math (and probably faster) solution is to get a length of begin and then divide it by 10^(length-4). Ot sth like (not tested):
uint shorter=begin;
while(shorter >= 10000) {
shorter /= 10;
}
Greetings - Jacek
|
|
|
|
|
Thank you everyone. If I explain my requirements maybe it will help.
I am generating a serial number in the following format:
00000-00000-00000-00000
I pass in two values into the serialGenerator class
int ProductID
int ProductVersion
I then combine these into one int value, say for example 12345123
Then I get the hex byte array representing this value, and hash it.
I then take 2 bytes of the hash from predetermined positions.
Then, I need to perform the bitwise so that I take a fixed part of teh new int value, which will always be 5 digits (first part of the serial number)
Generating the rest I have figured out.
Hope this clears things
Regards,
Stephen
|
|
|
|
|
stephen.darling wrote: I then take 2 bytes
You can't get 293844 from two "bytes".
Largest unsigned value from two 8 bit bytes used to create a 16 bit value is 256*256=65536.
|
|
|
|
|
jschell wrote: You can't get 293844 from two "bytes".
Sorry, I meant two uint32 values...
Steve
|
|
|
|
|
I use the following code when closing a form:
protected override void OnClosing(CancelEventArgs e)
{
//Your alternate implementation
FormClosingEventArgs ce = e as FormClosingEventArgs;
if (ce != null)
{
switch (ce.CloseReason)
{
case CloseReason.ApplicationExitCall:
//Handle application exit call
break;
case CloseReason.FormOwnerClosing:
//Handle Form owner close
break;
case CloseReason.MdiFormClosing:
//Handle MDI parent closing
break;
case CloseReason.None:
//Handle unknown reason
break;
case CloseReason.TaskManagerClosing:
//Handle taskmanager close
break;
case CloseReason.UserClosing:
//Handle User close
break;
case CloseReason.WindowsShutDown:
//Handle system shutdown
break;
}
}
base.OnClosing(e);
}
However on one of my forms it just working, it used to work fine
I setup a new form but still no results, I set a breakpoint and it doesn't even hit it.
Can anyone help with this problem.
Any help will be appreciated.
Thanks in advance,
Michael
|
|
|
|
|
I find your code confusing for two reasons
1) you override OnClosing instead of the preferred OnFormClosing method. Are you targetting .Net 1.1?
2) you cast the CancelEventArgs to FormClosingEventArgs. Surely this will never work and the resultant value will always be null.
The breakpoint problem might be explained by the cautionary note regarding the Application.Exit method in http://msdn.microsoft.com/en-us/library/system.windows.forms.form.onclosing.aspx[^].
|
|
|
|
|
i have FTP server in my computer (Windows-7) called MyFTP
i have thit code to transfer from local directory to FTP server
this code work excellent
string MyFile = @"d:\Test.txt";
//string url = "ftpUrl/FileName";
string url = "ftp://127.0.0.1/Test.txt";
FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(url);
request.Method = WebRequestMethods.Ftp.UploadFile;
//request.Credentials = new NetworkCredential("user name", "password");
request.UsePassive = true;
request.UseBinary = true;
request.KeepAlive = false;
byte[] buffer = File.ReadAllBytes(MyFile);
using (Stream reqStream = request.GetRequestStream())
{
reqStream.Write(buffer, 0, buffer.Length);
}
and now i need to to transfer from FTP server to local directory in my computer
how to do it ?
modified on Thursday, August 11, 2011 5:11 PM
|
|
|
|
|
Hello Experts,
I would like ask how I will alow my client(the one browsing the internet) to upload the file into my web server. I set up my web application using the abyss web server so that I can host the website to my local machine, and for the FTP I use filezilla.
Below here is my code but it's only working in my local machine.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.IO;
using System.Net;
using System.Web.UI.WebControls;
namespace ftpPractice
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public void uploadFileUsingFTP(String CompleteFTPPath, String CompleteLocalPat)
{
try
{
FtpWebRequest reqObj = WebRequest.Create(CompleteFTPPath) as FtpWebRequest;
reqObj.Method = WebRequestMethods.Ftp.UploadFile;
reqObj.Credentials = new NetworkCredential("Akosidan", "newbie");
FileStream streamObj = File.OpenRead(CompleteLocalPat);
byte[] buffer = new byte[streamObj.Length];
streamObj.Read(buffer, 0, buffer.Length);
streamObj.Close();
streamObj = null;
reqObj.GetRequestStream().Write(buffer, 0, buffer.Length);
reqObj = null;
lblMessage.Text= "File Uploaded Successfully :)";
}
catch (Exception error)
{
Response.Write(error.ToString());
}
}
protected void cmdUpload_Click(object sender, EventArgs e)
{
uploadFileUsingFTP("ftp://localhost/recieveSample.txt", "C:\\someUsers\\someFolder\\Desktop\\sample.txt");
}
}
}
Comments,suggestion or recommendation is so much appreciated.
AkosiDAN <- newbie
|
|
|
|
|
|
Hello,
Thanks for the link. Now I don't need anymore 3rd party ftp server just to transfer file
Thanks again,
DAN
|
|
|
|
|
Hello,
I have an activeMQ broker and .net(c#) application that send and consume message without problem.
Now, I want to add some security to broker to avoid anyone else send or consume my messages.
So, I add simpleAuthenticationPlugin with username/password in AMQ configuration file, now in .net client I can't send messages because username/passw should be provided.
Until now all is ok, the problem is I dont found where to supply this information from code.
I can't set it in CachingConnectionFactory or SimpleConnectionFactory, it is not allowed, I dont find any other type of ConnectionFactory available in Spring.Messagin.Nms namespace I could use.
So I need some hint from any of you.
spring conf file is very simple:
<object id="ActiveMqConnectionFactory" type="Apache.NMS.ActiveMQ.ConnectionFactory, Apache.NMS.ActiveMQ">
<property name="UserName" value="usertest"/>
<property name="Password" value="passwordtest"/>
</object>
<object id="ConnectionFactory" type="Spring.Messaging.Nms.Connections.CachingConnectionFactory, Spring.Messaging.Nms">
<constructor-arg index="0" ref="ActiveMqConnectionFactory"/>
<property name="SessionCacheSize" value="10"/>
</object>
<object id="NmsTemplate" type="Spring.Messaging.Nms.Core.NmsTemplate, Spring.Messaging.Nms">
<constructor-arg index="0" ref="ConnectionFactory"/>
<property name="MessageConverter" ref="SimpleMessageConverter"/>
</object>
and in c# code I just use NmsTemplate as:
this.NmsTemplate.ConvertAndSend(msg);
Thanks in advances
|
|
|
|
|
Hi everybody!
I want to know if it is possible to get the USB port current value when I plug the device in it. The value should be get programmatically using C#. The second parameter I need is USB save power mode. The correct name of the property in the device manager is "Allow the computer to turn off this device to save power".
I managed to detect the device (if it is connected or disconnected) and read data from it correctly. Do these two properties belong to USB device or to USB port?! WinUSB Api did not give me clear answers to my questions.
Thanks!
|
|
|
|
|
Ok, this is probably a very basic question, but how would I go about creating the following (bear with me. I'm new to oop):
Lets say I'm in the automotive industry and I build a c# class called "Cars". Within this class, I have 2 properties:
-Model
-Year
So I can call them via Cars.Model & Cars.Year via code like this:
public class Cars
{
public string Model { get; set; }
public string Year { get; set; }
}
So far, so good....HOWEVER....now, I want to do a sub-property of Model, called Color. I would want to call it with something like this:
Cars.Model.Color = "green";
How would I create this "Color" property so that it becomes a sub-property of "Model"?
Thanks
|
|
|
|
|
You give Model a type that has a property called Color
|
|
|
|
|
I don't think somebody likes us giving this poster answers.
|
|
|
|
|
So it would seem..
Oh well, we probably got more upvotes because of it
|
|
|
|
|
I have been repeatedly asking to make comments mandatory for downvotes. I understand that the voter may put some garbage in the comments just for the sake of it. But it would help us to identify the trolls and banish them. (It can also help Chris to delete those downvotes).
|
|
|
|
|
As your code currently stands, you can't. What you need to do is create a class that Model implements (let's call it the Model class). Now, in this Model class, you'll have your Color property, so you end up with something like the following:
public class Cars
{
public Model Model { get; set; }
public string Year { get; set; }
}
public class Model
{
public string Color { get; set; }
} Now, a couple of things to consider here. First of all, you shouldn't be using a string for the Year property - it's really a number. Secondly, you shouldn't really call your class Cars - it's describing a single car, so it should really be called Car.
|
|
|
|
|
I think you're going about it wrong.
I think the Model class should have the Year property, but not the Color property. Although the Model class could have an AvailableColors collections.
|
|
|
|
|
Hey Guys,
I want to write a C# WinForms application, which on clicking a button will go to a particular web page and input the user name and password correctly. Once this step is done, it will go to the inbox and here i want to click a button. All this needs to be done with the web page in hidden mode.
For eg, Go to mail.yahoo.com and correctly enter the user name and password. Now it should click on the "Delete" button in my inbox.
Is it possible? Any sample code is welcome.
Thanks in advance
|
|
|
|
|
Gmail offers access over it's own API[^], might be easier.
Bastard Programmer from Hell
|
|
|
|
|
.NET 4.0
I have just finished finally figuring out how (in WinForms) to make changes to Properties in an ObservableCollection<T> fire notifications ... attaching events to ObservableCollection items, like adds, and deletes, are, of course, easily handled ... and it required a rather ugly hack to do it which involved casting an instance of an Observable<t> to the INotifyPropertyChanged interface.
Attempting to figure out if I have created a monstrosity, or if there's a better way, I have been searching CP for information on generic ObservableCollections<T>, and INotifyPropertyChanged, and just about everything that comes up is WPF or SilverLight related.
My impression is that WPF and SilverLight offer much more flexibile facilities for wiring-up property changes than WinForms, that 'INotifyPropertyChanged' is a different critter in WPF, and that one would not have the problem I encountered in WinForms in getting Property changes to raise events.
But, I would appreciate an opinion from those of you who I am sure know both WinForms and WPF well, if my impression is correct.
In the unlikely case I have discovered some useful technique for WinForms, I'll certainly publish an article on it here on CP.
thanks, Bill
"In the River of Delights, Panic has not failed me." Jorge Luis Borges
modified on Thursday, August 11, 2011 2:23 PM
|
|
|
|