#include "stdio.h"
#include "string.h"
#include "stdlib.h"
#define MAX 20
int data[20];
int top=-1;
int isFull(){
if(top==MAX-1) return 1; else return 0;
}
int isEmpty(){
if(top==-1) return 1; else return 0;
}
void push(int d){
if(isFull()==0){
top++;
data[top]=d;
}
}
int pop(){
int t=-1;
if(isEmpty()==0){
t=data[top];
top--;
}
return t;
}
void operasi(char o){
int a, b, h;
switch(o){
case '+':
a = pop();
b = pop();
h = b + a;
push(h);
break;
case '-':
a = pop();
b = pop();
h = b - a;
push(h);
break;
case '*':
a = pop();
b = pop();
h = b * a;
push(h);
break;
case '/':
a = pop();
b = pop();
h = b / a;
push(h);
break;
case '=':
a = pop();
if(a!=-1) printf("%d\n",a);
else printf("EMPTY\n");
}
}
int isOp(char* op){
if(strcmp(op,"+")==0 || strcmp(op,"-")==0 || strcmp(op,"*")==0 || strcmp(op,"/")==0 || strcmp(op,"=")==0)
return 1;
else return 0;
}
void main(){
char d[10];
while(1){
scanf("%s",d);
if(isOp(d)){
operasi(d[0]);
} else if(strcmp(d,"x")==0){
break;
} else push(atoi(d));
}
}
Author: antonie
fungsi split di delphi
function split(input: string; schar: Char; s: Integer): string;
var
c: array of Integer;
b, t: Integer;
begin
Dec(s, 2); // for compatibility with very old & slow split function
t := 0; // variable T needs to be initialized...
setlength(c, Length(input));
for b := 0 to pred(High(c)) do
begin
c[b + 1] := posex(schar, input, succ(c[b]));
// BREAK LOOP if posex looped (position before previous)
// or wanted position reached..
if (c[b + 1] < c[b]) or (s < t) then break
else
Inc(t);
end;
Result := Copy(input, succ(c[s]), pred(c[s + 1] - c[s]));
end;
penggunaan:
SPLIT(‘this is a test ‘,’ ‘,3) = ‘is’
SPLIT(‘data;another;yet;again;more;’,’;’,4) = ‘yet’
Check if a file is text or binary in Delphi?
function IsTextFile(const sFile: TFileName): boolean;
//thanks to Marcelo Castro - from Brazil
var
oIn: TFileStream;
iRead: Integer;
iMaxRead: Integer;
iData: Byte;
dummy:string;
begin
result:=true;
dummy :='';
oIn := TFileStream.Create(sFile, fmOpenRead or fmShareDenyNone);
try
iMaxRead := 1000; //only text the first 1000 bytes
if iMaxRead > oIn.Size then
iMaxRead := oIn.Size;
for iRead := 1 to iMaxRead do
begin
oIn.Read(iData, 1);
if (idata) > 127 then result:=false;
end;
finally
FreeAndNil(oIn);
end;
end;
(* ----- Sample call ----- *)
procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
begin
if IsTextFile(OpenDialog1.FileName) then
showmessage('is ascii')
else showmessage('is BinaryFile')
end;
end;
Penggunaan TXMLDoc di Delphi
saya mencoba menulis kembali sebuah unit tersendiri sehingga dapat digunakan untuk mengelola TXMLDoc dan dapat digunakan untuk menggantikan file .INI
unit uPenggunaanXml;
interface
uses
Forms, SysUtils, Windows, XmlIntf, XMLDoc;
type
TXMLConfig = class
private
FModified: Boolean;
FFileName: string;
FXMLDoc: TXMLDocument;
FBackup: Boolean;
function GetVersion: string;
public
constructor Create(const FileName: string); overload;
constructor Create; overload;
destructor Destroy; override;
procedure Save;
function ReadString(const Section, Key, default: string): string;
procedure WriteString(const Section, Key, Value: string);
function ReadInteger(const Section, Key: string; default: Integer): Integer;
procedure WriteInteger(const Section, Key: string; Value: Integer);
function ReadBoolean(const Section, Key: string; default: Boolean): Boolean;
procedure WriteBoolean(const Section, Key: string; Value: Boolean);
property Backup: Boolean read FBackup write FBackup;
property Version: string read GetVersion;
end;
implementation
{ TXMLConfig }
constructor TXMLConfig.Create(const FileName: string);
begin
inherited Create;
FBackup := True;
FFileName := FileName;
FXMLDoc := TXMLDocument.Create(Application);
FXMLDoc.Options := [doNodeAutoIndent];
if FileExists(FFileName) then
FXMLDoc.LoadFromFile(FFileName)
else
begin
FXMLDoc.Active := True;
FXMLDoc.AddChild('Configuration');
end;
end;
constructor TXMLConfig.Create;
begin
Create(ChangeFileExt(Application.Exename, '_cfg.xml'));
end;
destructor TXMLConfig.Destroy;
begin
Save;
FXMLDoc.Destroy;
inherited;
end;
function TXMLConfig.GetVersion: string;
begin
Result := '1.00';
end;
function TXMLConfig.ReadBoolean(const Section, Key: string; default: Boolean): Boolean;
begin
Result := Boolean(ReadInteger(Section, Key, Integer(default)));
end;
function TXMLConfig.ReadInteger(const Section, Key: string; default: Integer): Integer;
begin
Result := StrToInt(ReadString(Section, Key, IntToStr(default)));
end;
function TXMLConfig.ReadString(const Section, Key, default: string): string;
var
Node: IXMLNode;
begin
Node := FXMLDoc.DocumentElement.ChildNodes.FindNode(Section);
if Assigned(Node) and Node.HasAttribute(Key) then
Result := Node.Attributes[Key]
else
Result := default;
end;
procedure TXMLConfig.Save;
begin
if not FModified then
Exit;
if FBackup then
CopyFile(PChar(FFileName), PChar(FFileName + '.bak'), False);
FXMLDoc.SaveToFile(FFileName);
FModified := False;
end;
procedure TXMLConfig.WriteBoolean(const Section, Key: string; Value: Boolean);
begin
WriteInteger(Section, Key, Integer(Value));
end;
procedure TXMLConfig.WriteInteger(const Section, Key: string; Value: Integer);
begin
WriteString(Section, Key, IntToStr(Value));
end;
procedure TXMLConfig.WriteString(const Section, Key, Value: string);
var
Node: IXMLNode;
begin
if ReadString(Section, Key, '') = Value then
Exit;
Node := FXMLDoc.DocumentElement.ChildNodes.FindNode(Section);
if not Assigned(Node) then
Node := FXMLDoc.DocumentElement.AddChild(Section);
Node.Attributes[Key] := Value;
FModified := True;
end;
end.
Semoga membantu…
Fungsi-fungsi untuk Lock, Hibernate, Logoff, Shutdown Windows pada VB.NET
Harus import:
using System.Runtime.InteropServices;
Lock Computer:
[DllImport(“user32.dll”)]
public static extern void LockWorkStation();
Kemudian panggil fungsinya:
LockWorkStation();
Logoff:
[DllImport(“user32.dll”)]
public static extern int ExitWindowsEx(int uFlags, int dwReason);
Panggil fungsinya:
Logoff biasa:
ExitWindowsEx(0, 0);
Logoff force:
ExitWindowsEx(4, 0);
Reboot:
ExitWindowsEx(2, 0);
Shutdown:
ExitWindowsEx(1, 0);
Hibernate:
Application.SetSuspendState(PowerState.Hibernate, true, true);
Standby:
Application.SetSuspendState(PowerState.Suspend true, true);
Bagus kan??
Akses SQLite menggunakan JDBC (java)
import java.sql.*;
public class Main {
public static void main(String[] args) throws Exception {
Class.forName("org.sqlite.JDBC");
Connection conn = DriverManager.getConnection("jdbc:sqlite:test.db");
Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery("SELECT Question, Answer, Type FROM Questions");
while (rs.next()) {
System.out.println(rs.getString("1"));
System.out.println(rs.getString("2"));
System.out.println(rs.getString("3"));
}
rs.close();
conn.close();
}
}
Pembuatan Database SQLite dengan VB.NET 2005
Tutorial ini mencoba menunjukkan bagaimana koneksi dengan SQLite dengan VB.NET 2005.
Kita membutuhkan sebuah DLL yang bernama System.Data.SQLite (http://sqlite.phxsoftware.com/) yang bersifat freeware…
Imports System.Data.SQLite
Imports System.IO
Private Sub btn_createdb_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_createdb.Click
'Save Dialog Box
Dim f As New SaveFileDialog
f.Filter = "SQLite 3 (*.db3)|*.db3|All Files|"
f.ShowDialog()
'Create Database
Dim SQLconnect As New SQLite.SQLiteConnection()
'Database Doesn't Exist so Created at Path
SQLconnect.ConnectionString = "Data Source=" & f.FileName & ";"
SQLconnect.Open()
SQLconnect.Close()
End Sub
Private Sub btn_tables_create_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_tables_create.Click
Dim SQLconnect As New SQLite.SQLiteConnection()
Dim SQLcommand As SQLiteCommand
SQLconnect.ConnectionString = "Data Source=" & txt_dbpath.Text & ";"
SQLconnect.Open()
SQLcommand = SQLconnect.CreateCommand
'SQL query to Create Table
SQLcommand.CommandText = "CREATE TABLE " & txt_tables_name.Text & "(id INTEGER PRIMARY KEY AUTOINCREMENT, title TEXT, description TEXT, image BLOB);"
SQLcommand.ExecuteNonQuery()
SQLcommand.Dispose()
SQLconnect.Close()
End Sub
Selamat mencoba!
Mengembalikan Image BLOB Menggunakan Web Service (VB.NET)
Pada kasus ini kita menggunakan SQLSERVER sebagai databasenya, dengan field seperti ini:
Field Tipe Data
==============
RowID int(11)
Picture BLOB
Yang perlu anda lakukan adalah mengganti parameter yang digunakan untuk koneksi ke SQLSERVER:
Buat method seperti ini pada Web Service Anda…
' Parameternya adalah sebuah id suatu record tertentu
Public Function GetPicture(ByVal RowID As Long) As Byte()
Dim Con As SqlClient.SqlConnection
Dim DA As SqlClient.SqlDataAdapter
Dim SQL As String
Dim BA As Byte()
Dim SC As New SqlCommand
SQL = "SELECT Picture FROM Pictures WHERE RowID = " & RowID
Con = New SqlConnection("User ID=YourID;password=YourPassword;" & _"Data Source=SQLSERVER;Initial Catalog=DatabaseName")
SC.Connection = Con
SC.Connection.Open()
SC.CommandType = CommandType.Text
SC.CommandText = SQL
BA = CType(SC.ExecuteScalar(), Byte())
SC.Connection.Close()
SC.Dispose()
Return BA
End Function
Kemudian siapkan sebuah picture box (PictureBox1) dan buat prosedur ini pada VB Desktop Anda:
Public Sub SetPicBox(ByVal ImageArray As Byte())
Dim ArraySize As New Integer
ArraySize = ImageArray.GetUpperBound(0)
Dim fs As New System.IO.FileStream("tmp.gif",
System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write)
fs.Write(ImageArray, 0, ArraySize + 1)
fs.Close()
PictureBox1.Image = New Bitmap("tmp.gif")
End Sub
Dan terakhir pada event on_Load pada form Anda, buat prosedur ini.
Anda bisa menggantinya dengan event-event lain.
Pada contoh dibawah ini, kita mencoba menggambil record dengan nomor 23:
Private Sub frmPicture_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load SetPicBox(YourService.GetPicture(23)) End Sub
Nah, selamat mencoba!