![]() |
請教有關C++ Builder的幾個問題
1.我用Edit來顯示計時,然後點Edit時時間會暫停,
然後可以改時間,假如輸入值不在範圍內的話, 會跳出錯誤訊息視窗(ShowMessage), 但是當Edit是空白時他就會出現錯誤 ![]() 請問要怎麼把它改成一樣會出現是在我寫的錯誤訊息? //--------------------------------------------------------------------------- #include <vcl.h> #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; int a=0; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::Timer1Timer(TObject *Sender) { a++; Edit1->Text=a; } //--------------------------------------------------------------------------- void __fastcall TForm1::Edit1Change(TObject *Sender) { a=StrToInt(Edit1->Text); while(a<0||a>100){ ShowMessage("輸入錯誤值"); Edit1->Text=InputBox("請輸入","0~100","0"); a=StrToInt(Edit1->Text); } Timer1->Enabled=true; } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { Timer1->Enabled=true; } //--------------------------------------------------------------------------- void __fastcall TForm1::Edit1Enter(TObject *Sender) { Timer1->Enabled=false; } //--------------------------------------------------------------------------- 2.我做一個表單的程式,年月日那邊我是用下拉式選單的方式 請問要怎麼用前面選擇的資料來決定號面會出現的資料? 例如輸入1月,後面日期的選項就是1~31號,如果是4月就是1~30號. 我那樣寫日期沒有東西請問要怎麼改? void __fastcall TForm1::FormCreate(TObject *Sender) { int Year=1900,Month=1,Day=1,Y,M; for(int i=0; i <=198 ; i++) ComboBox3->Items->Add(i+1900); for(int j = 0; j <=11 ; j++) ComboBox4->Items->Add(j+1); if(ComboBox4->Text==1){ for(Day = 0; Day <=30 ; Day++) ComboBox5->Items->Add(Day); } else if(ComboBox4->Text==2){ for(Day = 0; Day <=29 ; Day++) ComboBox5->Items->Add(Day); } } |
第一個問題應該可以家一個判斷式吧
if(Edit1->Text=="") Edit1->Text="0"; 因為StrToInt無法將""轉換為0 <參考> |
第二個問題
您可以利用TComboBox的Change或Click事件 在依照ItemIndex判斷使用者選擇哪個月份 <參考> |
所有時間均為台北時間。現在的時間是 09:08 AM。 |
Powered by vBulletin® 版本 3.6.8
版權所有 ©2000 - 2025, Jelsoft Enterprises Ltd.
『服務條款』
* 有問題不知道該怎麼解決嗎?請聯絡本站的系統管理員 *