transportation_15.jpg

bztronics

Advanced Technology for Better Living!

Home 
Company 
Software 
eBooks 
Store 
Circuits 
Code Tips 
Support 
Contact 

 

bztronics code tips

We will post little helpful programming tips on here from time to time. There are some great links on the bottom of the page for coders to get references as well. Borland Rad Studio 2007 is awesome by our reviews!

Here is a seriously easy and cool one liner to launch a website or file from a form (Windows Updated 11-21-08 for XP and Vista)

C++ Version for Visual Studio 2008 or Borland Rad Studio 2007

C++

char* URL = "http://www.bztronics.com";
// Now just use ShellExecute to run it
ShellExecute( NULL, "open", URL, NULL, "C:\\", SW_SHOW );

If you are using Delphi in Rad Studio 2007...

uses ShellApi

ShellExecute( handle, 'open' , 'http://www.bztronics.com', ' ', ' ' , SW_SHOW);
 
Remember that this is just a simple Windows API call. The function will open any file that Windows
has as an association to. If it is web address it will open the default browser. If it is a text file, it will open Notepad. This ancient function has been switched around in the last versions of Visual Studio 2008 and Rad Studio 2007. If you use ShellExecute() from older code, you will have to rearrange a few things. Pay attention - this is tricky for beginners!

HTTP with Java

Java and old J++ makes it very easy to do HTTP requests. You can use this code template as a guide when performing HTTP requests...

public void HTTP_Request()
{
try {
URL url = new URL(urlEdit.getText());//url
//setup http headers here
HttpURLConnection huc = (HttpURLConnection);
url.openConnection();
huc.setRequestMethod("POST");
huc.connect();
int code = huc.getResponseCode();
String response = huc.getResponseMessage(); //lblResponse.setText(urlEdit.getText()+ '\n'+ code +'\n'+ huc.getResponseMessage()); huc.disconnect(); //lblResponse.setText("");
}catch (IOException x) { show(); MessageBox.show("...Error Code...");}
}

One liner PHP to get an entire HTTP request document into a string variable

This is a cool one liner to get a web document into a string variable. This is very handy when you want to retreive an XML document or an RSS feed and use PHP parsing functions for dynamic web content.

$xm = file_get_contents('http://rss.news.yahoo.com/rss/mostviewedtc');

The entire html or XML document is contained in the variable $xm. Why would you use this? Many search engines increase page rank by how often content is changed, however many do not read "active content" from PHP or Java Scripts. You can use this little gem to create dynamic, updated HTML pages that all search engines recognize!

Optimizing 8051, PIC Microcontroller routines for speed

If you are using C to create your Micro Firmware, it is a good idea to drop into simple Assembly language routines to speed things up. As you probably already know, C handles stack routines automatically. Sometimes, the generated code is inefficient. This is because when you do a function call, ALL variables are automatically pushed to the FIFO stack. There are even more pushed to the stack when you cross a page boundary. Fortunately, you can use Assembly routines to override the default C operations. There are many times when you do not need to push and pop all of your variables to and from the stack, as many will not change in the called function. Depending on your compiler, you may even be able to avoid #PRAGMA directives, if your compiler supports inline Assembly.

Before function call...

asm {
push  Variable_1 // first variable you NEED to save
push Variable_2 //second variable you NEED to save
push Variable_x // ...any more variables that NEED to be saved

}

//On return

asm {
pop  Variable_1 // first variable you NEED to recall
pop Variable_2 //second variable you NEED to recall
pop Variable_x // ...any more variables that NEED to be recall

}

Just be sure not to leave anything out. This is an advanced optimization method, yet simple enough to be easily implemented by greenhorns. Depending on your compiler, compiler directives may need to be added and a complete Assembly function can be written to handle this automatically. Happy Coding!


Cool Code Links

Code Guru - http://www.codeguru.com

Programmers Heaven - http://www.programmersheaven.com/

Highly recommended Installer!

Cut you installer size down by 3 times, increase speed and delivery all for FREE using NSIS!

http://nsis.sourceforge.net/Main_Page

 

Web Design by bztronics 2007  © bztronics