Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,153,181 members, 7,818,566 topics. Date: Sunday, 05 May 2024 at 06:57 PM

Let Share Codes - Programming (2) - Nairaland

Nairaland Forum / Science/Technology / Programming / Let Share Codes (4200 Views)

Special Codes To Format Text On Nairaland / [Project] CGPA Mgt System VB.NET Project: Come In Let's Share Ideas On This / Running Python Codes In Php (2) (3) (4)

(1) (2) (Reply) (Go Down)

Re: Let Share Codes by krazied(m): 4:32pm On Nov 06, 2007
hey guyz am a student just studied c and trying to practice but can't seem to make my compiler work is there anywhere to get a c compiler better still java's and how do you use d java runtime enviroment just downloaded one pls try being explicit cry
Re: Let Share Codes by SayoMarvel(m): 5:45pm On Nov 11, 2007
I don't know if anyone needs the source code of my simple application that calculates the determinant of a 3 by 3 square maltrix.
Re: Let Share Codes by SmartK1(m): 1:01pm On Nov 12, 2007
I don't know if anyone needs the source code of my simple application that calculates the determinant of a 3 by 3 square maltrix.

You have tried man. Keep it up. I did exactly that, about 8 years ago when learning C. You can push it a little 4ward by use it to solve 3X3 simultaneous eqns. I mean real life situations like determining prices of known items.

Good luck.
Re: Let Share Codes by SmartK1(m): 5:26pm On Nov 12, 2007
Here is the code that converts amount in double to amount in words. I did it in C#. You may copy and use it if u like. It uses Nigeria currency :

Usage: AmountInWord(115.50) returns one hundred and fifteen naira fifty kobo only.

