Delphi代碼如下:
procereTForm1.Button1Click(Sender:TObject);
var
購物總價:Integer;
折扣:Extended;
begin
購物總價:=StrToInt(Edit1.Text);
if購物總價<250then
begin
折扣:=0;
end
elseif購物總價<500then
begin
折扣:=0.05;
end
elseif購物總價<1000then
begin
折扣:=0.075;
end
elseif購物總價<2000then
begin
折扣:=0.1;
end
{
此段的折扣是多少?
elseif購物總價<3000then
begin
折扣:=0.05;
end
}
elseif購物總價>=3000then
begin
折扣:=0.15;
end;
ShowMessage('您享受的折扣是:'+FloatToStr(折扣)
+'原價:'+IntToStr(購物總價)
+'折後總價:'+FloatToStr(購物總價*(1-折扣)));
end;
2. 在VB中,做一個小程序,請告訴我代碼
這一種是當你的滑鼠想去點擊按鈕1時就會隨機跑動,不讓人可以點到。
Dim CMD1 As Boolean'設置一個全局布爾變數
Private Sub Command1_Click()
CMD1 = True
End Sub
Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If CMD1 = True Then
X = Rnd * (Form1.ScaleWidth - Command1.Width)
Y = Rnd * (Form1.ScaleHeight - Command1.Height)
Command1.Move X, Y
End If
End Sub
Private Sub Command2_Click()
CMD1 = False
End Sub
這一種是你點了按鈕1後,這個接鈕1就不停的去跑動讓人很難點到。
Private Sub Form_Load()
Timer1.Interval = 100
Timer1.Enabled = False
End Sub
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub Command2_Click()
Timer1.Enabled = False
End Sub
Private Sub Timer1_Timer()
Command1.Top = Me.ScaleHeight * Rnd
Command1.Left = Me.ScaleWidth * Rnd
End Sub
這兩種方法的區別在於點擊按鈕1後,
第一種是你的滑鼠是永遠都點不到按鈕1。
第二種是你有可能會點中。