Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,154,081 members, 7,821,715 topics. Date: Wednesday, 08 May 2024 at 05:09 PM

Let Share Codes - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Let Share Codes (4203 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)

Let Share Codes by SmartK1(m): 1:53pm On Sep 11, 2007
Hi guys,
I have been nursing the idea of starting my blog for some times now but I have been very busy doing office work.
I have seen wonders that have been done in nairaland by developers. I feel its high time we truly help each other. I created this forum to serve as a forum where a developer can meet and help other developers. Mainly
i. Lets share general codes: I mean keep your business rules and share codes that are needed almost everywhere;
ii. Post any question(s) bothering you and possibly I or any other developer might find an answer to it;
iii. Lets share concepts and ideas.

Warning: I am MS developer, meaning I may be able to assist on VB, VB.NET, C, C++, C#, OOP only. Notwithstanding, I have done a little JAVA in the past (or I may ask some colleagues in my office). I may also assist on Javascript, PHP, etc.

So, LET US SHARE.

Good Luck.
Re: Let Share Codes by xanadu: 2:46pm On Sep 11, 2007
Nice thread, Smart K. I am definitely interested, will be glad to share PHP codes where I can. Looks like the begining of something great here - some kind of code repository that will help developers here on Nairaland and hopefully help move the country forward technologically.
Re: Let Share Codes by SmartK1(m): 3:29pm On Sep 11, 2007
@xanadu, welcome.

Check this:
Topic: Classes or Linear Programming

It is very interesting how some developers have neglected the use of classes these days. I have worked with some organizations that have never heard of classes one way or the other. Let me use this opportunity to state the advantages of using classes (the ones I can remember):

i. Class encapsulates;
ii. Makes ur programming easier to maintain;
iii. Promotes readability;
iv. Oh sorry, Class is the core central of OOP: add any advantage that you think OOP has.

Please Note that all my postings in this forum shall come in classes (method, interface, property , ).

Good luck.
Re: Let Share Codes by xanadu: 12:32am On Sep 12, 2007
Just to add a couple of lines to Smart K's post above: I find that, in my experience with php, the biggest advantage of classes to me has been Reusability.
Using classes, you can use the same code for several programms or projects. You can achieve the same, of course, using functions - but in many cases even functions need to be 'customised' when being reused in different projects. Classes eliminate this.
So, to add to the advantages of classes:

v. Reusability/portability
Re: Let Share Codes by SmartK1(m): 9:57am On Sep 12, 2007
Hi all,
I have been writing aspx some times now and I discovered that I have been writing the same function every time, so I decided to put it in a class and just call the function from the class whenever I need the function.
Here is a class that helps you to upload image file e.g. passport (u dont need to bother urself everytime doing the same ):