public static string AmountInWord(string amount)
{
long num;
long num2;
string str2;
string str3;
string str = "";
string[] strArray = new string[5];
amount = amount.Replace(",", ""wink;
amount = amount.Replace(" ", ""wink;
str = "";
try
{
double num3 = double.Parse(amount);
}
catch
{
throw new Exception("The amount supplied is not a number and therefore not convertuble"wink;
}
strArray[0] = "Trillion ";
strArray[1] = "Billion ";
strArray[2] = "Million ";
strArray[3] = "Thousand ";
strArray[4] = " ";
int index = amount.IndexOf("."wink;
if (index > -1)
{
str2 = amount.Substring(0, index);
str3 = amount.Substring(index, amount.Length - index);
if (str2.Length > 15)
{
throw new Exception("The amount supplied must not be greater than 999 999 999 999 999.99"wink;
}
str2 = string.Format("{0:D15}", long.Parse(str2));
str3 = string.Format("{0:F2}", double.Parse(str3));
}
else
{
if (amount.Length > 15)
{
throw new Exception("The amount supplied must not be greater than 999 999 999 999 999.99"wink;
}
str2 = string.Format("{0:D15}", long.Parse(amount));
str3 = "0.00";
}
amount = str2 + str3.Substring(1, 3);
int num5 = 0;
for (int i = 0; num5 <= 4; i += 3)
{
if (long.Parse(amount.Substring(i, 3)) > 0)
{
if (long.Parse(amount.Substring(i, 1)) > 0)
{
num = long.Parse(amount.Substring(i + 1, 1));
num2 = long.Parse(amount.Substring(i + 2, 1));
if ((num > 0) || (num2 > 0))
{
str = str + convert(amount.Substring(i, 1)) + "Hundred And ";
}
else
{
str = str + convert(amount.Substring(i, 1)) + "Hundred ";
}
}
num = long.Parse(amount.Substring(i + 1, 2));
num2 = long.Parse(amount.Substring(i + 1, 2));
if ((num >= 20) && (num2 <= 0x63))
{
num = long.Parse(amount.Substring(i + 1, 1) + "0"wink;
num2 = long.Parse(amount.Substring((i + 1) + 1, 1));
str = str + convert(num) + convert(num2);
}
num = long.Parse(amount.Substring(i + 1, 2));
num2 = long.Parse(amount.Substring(i + 1, 2));
if ((num >= 1) && (num2 < 20))
{
str = str + convert(amount.Substring(i + 1, 2));
}
str = str + strArray[num5];
}
num5++;
}
if (long.Parse(amount.Substring(0, 15)) > 0)
{
str = str + "naira ";
}
num = int.Parse(amount.Substring(amount.Length - 2, 2));
if (num > 0)
{
num = long.Parse(amount.Substring(amount.Length - 2, 2));
num2 = long.Parse(amount.Substring(amount.Length - 2, 2));
if ((num >= 20) && (num2 <= 0x63))
{
num = long.Parse(amount.Substring(0x10, 1) + "0"wink;
num2 = long.Parse(amount.Substring(0x11, 1));
str = str + convert(num) + convert(num2);
}
num = long.Parse(amount.Substring(amount.Length - 2, 2));
if ((num >= 1) && (num < 20))
{
str = str + convert(amount.Substring(amount.Length - 2, 2));
}
str = str + "kobo ";
}
return (str + "only"wink.ToLower();
}

private static string convert(long amount)
{
return convert(amount.ToString());
}

private static string convert(string amount)
{
switch (int.Parse(amount))
{
case 70:
return "seventy ";

case 80:
return "eighty ";

case 90:
return "ninety ";

case 0:
return "";

case 1:
return "one ";

case 2:
return "two ";

case 3:
return "three ";

case 4:
return "four ";

case 5:
return "five ";

case 6:
return "six ";

case 7:
return "seven ";

case 8:
return "eight ";

case 9:
return "nine ";

case 10:
return "ten ";

case 11:
return "eleven ";

case 12:
return "twelve ";

case 13:
return "thirteen ";

case 14:
return "fouteen ";

case 15:
return "fifteen ";

case 0x10:
return "sixteen ";

case 0x11:
return "seventeen ";

case 0x12:
return "eighteen ";

case 0x13:
return "nineteen ";

case 20:
return "twenty ";

case 30:
return "thirty ";

case 40:
return "fourty ";

case 50:
return "fifty ";

case 60:
return "sixty ";
}
return "";
}

public static bool IsNumeric(string val)
{
try
{
double num = double.Parse(val);
return true;
}
catch
{
return false;
}
}

Good luck
Re: Let Share Codes by yinka007(m): 11:43am On Nov 15, 2007
i think it will be better to share codes as attachments or using URL's eg. http://www.spiralteck.com
Re: Let Share Codes by SmartK1(m): 11:32am On May 12, 2008
Long time! Cooking up something , Sorry, I was away for a long time.
Re: Let Share Codes by SmartK1(m): 6:51pm On Apr 24, 2009
Hi guys, long time no see. Been busy with lots of projects recently.
OK let share this sample code to send mail HTML page using gmail server in C#:

  private String readHtmlPage(string url)
        {
            if (!System.IO.File.Exists(url)) return string.Empty;

            try
            {
                String result;
                WebResponse objResponse;
                WebRequest objRequest = System.Net.HttpWebRequest.Create(url);
                objResponse = objRequest.GetResponse();
                using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
                {
                    result = sr.ReadToEnd();
                    sr.Close();
                }
                return result;
            }
            catch (Exception ex)
            {
                App.LogError(ex);
                return string.Empty;
            }
        }


private void SendMailBtn_Click(object sender, EventArgs e)
        {               
                string mail = readHtmlPage(url);
                if (mail.Trim().Length == 0) return;

                string toAddress = "to_one@yahoo.co.uk";
                string fromAddress = "someone@gmail.com";

try
{

if (fromAddress.Trim().Length == 0)
{
MessageBox.Show(this, "Cannot send mail from an empty address. Please confirm the setting email.", "Byaxiom SendMail", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (toAddress.Trim().Length == 0)
{
MessageBox.Show(this, "Cannot send mail to an empty address. Please confirm the customer email.", "Byaxiom SendMail", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}

MailMessage msg = new MailMessage();
msg.IsBodyHtml = true;
msg.From = new MailAddress(fromAddress);
msg.To.Add(toAddress);
if (AppSettings.Default.EMailCopy.Length > 0)
msg.CC.Add("mycopyemail@yahoo.com"wink;

msg.Subject = subject;
msg.Body = message;

SmtpClient mailClient = new SmtpClient("smtp.gmail.com", 587);
mailClient.EnableSsl = true;
NetworkCredential cred = new NetworkCredential(toAddress, "fromAddresspassword"wink;
mailClient.Credentials = cred;

mailClient.Send(msg);
MessageBox.Show(this, "Track report mail sent to " + toAddress + ". Please confirm by checking your mail copy", "Byaxiom SendMail", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
App.LogError(ex);
MessageBox.Show(this, "There was an error sending mail. Please check your setings and internet connection.", "Byaxiom SendMail", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
        }
Re: Let Share Codes by blacksta(m): 7:43pm On Apr 24, 2009
@smark k

what would say is the best way of becoming a comptetent programmer in any choosen language. or could share scerets that has worked for you

thanks
Re: Let Share Codes by SmartK1(m): 11:08am On Apr 30, 2009
@blacksta

i. Have genuine interest in programming
ii. Sincerely ask yourself if u have what it takes
iii. Be consistent. It takes time to get used to programming
iv. Always be prepared to go some extra-mile. Go a step higher than the next person
v. Always open ur mind. Never close ur mind door. U could always find a better way of doing it.

Hey, manage this for now. Thanx
Re: Let Share Codes by cdeveloper(m): 2:27pm On May 11, 2009
I like this post and i think i have started something on this line before. Well I created a blog on www.youbanize.com recently because i wanted to create a place online to share programming experiences. I am a PHP programmer, a veteran in JavaScript and CSS. I have posted some of my codes in there;if you would like to share real experiences or learn from the experiences of others , you are welcome.
Re: Let Share Codes by textmypage(m): 1:44am On May 18, 2009
where can i get JDk and its product key to install
Re: Let Share Codes by okunade(m): 12:10pm On May 18, 2009
go to java.sun.com
Re: Let Share Codes by textmypage(m): 6:59am On May 20, 2009
Where can i get java file editor to download?
Re: Let Share Codes by textmypage(m): 7:07am On May 20, 2009
and I use Windows XP Professional 2008.make una help me out
Re: Let Share Codes by SmartK1(m): 5:46pm On Aug 28, 2010
He! long time.

Check me on http://kunlesmart..com for jQuery Cascading Dropdown plug-in.

You can let me know what you think, and if you have any problem using the guy.

Bless u.
Re: Let Share Codes by Beaf: 8:43pm On Aug 28, 2010
For those interested in generating CRUD queries and O/R Mapping, here's some starter code (you need to check my profile for the rest of the code, the spambot keep deleting my posts);

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SqlServer.Management.Smo;
using System.Collections.Specialized;
using Microsoft.SqlServer.Management.Sdk.Sfc;
using System.Data;
using Microsoft.SqlServer.Management.Smo.Wmi;
using System.ComponentModel;
using Microsoft.Win32;
//using Microsoft.SqlServer.Management.Smo.RegisteredServers;
using Microsoft.SqlServer.Management.RegisteredServers;
using Microsoft.SqlServer.Management.Common;

namespace UgowundoMappers.UgowundoDatabaseMapper
{
    public enum SMOObjectExceptions
    {
        SrvConnectionFailureException = 0,
        DbConnectionFailureException = 1,
        Unknown = 9
    }

    public class SMOObjects
    {
        public static string CurrentServerName = String.Empty;
        public static string CurrentDatabaseName = String.Empty;

        public static string[] ListServers(bool listLocalServersOnly)
        {
            DataTable dt = SmoApplication.EnumAvailableSqlServers(listLocalServersOnly);
            ManagedComputer mc = new ManagedComputer();
            if (dt.Rows.Count > 0)
            {
                string[] names = new string[dt.Rows.Count + mc.ServerInstances.Count];
                int count = 0;
                foreach (DataRow dr in dt.Rows)
                {
                    names[count] = dr["Server"].ToString();
                    if (dr["Instance"] != null && dr["Instance"].ToString().Length > 0)
                        names[count] += @"\" + dr["Instance"].ToString();

                    //names[count] = dr["Name"].ToString();
                    count++;
                }
                foreach (ServerInstance si in mc.ServerInstances)
                {
                    names[count] = si.Name;
                    count++;
                }
                Array.Sort(names);

                return names;
            }
            return new string[0];
        }
Re: Let Share Codes by Beaf: 8:50pm On Aug 28, 2010
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UgowundoStrings;
using System.Runtime.Serialization;
using System.Collections.ObjectModel;

namespace UgowundoMappers.UgowundoDatabaseMapper
{
[DataContract]
public class DatabaseStructure
{
[DataMember]
public string ServerName { get; set; }
[DataMember]
public string DatabaseName { get; set; }
[DataMember]
public List<TableStructure> TableCollection;
}

[DataContract]
public class TableStructure
{
[DataMember]
public string ServerName { get; set; }
[DataMember]
public string DatabaseName { get; set; }
[DataMember]
public string TableName { get; set; }
[DataMember]
public List<ColumnProperties> ColumnCollection;
}

[DataContract]
public struct ColumnProperties : IProperty
{
[DataMember]
public bool InPrimaryKey { get; set; }
[DataMember]
public bool ForeignKey { get; set; }
[DataMember]
public bool Identity { get; set; }
[DataMember]
public string Name { get; set; }
[DataMember]
public string DataType { get; set; }
[DataMember]
public int Size { get; set; }
[DataMember]
public int Scale { get; set; }
[DataMember]
public string Default { get; set; }
[DataMember]
public int Precision { get; set; }
[DataMember]
public bool AllowNulls { get; set; }
[DataMember]
public string DefaultValue { get; set; }
[DataMember]
public int IdentitySeed { get; set; }
[DataMember]
public int IdentityIncrement { get; set; }
[DataMember]
public bool IsRowGuid { get; set; }

public Collection<string> TemplateText { get; set; }
public string ObjectPath { get; set; }
}
}
Re: Let Share Codes by Mobinga: 12:09am On Aug 29, 2010
one of my wack c++ codes.
temperature converter cheesy
#include <iostream>;

using namespace std;
int main ()
{
int C,F; //°C=5/9(°F-32)
cout<<Enter Temperature in Farenheit;
cin>>F;
C=5/9(F-32)
cout<<Temperature in Celsius = C;


}


#include <iostream>
using namespace std;
int main ()
{
int a,b,c;
cout<<"b=";
cin>>b;
cout<<"c=";
cin>>c;
a=b+c;
cout<< a;


}

Re: Let Share Codes by SmartK1(m): 1:03pm On Aug 30, 2010
Beaf

How you dey? I love the code you provided, but really have not found any need for database mapping in my applications. Could u please give me some scenario. I really would like to know more about this stuff.

Thanx.

Note: I am not talking about creating classes that maps table fields.
Re: Let Share Codes by SayoMarvel(m): 4:10pm On Sep 02, 2010
I can't believe my eyes. This is the same old thread we used in those days when I was still a novice. I you check the first page of this thread you will see that I was unable to even parse a String to int but see me today, A near guru giving solutions to nairaland java problems. Thank you God. Starters in the house, work hard its the only road. I started out like you too.
@Smart K. Thanks for this thread.
Re: Let Share Codes by Beaf: 4:16pm On Sep 03, 2010
Smart K.:

Beaf

How you dey? I love the code you provided, but really have not found any need for database mapping in my applications. Could u please give me some scenario. I really would like to know more about this stuff.

Thanx.

Note: I am not talking about creating classes that maps table fields.

I de kampe, how your side?
That code is not only useful for mapping. You will find that, at the very least, it can list all Sql Servers on a network.
More important though, if you wish to take it a little further, its an intro to SQL Server Management Objects (SMO). With SMO, you can do every single thing SQL Server is capable of, what I've submitted is just a peep in.
Re: Let Share Codes by haleighaugustu: 9:53am On Jun 09, 2022
It is still used by 126 million players every month. The game's development started in 2009 when Markus Persson, the creator of Minecraft, released the Cave Game for PC. Get more interesting details about minecraft servers check it out.

(1) (2) (Reply)

Why Doesn't Anyone In Nigeria Code In A Lisp / Gtbank Buying Credit From Your Account --does Anyone Know The Technology Behind? / Is Freelancing As A Software Programmer Possible?

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 50
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.