|
This actually works... I've taken out the structure of the database but this does work to put the file in the database in the form of bytes.
Private Function insertDatabase(ByVal filename As String, ByVal int As Integer)
Dim command As SQLite.SQLiteCommand
Dim upload As New System.IO.FileStream(******, FileMode.Open, FileAccess.Read)
Dim filedata(upload.Length) As Byte
upload.Read(filedata, 0, filedata.Length)
upload.Close()
database.ConnectionString = "Data Source= test.db3;"
database.Open()
command = database.CreateCommand
'Insert Record into Database
command.CommandText = "INSERT INTO Vault(******,*******,*****) Values (@tfile, @data, @size);"
command.Parameters.AddWithValue("@tfile", filename)
command.Parameters.AddWithValue("@data", filedata)
command.Parameters.AddWithValue("@size", int)
command.ExecuteNonQuery()
command.Dispose()
database.Close()
Return 1
End Function
And I now I'm having trouble taking the file out of the database. I'm trying to reverse what I did but its not working all that well. So far I can extract the attributes I need but still need some work. Any suggestions would help.
|
|
|
|
|
Hi,
My VB 6.0 applications run perfectly under 64 bits OS, except for one single thing :
MS Chart errors out at run time when setting the number of cols or rows !
The same apps run PK pn Win 7 - 32 bits.
Is there a way around to avoid this ?
Thanks in advance.
Georges
|
|
|
|
|
Use a component that isn't 15 years old.
Without knowing the error message you get, it's impossible to tell you what the problem is.
|
|
|
|
|
What is the equivalent code in vb?
This is Delphi code
Thanks!
{
***** Process scheduling - FCFS, HRRN, SPN simulator ********
**
** Tested on Microsoft Windows XP SP2
**
** Written with Borland Delphi 7 Enterprise edition
**
*******************************************************
**
*******************************************************
* Greets:
**
** To my dear mother, father & anybody who supports me
**
******************************************************* }
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ExtCtrls, XPMan, ComCtrls;
(****************************************************************************)
Type
TProcess=Record
Name:String;
ArrivalTime:Integer;
ServiceTime:Integer;
FinishTime:Integer;
TimeLeft:Integer;
Tq:Integer; {Turnaround time: total time in system, waiting + execution}
TqDivTs:Real; {Tq/Ts: Is the normalized turnaround time.
This value indicates the
relative delay experienced by a process.}
end;
(****************************************************************************)
Type TOrigin=Packed Record
X: Longint;
Y: Longint;
end;
(****************************************************************************)
Type
TForm1 = class(TForm)
XPManifest1: TXPManifest;
SaveDialog1: TSaveDialog;
SaveDialog2: TSaveDialog;
MemoService: TMemo;
Memo1: TMemo;
MemoArrival: TMemo;
MemoProcess: TMemo;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Image1: TImage;
BtnStart: TBitBtn;
btnSavePicture: TBitBtn;
btnSaveLog: TBitBtn;
ComboScheduling: TComboBox;
Label5: TLabel;
StatusBar1: TStatusBar;
procedure ComboSchedulingSelect(Sender: TObject);
procedure MemoArrivalKeyPress(Sender: TObject; var Key: Char);
procedure MemoServiceKeyPress(Sender: TObject; var Key: Char);
procedure BtnStartClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure btnSavePictureClick(Sender: TObject);
procedure btnSaveLogClick(Sender: TObject);
(****************************************************************************)
private
Procedure SortQueue;
Procedure CheckErrors;
Procedure ClearCanvas;
Procedure FilterNumericKeys(var Memo:TMemo;var Key:Char);
procedure TrimMemo(var Memo:TMemo);
Function CountsAreEqual:Boolean;
Function DualProcess:Boolean;
Procedure InitQ;
Procedure FCFS;
Procedure SPN;
Procedure DrawAxle;
Procedure DeleteElementFromReadyQ(Loc:Integer);
Procedure HRRN;
Public
Max:Integer;
Origin:TOrigin;
ReadyQ:Array of TProcess; {Dynamic Array of TQueue}
end;
var Form1: TForm1;
implementation
{$R *.dfm}
(***********************************************************************)
Procedure Tform1.FilterNumericKeys(var Memo:TMemo;var Key:Char);
begin
If Not( Key In ['0'..'9',#8,#13] ) Then Key:=#0;
end;
(*******************[ Accepts Numeric Keys]**************************)
procedure TForm1.MemoArrivalKeyPress(Sender: TObject; var Key: Char);
begin
Self.FilterNumericKeys(MemoArrival,key);
end;
(*******************[ Accepts Numeric Keys]**************************)
procedure TForm1.MemoServiceKeyPress(Sender: TObject; var Key: Char);
begin
Self.FilterNumericKeys(MemoService,key);
end;
(***********************************************************************)
Procedure TForm1.btnSavePictureClick(Sender: TObject);
begin
If SaveDialog1.Execute then
Image1.Picture.SaveToFile(SaveDialog1.FileName);
end;
(***********************************************************************)
procedure TForm1.btnSaveLogClick(Sender: TObject);
begin
If SaveDialog2.Execute Then
Memo1.Lines.SaveToFile(SaveDialog2.FileName);
end;
(*******************[ Earse all blank lines ]********************************)
procedure Tform1.TrimMemo(var Memo:TMemo);
var
Index:Integer;
begin
With Memo do
begin
For Index:=0 To (Lines.Count-1) do
begin
Trim(Lines.Strings[Index]);
If (Lines.Strings[Index])='' Then Lines.Delete(Index);
end;
end;
end;
(***************** [2 Processes with the same name?]***************************)
function TForm1.DualProcess:Boolean;
var
I,J:Integer;
k:Byte; {0..255}
begin
K:=0;
With MemoProcess.Lines do
begin
For I:=0 To (Count)-1 do
For J:=(I+1) To (Count) do If (Strings[J])=(Strings[I]) Then Inc(K,1);
If (K > 0) Then
begin
Application.MessageBox('2 processes with the same name !','',mb_iconError);
Abort;
end;
end;
Result:=True;
end;
(******************[Count of lines are equal ?]******************************)
Function Tform1.CountsAreEqual:Boolean;
var
i,ProcessCount:Integer;
begin
Result:=True;
With Self do
begin
For i:=0 To MemoService.Lines.Count-1 Do
if Trim(MemoService.Lines.Strings[i])='0' Then
begin
ShowMessage('Serive time can not be zero');
Result:=False;
Exit;
end;
end;
With Self do
begin
ProcessCount:=MemoProcess.Lines.Count;
If Not((MemoService.Lines.Count= ProcessCount )And(MemoArrival.Lines.Count=ProcessCount)) Then
begin
Application.MessageBox('Lines count are''nt equal','',mb_iconerror);
Result:=False;
end
Else
Self.Max:=ProcessCount;
end;
end;
(***********************[Algorithm is Selected]******************************)
procedure TForm1.ComboSchedulingSelect(Sender: TObject);
begin
BtnStart.Enabled:=True;
end;
(*************************************************************************)
procedure TForm1.CheckErrors;
begin
Self.TrimMemo(MemoProcess);
Self.TrimMemo(MemoArrival);
Self.TrimMemo(MemoService);
If (Not(Self.CountsAreEqual)) Then Abort;
Self.DualProcess;
end;
(********************[In fact, our simulation satarts from here]**************)
procedure TForm1.FormCreate(Sender: TObject);
begin
Origin.X:=16 ;
Origin.Y:=16;
DrawAxle;
end;
(****************************************************************************)
procedure TForm1.BtnStartClick(Sender: TObject);
begin
Self.CheckErrors;
Self.DrawAxle;
Self.InitQ;
btnSavePicture.Enabled:=True;
btnSaveLog.Enabled:=True;
With Image1.Canvas do
begin
Case ComboScheduling.ItemIndex of
0: begin Self.FCFS; TextOut(Image1.Width-35,Image1.Height-15,'FCFS'); end;
1: begin Self.SPN; TextOut(Image1.Width-35,Image1.Height-15,'SPN'); end;
2: begin Self.HRRN; TextOut(Image1.Width-35,Image1.Height-15,'HRRN'); end;
End;
end;
end;
(***************************************************************************)
Procedure TForm1.ClearCanvas;
begin
With Image1.Canvas do
begin {Clears Canvas content with a white rectangle}
Brush.Color:=clWhite;
Brush.Style:=bsSolid;
Pen.Width:=1;
Pen.Color:=clWhite;
Rectangle(0,0,Image1.Width,Image1.Height);
end;
end;
(****************************************************************************)
Procedure Tform1.DrawAxle;
begin
With Image1.Canvas do
begin
Self.ClearCanvas;
Font:=Self.Font;
TextOut(Image1.Width-25,1,'Time' );
TextOut(1,Image1.Height-15,'Process');
Pen.Width:=2;
Pen.Color:=clBlue;
MoveTo(Origin.X,Origin.Y);
LineTo(Image1.Width-10,Origin.Y);
MoveTo(Origin.X,Origin.Y);
LineTo(Origin.X,Image1.Height-20);
RePaint;
end;
end;
(*****************************[ Initiliza Q ]*********************************)
Procedure Tform1.InitQ;
var
Next:Integer;
begin
Try
SetLength(ReadyQ,0);
SetLength(ReadyQ,Max);
For Next:=0 To (Max-1) do {Queue is FiFo }
begin
ReadyQ[Next].Name:=Trim(MemoProcess.Lines.Strings[Next]);
ReadyQ[Next].ArrivalTime:=StrToInt(Trim(MemoArrival.Lines.Strings[Next]));
ReadyQ[Next].ServiceTime:=StrToInt(Trim(MemoService.Lines.Strings[Next]));
end;
Except
ShowMessage('Initialize error');
end;
end;
(*****************************************************************************)
Procedure TForm1.SortQueue;
var
I,J:Integer;
T:TProcess; {Temporary}
begin
For I:=Low(ReadyQ) To High(ReadyQ)-1 do
For J:=(I+1) To High(ReadyQ) do
If (ReadyQ[i].ArrivalTime >= ReadyQ[j].ArrivalTime) Then
begin
T:=ReadyQ[i];
ReadyQ[i]:=ReadyQ[j];
ReadyQ[j]:=T;
end;
end;
(*****************************************************************************)
procedure TForm1.DeleteElementFromReadyQ(Loc:Integer);
begin
with ReadyQ[Loc] do
begin
Name:='';
ArrivalTime:=-1;
ServiceTime:=-1;
end;
end;
(***************************[Fist Come First Served]**************************)
Procedure Tform1.FCFS;
var
Sum,X,U,V,Y,I:Integer;
TqTs:Real;
M:String;
begin
Memo1.Lines.Add(' ');
Memo1.Lines.Add('FCFS:');
M:='Process Arrival Service Finished Tq Tq/Ts';
Memo1.Lines.Add(M);
M:='';
Memo1.Lines.Add('-----------------------------------------------------------------');
X:=(Origin.X)+2;
Y:=(Origin.Y)+2;
U:=35;
Self.SortQueue;
X:= X+ (ReadyQ[0].ArrivalTime * 20);
With Image1.Canvas do
begin
TextOut(X,1,IntToStr(ReadyQ[0].ArrivalTime));
For I:=Low(ReadyQ) To High(ReadyQ) do
begin
Pen.Width:=1; Pen.Color:= $00FF3620 ; Brush.Color:=$00FF9D93; Brush.Style:=bsSolid;
V:=X+(ReadyQ[I].ServiceTime*20);
Rectangle(X,Y,V,U);
Brush.Color:=clWhite;Brush.Style:=bsClear;
TextOut(1,Y,ReadyQ[I].Name);
TextOut(V,1,IntToStr(V div 20));
ReadyQ[i].FinishTime:=V div 20;
ReadyQ[i].Tq:=(ReadyQ[I].FinishTime)-(ReadyQ[I].ArrivalTime);
ReadyQ[i].TqDivTs:= (ReadyQ[i].Tq / ReadyQ[i].ServiceTime);
ReadyQ[i].TimeLeft:=0;
IF (V div 20) >= (ReadyQ[I+1].ArrivalTime) Then X:=V
Else
begin
X:=18 + (ReadyQ[I+1].ArrivalTime * 20);
TextOut(X,1,IntToStr(X div 20));
end;
Y:=U+2;
U:=U+17;
M:=M+' '+ReadyQ[i].Name + ' ' +
Format('%d',[ReadyQ[i].ArrivalTime]) + ' ' +
Format('%d',[ReadyQ[i].ServiceTime])+ ' ' +
Format('%3d',[ReadyQ[i].FinishTime])+ ' '+
Format('%2d',[ReadyQ[i].Tq]) + ' ' +
Format('%1.1f',[ReadyQ[i].TqDivTs] );
Memo1.Lines.Add(M);
M:='';
DeleteElementFromReadyQ(I);
end;
end;
Sum:=0;
For I:=Low(ReadyQ) To High(ReadyQ) Do Sum := Sum + ReadyQ[I].TQ ;
Memo1.Lines.Add('Average(Tq)= ' + Format('%1.2f',[sum/Max]) );
TqTs:=0;
For I:=Low(ReadyQ) To High(ReadyQ) Do TqTs := TqTs + ReadyQ[I].TqDivTs;
Memo1.Lines.Add('Average(Tq/Ts)= ' + Format('%1.2f',[TqTs/Max]));
end;
(****************************[Shortest Process Next]**************************)
Procedure Tform1.SPN;
var
Job,Sum,X,Y,U,V,min,J,I,K:Integer;
P:TProcess;
M:String;
TqTs:Real;
begin
Memo1.Lines.Add(' '); Memo1.Lines.Add('SPN:');
M:='Process Arrival Service Finished Tq Tq/Ts';
Memo1.Lines.Add(M); M:=''; Memo1.Lines.Add('-----------------------------------------------------------------');
X:=Origin.X + 2;
Y:=Origin.Y + 2;
U:=35;
Self.SortQueue;
I:=Low(ReadyQ);
P:= ReadyQ[I];
X := X + ( P.ArrivalTime * 20 );
Job:=Max;
Image1.Canvas.Textout(X,1,IntToStr(P.ArrivalTime));
With Image1.Canvas do
While Job > 0 do
begin
Pen.Width:=1; Pen.Color:=clGreen; Brush.Color:=clLime; Brush.Style:=bsSolid;
V:=X+(P.ServiceTime*20);
Rectangle(X,Y,V,U);
Brush.Color:=clWhite;Brush.Style:=bsClear;
TextOut(1,Y,P.Name);
TextOut(V,1,IntToStr(V div 20));
ReadyQ[I].TimeLeft:=0;
ReadyQ[I].FinishTime:= (V div 20);
ReadyQ[I].Tq:= (ReadyQ[I].FinishTime)-(ReadyQ[I].ArrivalTime);
ReadyQ[I].TqDivTs:= (ReadyQ[I].Tq / ReadyQ[I].ServiceTime);
Y:=U+2;
Inc(U,17);
M:=M+' '+ReadyQ[I].Name + ' ' + Format('%2d',[ReadyQ[I].ArrivalTime]) + ' ' +
Format('%d',[ReadyQ[I].ServiceTime])+ ' ' + Format('%3d',[ReadyQ[I].FinishTime])+ ' '+
Format('%2d',[ReadyQ[I].Tq]) + ' ' + Format('%1.1f',[ReadyQ[I].TqDivTs] );
Memo1.Lines.Add(M);
M:='';
DeleteElementFromReadyQ(I);
Dec(Job,1);
K:=(-1);
Min:=(9000);
For J:=Low(ReadyQ) To High(ReadyQ) do
begin
If (ReadyQ[J].ArrivalTime <= (V div 20))And(ReadyQ[J].ServiceTime <> -1) Then
If (ReadyQ[J].ServiceTime <= Min)Then
begin
Min:=ReadyQ[J].ServiceTime;
K:=J;
end;
end;
If (K <> -1) Then
begin
I:=K;
P:=ReadyQ[I];
end
Else
begin
For J:=Low(ReadyQ) To High(ReadyQ) do
If (ReadyQ[J].ServiceTime <> -1 ) Then
begin
I:=J;
P:=ReadyQ[I];
Break;
end;
end;
If (V div 20) >= (P.ArrivalTime) Then X:=V
Else
begin
X:= (Origin.X+2)+(P.ArrivalTime*20);
TextOut(X,1,IntToStr(X div 20));
end;
end;
Sum:=0;
For I:=Low(ReadyQ) To High(ReadyQ) Do Sum:=Sum+(ReadyQ[I].Tq);
Memo1.Lines.Add('Average(Tq)= ' + Format('%1.2f',[Sum/Max]) );
TqTs:=0;
For I:=Low(ReadyQ) To High(ReadyQ) Do TqTs:=TqTs+(ReadyQ[I].TqDivTs);
Memo1.Lines.Add('Average(Tq/Ts)= ' + Format('%1.2f',[TqTs/Max]));
end;
(*****************************[ HRRN ]*****************************)
Procedure TForm1.HRRN;
var
Job,Sum,X,Y,U,V,J,I,K : Integer;
P : TProcess;
M : String;
TqTs,Rate,Maximum : Real;
begin
Memo1.Lines.Add(' '); Memo1.Lines.Add('HRRN:');
M:='Process Arrival Service Finished Tq Tq/Ts';
Memo1.Lines.Add(M); M:=''; Memo1.Lines.Add('-----------------------------------------------------------------');
X:=Origin.X + 2;
Y:=Origin.Y + 2;
U:=35;
Self.SortQueue;
I:=Low(ReadyQ);
P:= ReadyQ[I];
X := X + ( P.ArrivalTime * 20 );
Job:=Max;
Image1.Canvas.Textout(X,1,IntToStr(P.ArrivalTime));
With Image1.Canvas do
While Job > 0 do
begin
Pen.Width:=1; Pen.Color:=$005098A5; Brush.Color:=$00A4CBD2; Brush.Style:=bsSolid;
V:=X+(P.ServiceTime*20);
Rectangle(X,Y,V,U);
Brush.Color:=clWhite;Brush.Style:=bsClear;
TextOut(1,Y,P.Name);
P.FinishTime:=(V div 20) ;
TextOut(V,1,IntToStr(P.FinishTime));
ReadyQ[I].TimeLeft:=0;
ReadyQ[I].FinishTime:= (P.FinishTime);
ReadyQ[I].Tq:= (ReadyQ[I].FinishTime)-(ReadyQ[I].ArrivalTime);
ReadyQ[I].TqDivTs:= (ReadyQ[I].Tq / ReadyQ[I].ServiceTime);
Y:=U+2;
Inc(U,17);
M:=M+' '+ReadyQ[I].Name + ' ' + Format('%2d',[ReadyQ[I].ArrivalTime]) + ' ' +
Format('%d',[ReadyQ[I].ServiceTime])+ ' ' + Format('%3d',[ReadyQ[I].FinishTime])+ ' '+
Format('%2d',[ReadyQ[I].Tq]) + ' ' + Format('%1.1f',[ReadyQ[I].TqDivTs] );
Memo1.Lines.Add(M);
M:='';
DeleteElementFromReadyQ(I);
Dec(Job,1);
K:=-1;
Maximum:=0;
For J:=Low(ReadyQ) To High(ReadyQ) do
begin
If (ReadyQ[J].ArrivalTime <= (P.FinishTime)) And (ReadyQ[J].ServiceTime <> -1) Then
begin
Rate:=( (P.FinishTime - ReadyQ[j].ArrivalTime) + (ReadyQ[j].ServiceTime)) / (ReadyQ[j].ServiceTime);
If Rate>Maximum Then
begin
Maximum:=Rate;
K:=J;
end;
end;
end;
If (K <> -1) Then
begin
I:=K;
P:=ReadyQ[I];
end
Else
begin
For J:=Low(ReadyQ) To High(ReadyQ) do
If (ReadyQ[J].ServiceTime <> -1 ) Then
begin
I:=J;
P:=ReadyQ[I];
Break;
end;
end;
If (V div 20) >= (P.ArrivalTime) Then X:=V
Else
begin
X:= (Origin.X+2)+(P.ArrivalTime*20);
TextOut(X,1,IntToStr(X div 20));
end;
end;
Sum:=0;
For I:=Low(ReadyQ) To High(ReadyQ) Do Sum:=Sum+(ReadyQ[I].Tq);
Memo1.Lines.Add('Average(Tq)= ' + Format('%1.2f',[Sum/Max]) );
TqTs:=0;
For I:=Low(ReadyQ) To High(ReadyQ) Do TqTs:=TqTs+(ReadyQ[I].TqDivTs);
Memo1.Lines.Add('Average(Tq/Ts)= ' + Format('%1.2f',[TqTs/Max]));
end;
(***************************************************************************)
end.
thanks
modified on Saturday, December 18, 2010 4:03 AM
|
|
|
|
|
This is only the interface, there should also be a part that describes the implementation. As is, your code is incomplete and can't be translated. To explain it in .NET terms, these are merely prototypes that describe the actual implementation.
We have a Delphi-forum - try there, and include the implementation if you need a translation. Keep in mind that translations aren't a service that the site offers; you can expect more help if you post a specific question.
I are Troll
|
|
|
|
|
Hi
How are you?
Thank you for the answer.
If the code is complete?
{
***** Process scheduling - FCFS, HRRN, SPN simulator ********
**
** Tested on Microsoft Windows XP SP2
**
** Written with Borland Delphi 7 Enterprise edition
**
*******************************************************
* Programmer:
**
**
*******************************************************
* Greets:
**
** To my dear mother, father & anybody who supports me
**
******************************************************* }
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ExtCtrls, XPMan, ComCtrls;
(****************************************************************************)
Type
TProcess=Record
Name:String;
ArrivalTime:Integer;
ServiceTime:Integer;
FinishTime:Integer;
TimeLeft:Integer;
Tq:Integer; {Turnaround time: total time in system, waiting + execution}
TqDivTs:Real; {Tq/Ts: Is the normalized turnaround time.
This value indicates the
relative delay experienced by a process.}
end;
(****************************************************************************)
Type TOrigin=Packed Record
X: Longint;
Y: Longint;
end;
(****************************************************************************)
Type
TForm1 = class(TForm)
XPManifest1: TXPManifest;
SaveDialog1: TSaveDialog;
SaveDialog2: TSaveDialog;
MemoService: TMemo;
Memo1: TMemo;
MemoArrival: TMemo;
MemoProcess: TMemo;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Image1: TImage;
BtnStart: TBitBtn;
btnSavePicture: TBitBtn;
btnSaveLog: TBitBtn;
ComboScheduling: TComboBox;
Label5: TLabel;
StatusBar1: TStatusBar;
procedure ComboSchedulingSelect(Sender: TObject);
procedure MemoArrivalKeyPress(Sender: TObject; var Key: Char);
procedure MemoServiceKeyPress(Sender: TObject; var Key: Char);
procedure BtnStartClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure btnSavePictureClick(Sender: TObject);
procedure btnSaveLogClick(Sender: TObject);
(****************************************************************************)
private
Procedure SortQueue;
Procedure CheckErrors;
Procedure ClearCanvas;
Procedure FilterNumericKeys(var Memo:TMemo;var Key:Char); // don't let to enter non-numeric keys
procedure TrimMemo(var Memo:TMemo); // earse all blank lines
Function CountsAreEqual:Boolean; //number of lines in MEMOs are equal
Function DualProcess:Boolean; // 2 process with the same name ?
Procedure InitQ; // initialize Arrays
Procedure FCFS;
Procedure SPN;
Procedure DrawAxle;
Procedure DeleteElementFromReadyQ(Loc:Integer);
Procedure HRRN;
Public
Max:Integer; // holds numbers of lines in memoProcess
Origin:TOrigin;
ReadyQ:Array of TProcess; {Dynamic Array of TQueue}
end;
var Form1: TForm1;
implementation
{$R *.dfm}
(***********************************************************************)
Procedure Tform1.FilterNumericKeys(var Memo:TMemo;var Key:Char);
begin
If Not( Key In ['0'..'9',#8,#13] ) Then Key:=#0;
end;
(*******************[ Accepts Numeric Keys]**************************)
procedure TForm1.MemoArrivalKeyPress(Sender: TObject; var Key: Char);
begin
Self.FilterNumericKeys(MemoArrival,key);
end;
(*******************[ Accepts Numeric Keys]**************************)
procedure TForm1.MemoServiceKeyPress(Sender: TObject; var Key: Char);
begin
Self.FilterNumericKeys(MemoService,key);
end;
(***********************************************************************)
Procedure TForm1.btnSavePictureClick(Sender: TObject);
begin
If SaveDialog1.Execute then
Image1.Picture.SaveToFile(SaveDialog1.FileName);
end;
(***********************************************************************)
procedure TForm1.btnSaveLogClick(Sender: TObject);
begin
If SaveDialog2.Execute Then
Memo1.Lines.SaveToFile(SaveDialog2.FileName);
end;
(*******************[ Earse all blank lines ]********************************)
procedure Tform1.TrimMemo(var Memo:TMemo);
var
Index:Integer;
begin
With Memo do
begin
For Index:=0 To (Lines.Count-1) do
begin
Trim(Lines.Strings[Index]);
If (Lines.Strings[Index])='' Then Lines.Delete(Index);
end;
end;
end;
(***************** [2 Processes with the same name?]***************************)
function TForm1.DualProcess:Boolean;
var
I,J:Integer;
k:Byte; {0..255}
begin
K:=0;
With MemoProcess.Lines do
begin
For I:=0 To (Count)-1 do
For J:=(I+1) To (Count) do If (Strings[J])=(Strings[I]) Then Inc(K,1);
If (K > 0) Then
begin
Application.MessageBox('2 processes with the same name !','',mb_iconError);
Abort;
end;
end; //with
Result:=True;
end;
(******************[Count of lines are equal ?]******************************)
Function Tform1.CountsAreEqual:Boolean;
var
i,ProcessCount:Integer;
begin
Result:=True; // init
With Self do
begin
For i:=0 To MemoService.Lines.Count-1 Do
if Trim(MemoService.Lines.Strings[i])='0' Then
begin
ShowMessage('Serive time can not be zero');
Result:=False;
Exit;
end;
end;
With Self do
begin
ProcessCount:=MemoProcess.Lines.Count;
If Not((MemoService.Lines.Count= ProcessCount )And(MemoArrival.Lines.Count=ProcessCount)) Then
begin
Application.MessageBox('Lines count are''nt equal','',mb_iconerror);
Result:=False; // Tell caller we got an error
end
Else
Self.Max:=ProcessCount;
end;
end;
(***********************[Algorithm is Selected]******************************)
procedure TForm1.ComboSchedulingSelect(Sender: TObject);
begin
BtnStart.Enabled:=True; // let's run
end;
(*************************************************************************)
procedure TForm1.CheckErrors;
begin
Self.TrimMemo(MemoProcess);
Self.TrimMemo(MemoArrival);
Self.TrimMemo(MemoService);
If (Not(Self.CountsAreEqual)) Then Abort;
Self.DualProcess;
end;
(********************[In fact, our simulation satarts from here]**************)
procedure TForm1.FormCreate(Sender: TObject);
begin
Origin.X:=16 ;
Origin.Y:=16;
DrawAxle; // Draw Vertical and Horizantal lines as axle
end;
(****************************************************************************)
procedure TForm1.BtnStartClick(Sender: TObject);
begin
Self.CheckErrors;
Self.DrawAxle;
Self.InitQ;
btnSavePicture.Enabled:=True;
btnSaveLog.Enabled:=True;
With Image1.Canvas do
begin
Case ComboScheduling.ItemIndex of
0: begin Self.FCFS; TextOut(Image1.Width-35,Image1.Height-15,'FCFS'); end;
1: begin Self.SPN; TextOut(Image1.Width-35,Image1.Height-15,'SPN'); end;
2: begin Self.HRRN; TextOut(Image1.Width-35,Image1.Height-15,'HRRN'); end;
End;
end;
end;
(***************************************************************************)
Procedure TForm1.ClearCanvas;
begin
With Image1.Canvas do
begin {Clears Canvas content with a white rectangle}
Brush.Color:=clWhite;
Brush.Style:=bsSolid;
Pen.Width:=1;
Pen.Color:=clWhite;
Rectangle(0,0,Image1.Width,Image1.Height); // clear canvas
end;
end;
(****************************************************************************)
Procedure Tform1.DrawAxle;
begin
With Image1.Canvas do
begin
Self.ClearCanvas;
Font:=Self.Font;
TextOut(Image1.Width-25,1,'Time' );
TextOut(1,Image1.Height-15,'Process');
Pen.Width:=2;
Pen.Color:=clBlue;
MoveTo(Origin.X,Origin.Y); //Origin is (16,16)
LineTo(Image1.Width-10,Origin.Y); //Vertical axle
MoveTo(Origin.X,Origin.Y); //Origin is (16,16)
LineTo(Origin.X,Image1.Height-20); //Horizantal axle
RePaint;
end;
end;
(*****************************[ Initiliza Q ]*********************************)
Procedure Tform1.InitQ;
var
Next:Integer;
begin
Try
SetLength(ReadyQ,0); // Empty last saved data
SetLength(ReadyQ,Max);
For Next:=0 To (Max-1) do {Queue is FiFo }
begin
ReadyQ[Next].Name:=Trim(MemoProcess.Lines.Strings[Next]);
ReadyQ[Next].ArrivalTime:=StrToInt(Trim(MemoArrival.Lines.Strings[Next]));
ReadyQ[Next].ServiceTime:=StrToInt(Trim(MemoService.Lines.Strings[Next]));
end;
Except
ShowMessage('Initialize error');
end;
end;
(*****************************************************************************)
Procedure TForm1.SortQueue;
var
I,J:Integer;
T:TProcess; {Temporary}
begin
For I:=Low(ReadyQ) To High(ReadyQ)-1 do
For J:=(I+1) To High(ReadyQ) do
If (ReadyQ[i].ArrivalTime >= ReadyQ[j].ArrivalTime) Then
begin
T:=ReadyQ[i];
ReadyQ[i]:=ReadyQ[j];
ReadyQ[j]:=T;
end;
end;
(*****************************************************************************)
procedure TForm1.DeleteElementFromReadyQ(Loc:Integer);
begin
with ReadyQ[Loc] do
begin
Name:='';
ArrivalTime:=-1;
ServiceTime:=-1;
end;
end;
(***************************[Fist Come First Served]**************************)
Procedure Tform1.FCFS;
var
Sum,X,U,V,Y,I:Integer;
TqTs:Real;
M:String;
begin
Memo1.Lines.Add(' ');
Memo1.Lines.Add('FCFS:');
M:='Process Arrival Service Finished Tq Tq/Ts';
Memo1.Lines.Add(M);
M:='';
Memo1.Lines.Add('-----------------------------------------------------------------');
X:=(Origin.X)+2;
Y:=(Origin.Y)+2;
U:=35;
Self.SortQueue;
X:= X+ (ReadyQ[0].ArrivalTime * 20);
With Image1.Canvas do
begin
TextOut(X,1,IntToStr(ReadyQ[0].ArrivalTime));
For I:=Low(ReadyQ) To High(ReadyQ) do
begin
Pen.Width:=1; Pen.Color:= $00FF3620 ; Brush.Color:=$00FF9D93; Brush.Style:=bsSolid;
V:=X+(ReadyQ[I].ServiceTime*20);
Rectangle(X,Y,V,U);
Brush.Color:=clWhite;Brush.Style:=bsClear;
TextOut(1,Y,ReadyQ[I].Name);
TextOut(V,1,IntToStr(V div 20));
ReadyQ[i].FinishTime:=V div 20;
ReadyQ[i].Tq:=(ReadyQ[I].FinishTime)-(ReadyQ[I].ArrivalTime);
ReadyQ[i].TqDivTs:= (ReadyQ[i].Tq / ReadyQ[i].ServiceTime);
ReadyQ[i].TimeLeft:=0;
IF (V div 20) >= (ReadyQ[I+1].ArrivalTime) Then X:=V
Else
begin
X:=18 + (ReadyQ[I+1].ArrivalTime * 20);
TextOut(X,1,IntToStr(X div 20));
end;
Y:=U+2;
U:=U+17;
M:=M+' '+ReadyQ[i].Name + ' ' +
Format('%d',[ReadyQ[i].ArrivalTime]) + ' ' +
Format('%d',[ReadyQ[i].ServiceTime])+ ' ' +
Format('%3d',[ReadyQ[i].FinishTime])+ ' '+
Format('%2d',[ReadyQ[i].Tq]) + ' ' +
Format('%1.1f',[ReadyQ[i].TqDivTs] );
Memo1.Lines.Add(M);
M:='';
DeleteElementFromReadyQ(I);
end;
end;
Sum:=0;
For I:=Low(ReadyQ) To High(ReadyQ) Do Sum := Sum + ReadyQ[I].TQ ;
Memo1.Lines.Add('Average(Tq)= ' + Format('%1.2f',[sum/Max]) );
TqTs:=0;
For I:=Low(ReadyQ) To High(ReadyQ) Do TqTs := TqTs + ReadyQ[I].TqDivTs;
Memo1.Lines.Add('Average(Tq/Ts)= ' + Format('%1.2f',[TqTs/Max]));
end;
(****************************[Shortest Process Next]**************************)
Procedure Tform1.SPN;
var
Job,Sum,X,Y,U,V,min,J,I,K:Integer;
P:TProcess;
M:String;
TqTs:Real;
begin
Memo1.Lines.Add(' '); Memo1.Lines.Add('SPN:');
M:='Process Arrival Service Finished Tq Tq/Ts';
Memo1.Lines.Add(M); M:=''; Memo1.Lines.Add('-----------------------------------------------------------------');
X:=Origin.X + 2;
Y:=Origin.Y + 2;
U:=35;
Self.SortQueue;
I:=Low(ReadyQ);
P:= ReadyQ[I];
X := X + ( P.ArrivalTime * 20 );
Job:=Max;
Image1.Canvas.Textout(X,1,IntToStr(P.ArrivalTime));
With Image1.Canvas do
While Job > 0 do
begin
Pen.Width:=1; Pen.Color:=clGreen; Brush.Color:=clLime; Brush.Style:=bsSolid;
V:=X+(P.ServiceTime*20);
Rectangle(X,Y,V,U);
Brush.Color:=clWhite;Brush.Style:=bsClear;
TextOut(1,Y,P.Name);
TextOut(V,1,IntToStr(V div 20));
ReadyQ[I].TimeLeft:=0;
ReadyQ[I].FinishTime:= (V div 20);
ReadyQ[I].Tq:= (ReadyQ[I].FinishTime)-(ReadyQ[I].ArrivalTime);
ReadyQ[I].TqDivTs:= (ReadyQ[I].Tq / ReadyQ[I].ServiceTime);
Y:=U+2;
Inc(U,17);
M:=M+' '+ReadyQ[I].Name + ' ' + Format('%2d',[ReadyQ[I].ArrivalTime]) + ' ' +
Format('%d',[ReadyQ[I].ServiceTime])+ ' ' + Format('%3d',[ReadyQ[I].FinishTime])+ ' '+
Format('%2d',[ReadyQ[I].Tq]) + ' ' + Format('%1.1f',[ReadyQ[I].TqDivTs] );
Memo1.Lines.Add(M);
M:='';
DeleteElementFromReadyQ(I);
Dec(Job,1);
K:=(-1);
Min:=(9000);
For J:=Low(ReadyQ) To High(ReadyQ) do
begin
If (ReadyQ[J].ArrivalTime <= (V div 20))And(ReadyQ[J].ServiceTime <> -1) Then
If (ReadyQ[J].ServiceTime <= Min)Then
begin
Min:=ReadyQ[J].ServiceTime;
K:=J;
end;
end;
If (K <> -1) Then // If we found anything...
begin
I:=K;
P:=ReadyQ[I];
end
Else // We didn't find anything
begin
For J:=Low(ReadyQ) To High(ReadyQ) do // find 1st undeleted process...
If (ReadyQ[J].ServiceTime <> -1 ) Then
begin
I:=J;
P:=ReadyQ[I];
Break;
end;
end;
If (V div 20) >= (P.ArrivalTime) Then X:=V // the same origin
Else
begin // make gap ( blank space )
X:= (Origin.X+2)+(P.ArrivalTime*20);
TextOut(X,1,IntToStr(X div 20));
end;
end;
Sum:=0;
For I:=Low(ReadyQ) To High(ReadyQ) Do Sum:=Sum+(ReadyQ[I].Tq);
Memo1.Lines.Add('Average(Tq)= ' + Format('%1.2f',[Sum/Max]) );
TqTs:=0;
For I:=Low(ReadyQ) To High(ReadyQ) Do TqTs:=TqTs+(ReadyQ[I].TqDivTs);
Memo1.Lines.Add('Average(Tq/Ts)= ' + Format('%1.2f',[TqTs/Max]));
end;
(*****************************[ HRRN ]*****************************)
Procedure TForm1.HRRN;
var
Job,Sum,X,Y,U,V,J,I,K : Integer;
P : TProcess;
M : String;
TqTs,Rate,Maximum : Real;
begin
Memo1.Lines.Add(' '); Memo1.Lines.Add('HRRN:');
M:='Process Arrival Service Finished Tq Tq/Ts';
Memo1.Lines.Add(M); M:=''; Memo1.Lines.Add('-----------------------------------------------------------------');
X:=Origin.X + 2;
Y:=Origin.Y + 2;
U:=35;
Self.SortQueue;
I:=Low(ReadyQ);
P:= ReadyQ[I];
X := X + ( P.ArrivalTime * 20 );
Job:=Max;
Image1.Canvas.Textout(X,1,IntToStr(P.ArrivalTime));
With Image1.Canvas do
While Job > 0 do
begin
Pen.Width:=1; Pen.Color:=$005098A5; Brush.Color:=$00A4CBD2; Brush.Style:=bsSolid;
V:=X+(P.ServiceTime*20);
Rectangle(X,Y,V,U);
Brush.Color:=clWhite;Brush.Style:=bsClear;
TextOut(1,Y,P.Name);
P.FinishTime:=(V div 20) ;
TextOut(V,1,IntToStr(P.FinishTime));
ReadyQ[I].TimeLeft:=0;
ReadyQ[I].FinishTime:= (P.FinishTime);
ReadyQ[I].Tq:= (ReadyQ[I].FinishTime)-(ReadyQ[I].ArrivalTime);
ReadyQ[I].TqDivTs:= (ReadyQ[I].Tq / ReadyQ[I].ServiceTime);
Y:=U+2;
Inc(U,17);
M:=M+' '+ReadyQ[I].Name + ' ' + Format('%2d',[ReadyQ[I].ArrivalTime]) + ' ' +
Format('%d',[ReadyQ[I].ServiceTime])+ ' ' + Format('%3d',[ReadyQ[I].FinishTime])+ ' '+
Format('%2d',[ReadyQ[I].Tq]) + ' ' + Format('%1.1f',[ReadyQ[I].TqDivTs] );
Memo1.Lines.Add(M);
M:='';
DeleteElementFromReadyQ(I);
Dec(Job,1);
K:=-1;
Maximum:=0;
For J:=Low(ReadyQ) To High(ReadyQ) do
begin
If (ReadyQ[J].ArrivalTime <= (P.FinishTime)) And (ReadyQ[J].ServiceTime <> -1) Then
begin
Rate:=( (P.FinishTime - ReadyQ[j].ArrivalTime) + (ReadyQ[j].ServiceTime)) / (ReadyQ[j].ServiceTime); // Max((w+s)/s)
If Rate>Maximum Then
begin
Maximum:=Rate;
K:=J;
end;
end;
end;
If (K <> -1) Then // If we found something...
begin
I:=K;
P:=ReadyQ[I];
end
Else // We didn't find
begin
For J:=Low(ReadyQ) To High(ReadyQ) do // find 1st undeleted process...
If (ReadyQ[J].ServiceTime <> -1 ) Then
begin
I:=J;
P:=ReadyQ[I];
Break;
end;
end;
If (V div 20) >= (P.ArrivalTime) Then X:=V // the same origin
Else
begin // make gap ( blank space )
X:= (Origin.X+2)+(P.ArrivalTime*20);
TextOut(X,1,IntToStr(X div 20));
end;
end;
Sum:=0;
For I:=Low(ReadyQ) To High(ReadyQ) Do Sum:=Sum+(ReadyQ[I].Tq);
Memo1.Lines.Add('Average(Tq)= ' + Format('%1.2f',[Sum/Max]) );
TqTs:=0;
For I:=Low(ReadyQ) To High(ReadyQ) Do TqTs:=TqTs+(ReadyQ[I].TqDivTs);
Memo1.Lines.Add('Average(Tq/Ts)= ' + Format('%1.2f',[TqTs/Max]));
end;
(***************************************************************************)
end.
|
|
|
|
|
Milad.Biroonvand wrote: If the code is complete?
I'm sorry, but that's a bit much too translate - you'll need someone who speaks either language. Most constructs, like the SaveDialog, are available in both languages. To give you an idea of what needs be done;
Procedure TForm1.btnSavePictureClick(Sender: TObject);
begin
If SaveDialog1.Execute then
Image1.Picture.SaveToFile(SaveDialog1.FileName);
end;
private void Form1_btnSavePictureClick(Object sender, EventArgs e)
{
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
pictureBox1.Image.Save(saveFileDialog1.FileName);
}
Look like old relatives, don't they?
We'll be available for further help if you get stuck on making the translation.
I are Troll
|
|
|
|
|
|
I'm new to programming and VB so just for fun I'm trying to build a music player app. I want to have it set up so you can choose your own background from picture files on your computer. The code I'm using to save the registry file is:
Private Sub MusicPlayerForm_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
My.Computer.Registry.SetValue _
(m_strKeyName, "BackgroundImage", Me.BackgroundImage)
End Sub
The file is saved and I can see it when I use the regedit. The problem I'm having is loading the file. Currently I have:
Private Sub MusicPlayerForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Timer1.Start()
LoadDefault()
Me.BackgroundImage = m_objBackgroundImage
End Sub
Public Sub LoadDefault()
If CStr(My.Computer.Registry.GetValue(m_strKeyName, "BackgroundImage", _
Me.BackgroundImage)) = "" Then
Exit Sub
Else
m_objBackgroundImage = Image.FromFile(My.Computer.Registry.GetValue _
(m_strKeyName, "BackgroundImage", Me.BackgroundImage))
End If
End Sub
The error message I get is 'System.IO.FileNotFound Exception'. I know it's probably something simple that I overlooked, but can anyone help me?
THANKS!!!
|
|
|
|
|
Garrett Crawford wrote: System.IO.FileNotFound Exception
That should give you a clue; you are trying to load a file and either the path is mis-spelled or the file itself has been moved or deleted. Check the value of the registry key to ensure it is correct.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
You really shouldn't be saving an image to the registry. The registry is bloated enough without doing something like this.
But, what you've have to do is convert the image to a byte array. Create a MemoryStream object, then save the image to the MemoryStream. Create a byte array the length of the memorystream, then read the memory stream into the array. There's an example here[^].
Loading the image from the registry is the reverse of this.
|
|
|
|
|
Is there another way to save a user selected background image besides the registry?
|
|
|
|
|
Save it to a file??
The Bitmap object has a Save method you can use.
|
|
|
|
|
Just very new and can't get it to show up when I reload the form. But thanks for your help. For some reason when I try to save it to the registry I don't think it's reading the registry value.
|
|
|
|
|
Bitmap's constructor also takes a filename when you want to load it back in.
Dim myImage As New Bitmap( filepath )
|
|
|
|
|
Thanks for the help
|
|
|
|
|
We use SourceSafe at work, and today, I added a VB.Net project (converted from C#) to the repository. I then tried to checkout a file to work on it. SourceSafe shows it's checked out, and on the hard drive, the file shows that it's NOT read-only. When I tried to open the file in the IDE, however, it still shows as being read-only, and I can't edit it.
I've tried a number of variations on that usage theme, but I can't edit the file. When I try to do the same thing in the old C# project, everything works as expected.
I do NOT have the IDE tied into SourceSafe, and I'm not at all eager to turn that "feature" on in the IDE.
Does anyone know why this is happening, and how to fix it?
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Because you're not using the integrated tool, you may just have to close the solution, shut down the IDE and then reopen everything again. I've encountered similar behavior when doing this after checking out from subversion. I think the IDE is trying to be "smart" on file permissions.
I wasn't, now I am, then I won't be anymore.
|
|
|
|
|
Try undo checkout and then checkout once again.
|
|
|
|
|
As someone else mentioned, you probably need to exit and restart the IDE. VS tends to cache file attributes rather than re-check them every time you want to do something.
You might also want to check that the working folder for the project in SourceSafe is the same folder from which you are opening the file in the IDE.
John Simmons / outlaw programmer wrote: I do NOT have the IDE tied into SourceSafe, and I'm not at all eager to turn that "feature" on in the IDE.
I'll probably get flamed for this, but why not?
SourceSafe integrates perfectly well with Visual Studio, as long as you use the latest version of SourceSafe (VSS 2005) with VS2008 and later. Earlier versions still work, but are missing some bug fixes that the later versions of Visual Studio need.
SourceSafe isn't the best source control solution in the world, but it isn't the complete "dog's arse" (as our friends from Oz would put it) that everyone says it is.
Software Zen: delete this;
|
|
|
|
|
The problem is that you converted your project to VB.NET from c#. If you convert it back... everything will work fine
I kid
|
|
|
|
|
Get rid of Source-Safe and move to Subversion. You will never get the type of issues you are describing...
Besides, Subversion is free...
Steve Naidamast
Black Falcon Software, Inc.
blackfalconsoftware@ix.netcom.com
|
|
|
|
|
Source-Safe is anything but safe. Make sure your data base never gets too big, make sure you never run out of disk space, etc. Actually you should probably memorize these Best Practices.
To me is sounds like running with Scissors would be safer...
|
|
|
|
|
Oh my, I thought it couldn't get worse when you said you had to convert C# to VB...
Now VB + SourceSafe... Oh my, you are F*****!!
Did you start looking for a new job yet?
|
|
|
|
|
Well, that was a big help. Not!
|
|
|
|
|