public class UploadManager
{
public bool UploadFile(ref FileUpload f, ref string message)
{
if (!f.HasFile)
{
message = "No file is selected.";
return false;
}
HttpContext context = HttpContext.Current;
string sessionid = context.Session.SessionID;
string fileExtension = Path.GetExtension(f.FileName).ToLower();
string[] allowedExtensions = new string[] { ".jpeg", ".jpg" };
int totallegth = allowedExtensions.Length;
for (int counter = 0; counter < totallegth; counter++)
{
if (fileExtension == allowedExtensions[counter])
{
Bitmap myImage = new Bitmap(120, 140);
try
{
string path = context.Server.MapPath("~/UploadedImages/"wink;
string filename = sessionid + DateAndTime.get_Now().Millisecond.ToString() + ".jpg";
string fullpath = path + filename;
f.PostedFile.SaveAs(fullpath);
myImage = new Bitmap(fullpath);
if (((myImage.Width >= 110) & (myImage.Width <= 130)) & ((myImage.Height >= 130) & (myImage.Height <= 150)))
{
message = "~/UploadedImages/" + filename;
return true;
}
message = "Invalid Picture size! The Passport Photograph must be of size 120 X 140px";
return false;
}
catch (Exception exception1)
{
ProjectData.SetProjectError(exception1);
Exception ex = exception1;
AppException.LogError(ex.Message);
message = "Image could not be uploaded at the moment.";
ProjectData.ClearProjectError();
return false;
ProjectData.ClearProjectError();
}
finally
{
myImage.Dispose();
}
}
}
message = "Invalid Picture format! The Passport Photograph must a jpeg.";
return false;
}

}

Usage:
UploadManager um = new UploadManager();

if (um.UploadFile(this.filPassport, message) )
{
this.imgPassport.ImageUrl = message;
ViewState("picPath"wink = message;
}
else
{
this.lblErrorMesage = message;
}

Enjoy and pls let me know if u have any problem using the class.

Good luck.
Re: Let Share Codes by Fikzy(f): 8:11pm On Sep 12, 2007
I need to load a lot of records from database with C# and simultaneously UP date UI with status like "Loading X or Y, " and also update the progress monitor. I know its

Treading, I have raved around the internet and deciphering the tutorials on Threads is not working for me now. I need a code sample to handle my need.

I need help.

Cheers,
Re: Let Share Codes by SmartK1(m): 9:50am On Sep 21, 2007
Sorry Fikzy,
will get back to u b4 end of work today. i have been very busy lately.
Re: Let Share Codes by Fikzy(f): 11:51am On Sep 21, 2007
@Smart K
The BackgroundWorker Component allows a form to run an operation asynchronously. This is very useful when we deal with such kind of operations as database transactions, image downloads etc.

I used the backgroud worker to partially solve my code challenges but the following problem arose.

1. I needed to update UI like textbox with status of my program but couldnt because C# said i cant call the object from another thread. what i did then was to increament an integer and get the current value of the integer via a Timer's Tick() event. here, i update the textBox with the current value of the Increamenting integer.

2. I am not satisfied with the speed of loading. Ok, what i am realy loading is some byte records of about 1001K [Database size] into an ArrayList. my programs loads aproximatelly 1 record every 100miliseconds. i believe it should be able to do this faster.

Question: how do i know the default sleep time for the BackgroundWorker Class Thread. 2) can control the sleep time.

Ultimatelly, i want to be able to manage my app threading requirments withuout using the BackgroudWorker with the hopes that it will give me a better performance.
Re: Let Share Codes by Fikzy(f): 12:05pm On Sep 21, 2007
@Smart K
some how, this post is not active. why? or is there another code sharing link on this forumn where developers hang out?,
Re: Let Share Codes by SmartK1(m): 12:29pm On Sep 21, 2007
some how, this post is not active. why? or is there another code sharing link on this forumn where developers hang out?,

Not exactly that I know of but there also similar forums in programming. Its just a matter of time.
Re: Let Share Codes by Fikzy(f): 4:23pm On Sep 21, 2007
Guys, check out this link.

Title: How to: Make Thread-Safe Calls to Windows Forms Controls

It explains how to check if the call to a thread is from the current Thread or not,
it also explained how to update UI using the BackgroundWorker RunWorkerCompleted(, ) and ProgressChanged(, ) metchods.

http://msdn2.microsoft.com/en-us/library/ms171728(VS.80).aspx
Re: Let Share Codes by miclad(m): 9:20am On Sep 29, 2007
Good of you guy pls kindlly hlp me for the code (php) i can use for searching a domain name like whois and some other php tutorials i am a beginner my email is solution@miclad.com thanks Miclad.
Re: Let Share Codes by Fikzy(f): 7:48pm On Sep 29, 2007
@miclad

PHP scripts to do WHOIS, check this out;
http://www.hotscripts.com/PHP/Scripts_and_Programs/Networking_Tools/Whois/index.html

To get elementry tutorial on php, check this out;
http://www.phpfreaks.com/tutorial_cat/8/Basics-&-Beginner-Tutorials.php

PHP is interesting and easy to lean.

all the best,
Re: Let Share Codes by ritchboi: 10:29pm On Sep 29, 2007
i jus started learnin basic programin wit C.oviously u guys r WAY ahead of me,so can sum1 kindly share wid me where they studied IT,wat kinda job u do now or any oda tin dat can b helpful 2 me.Tanx
Re: Let Share Codes by Kobojunkie: 7:15pm On Sep 30, 2007
In the Spirit of Sharing code, anyone know how to write and able to share code for an ASP.NET/AJAX Image Preloader that basically allows users to select picture user would like to upload into web album and preview the image at the same time without necessarily uploading the picture I started working on one but since I am not really a Javascript guru, I was wondering if someone has already figured this out and would like to share.


KoboJunkie
Re: Let Share Codes by seluvsmayo(f): 9:20am On Oct 02, 2007
Hello Fellow Nairaland developers,
   Am relatively new to this site but have being so fascinated about this site, i really find it quite interesting to read different peoples comment on different issues. Am a learning developer and i just started working for this firm and basically the sofware they are using is Delphi, i dont know if there is anyone on this blog that is very familiar with that language I know its not like an everyday programming language but i will really appreciate it if there is anyone that will be of help to me. I hope i will get responses. Thank you
Re: Let Share Codes by Fikzy(f): 12:46pm On Oct 02, 2007
@seluvsmayo
I am not conversant with delphi but you can get tutorials corvering various aspect of Delphi from; http://www.delphibasics.co.uk/
Re: Let Share Codes by seluvsmayo(f): 1:46pm On Oct 02, 2007
thanks fikzy, have being to the site already but its still not giving me all i need. thanks anyway for your quick reply.
Re: Let Share Codes by Fikzy(f): 10:30am On Oct 04, 2007
Re: Let Share Codes by SmartK1(m): 7:14pm On Nov 01, 2007
c u guys morrow with something new. sorry for long-time-no-c. i have 2 busy lately.
Re: Let Share Codes by scientist(m): 7:39pm On Nov 02, 2007
shocked shocked shocked shocked  can i incorporate this code segment on a form in vb6.0 such that it enables me load pictures from a database?  e.g. ms access  grin grin grin grin
Re: Let Share Codes by Kobojunkie: 8:01pm On Nov 02, 2007
scientist:

  shocked shocked shocked shocked  can i incorporate this code segment on a form in vb6.0 such that it enables me load pictures from a database?  e.g. ms access  grin grin grin grin


You simply need to write an SQL Query/Stored procedure to return the dataset containing the information which you then attach to your datagridview control on the front end.

http://www.beansoftware.com/ASP.NET-Tutorials/Images-Database.aspx
Re: Let Share Codes by scientist(m): 1:40pm On Nov 03, 2007
shocked wow, now this is getting even much more interesting. I've heard of stored procedures but dont know what they are and how they are used/implemented on vb 6.0 since I've never used them. I need more lectures on these areas stored procedures and also on modules/classes/collections etc grin Thanks
Re: Let Share Codes by Kobojunkie: 5:15pm On Nov 03, 2007
Here is how to learn of anything , go to www.google.com type in Stored Procedures tutorial and select one of the many search results that follow, There is a ton of information available to every developer free of charge online. All you have to do is search for it .

http://www.geekpedia.com/
Re: Let Share Codes by SmartK1(m): 11:39am On Nov 05, 2007
Hi guys,
I was doing a project recently and I needed to interact with server without post back. Guess wath I did: I created a webservice and called the webservice from client with javascript and i could now upate my UI with javascript. isn't that cool. I guess i may share some of the codes with u.
Note: this is for aspnet developers (the sample code is c# though simple enough to convert).

i. Create a webservice called MyService
using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;

/// <summary>
/// Project: Byaxiom Service
/// Company: Byaxiom Solutions Limited, http://www.byaxiom.com
/// Author: I. A. Rahman
/// Created: October 2007
/// </summary>
[WebService(Namespace = "http://www.byaxiom.com/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService()]
public class MyService : System.Web.Services.WebService
{
public MyService()
{
//Uncomment the following line if using designed components
//InitializeComponent();
}

public string doSomething(string tabID)
{
string retVal = "Up Smart.";//do your business logics here
return retVal; //return back to javascript
}
}

ii. create an aspx code to consume the guy




<%@ Page Language="C#" AutoEventWireup="true" CodeFile="default.aspx.cs" Inherits="default" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Poolsol Portal 1.0</title>
<link href=", /stylesheets/main.css" rel="stylesheet" type="text/css" />
<link href=", /stylesheets/content.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" language="javascript" src=", /scripts/moduleProcess.js"></script>

<script type="text/javascript" language="javascript" >
function doSomethingFromWebService(action){
MyService.doSomething(action, doSomethingComplete, doSomethingError, doSomethingTimeOut);
}


function doSomethingComplete(arg)
{
document.getElementsByID("<%ReturnTextBox.ClientID %>"wink.value=arg;
}
function doSomethingTimeOut(arg)
{
alert("timeOut has occured"wink;
}
function doSomethingError(arg)
{
alert("error has occured: " + arg._message);
}

</script>
</head>

<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="~/MyService.asmx" />
</Services>
</asp:ScriptManager>
<table border="0" width="100%" style="border-collapse: collapse" id="mainTable">
<tr>
<td id="master_header_left" >&nbsp;<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="doSomethingFromWebService(1)" />
<asp:TextBox ID="ReturnTextBox" runat="server"></asp:TextBox></td>
</tr>
</table>
</form>
</body>
</html>

SO, GOOD LUCK.
Re: Let Share Codes by Kobojunkie: 11:44am On Nov 05, 2007
I worked on exactly same type of project. Calling server side code without postbacks from client side. I on the other hand did not have to use webservice, I instead made use of the ClientCallback objects in .NET , here is a sample and link


http://msdn2.microsoft.com/en-us/library/ms178210.aspx



using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class ClientCallback : System.Web.UI.Page,
System.Web.UI.ICallbackEventHandler
{
protected System.Collections.Specialized.ListDictionary catalog;
protected String returnValue;
protected void Page_Load(object sender, EventArgs e)
{
String cbReference =
Page.ClientScript.GetCallbackEventReference(this,
"arg", "ReceiveServerData", "context"wink;
String callbackScript;
callbackScript = "function CallServer(arg, context)" +
"{ " + cbReference + ";}";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(),
"CallServer", callbackScript, true);

catalog = new System.Collections.Specialized.ListDictionary();
catalog.Add("monitor", 12);
catalog.Add("laptop", 10);
catalog.Add("keyboard", 23);
catalog.Add("mouse", 17);

ListBox1.DataSource = catalog;
ListBox1.DataTextField = "key";
ListBox1.DataBind();

}

public void RaiseCallbackEvent(String eventArgument)
{
if (catalog[eventArgument] == null)
{
returnValue = "-1";
}
else
{
returnValue = catalog[eventArgument].ToString();
}
}
public String GetCallbackResult()
{
return returnValue;
}
}
Re: Let Share Codes by lucianoefe(m): 12:04pm On Nov 05, 2007
[b] hey pple, hw r yall doin? must commend the guy that started this blog, it seems every body in this blog is too advanced 4 me. is there any other blog where the young developers can meet? i've just started studyin Java, got a supposed to be compiler but i dont know hw to test wat i've studied. got it installed in my system though, but dnt knw hw to use it. can any body help? will be mo than grateful, wink[b]
Re: Let Share Codes by SmartK1(m): 12:15pm On Nov 05, 2007
i've just started studyin Java, got a supposed to be compiler but i don't know hw to test what i've studied.

Have u installed SDK. Which compiler are u talking about? What editor are u using.

it seems every body in this blog is too advanced 4 me. is there any other blog where the young developers can meet?
U can ask ur questions here or u can simply start ur question on a thread if u feel its worthwhile.

Good Luck.
Re: Let Share Codes by SmartK1(m): 9:45am On Nov 06, 2007
DOT NET: Anyone looking for ways to avoid page refresh re-sending your data. Check out
http://jarednevans.typepad.com/technoblog/2005/01/jareds_techno_b.html
Re: Let Share Codes by SayoMarvel(m): 10:42am On Nov 06, 2007
I am Oladeji Oluwasayo. I'm a Java Programmer. I'm highly intrested in this sharing of code stuff. I'm still young in programming but i can still solve problems. my codes will come in classes and they will be fully indented. I have a problem in getting integers from text fields.

int s;
JTextField f = new JTextField();
s = f.getText();

the above snipet only works if s is a String. I want i to work for integer.
Re: Let Share Codes by SayoMarvel(m): 10:54am On Nov 06, 2007
you don't know how to use your java compiler?

install JDK (java development kit), set the path, and then go to cammand prompt, browse to
the folder where you hava your source code, and use the command "javac".
for example if your code is named wolf.java and it is in the root directory of your hard disk c.
then at command promt. type "cd\".
you will have something like this. C:\>
then type "javac Wolf.java"
you will have "C:\>javac Wolf.java"
if your code contains no error. it will reurn to C:\>
then a class file will be generated. i.e Wolf.class
execute it by typing "java Wolf"
you will have C:\>java Wolf

the class file will be executed.

I do hope i've been able to solve your problem.
Re: Let Share Codes by SmartK1(m): 11:04am On Nov 06, 2007
int s;
JTextField f = new JTextField();
s = f.getText();

the above snipet only works if s is a String. I want i to work for integer.

try this man!

int s;
JTextField f = new JTextField();
s = Integer.parseInt( f.getText());

(1) (2) (Reply)

Why Doesn't Anyone In Nigeria Code In A Lisp / Writing Into A Local File From A Browser Using The HTML5 File System Api-help Me / 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. 87
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.