Board logo

標題: 兩條 C# 問題 , plx help [打印本頁]

作者: sckds    時間: 2008-10-21 19:03     標題: 兩條 C# 問題 , plx help

1.  遇到 error  就重新黎過 (即係好似restart咁)
2. textbox 一定要入 number

HOW TO DO IT ?

thx
作者: ioptional    時間: 2008-10-21 19:08

1.
public xxx(){
try {

}
catch {
xxx()
}
}
咁樣得唔得?

2. textbox.Numeric
bool, Check 係唔係數字
作者: AlexAu    時間: 2008-10-21 19:16

1 用LOOPING都得
作者: sckds    時間: 2008-10-21 19:29

原帖由 ioptional 於 2008-10-21 07:08 PM 發表
1.
public xxx(){
try {

}
catch {
xxx()
}
}
咁樣得唔得?

2. textbox.Numeric
bool, Check 係唔係數字


1. 就係唔想咁
我想放係if 入面
if (statement){
show error;
reload;
}

2. 請問 code 點寫 ?

thx~
作者: rocketdive04    時間: 2008-10-21 19:30

原帖由 sckds 於 2008-10-21 19:03 發表
1.  遇到 error  就重新黎過 (即係好似restart咁)
2. textbox 一定要入 number

HOW TO DO IT ?

thx


guess what is this for

if (e.KeyChar != 8 && !Char.IsDigit(e.KeyChar))
            {
                e.Handled = true;
            }
作者: AlexAu    時間: 2008-10-21 19:36

原帖由 sckds 於 2008-10-21 19:29 發表


1. 就係唔想咁
我想放係if 入面
if (statement){
show error;
reload;
}

2. 請問 code 點寫 ?

thx~


1.
public xxx(){
try {

}
catch {
show error;
xxx()
}
}
咁樣呢
作者: rocketdive04    時間: 2008-10-21 19:39

原帖由 AlexAu 於 2008-10-21 19:36 發表

1.
public xxx(){
try {

}
catch {
show error;
xxx()
}
}
咁樣呢


yes

try
{
}
catch (Exception e)
{
MessageBox.Show (e.Message)
}
作者: sckds    時間: 2008-10-21 19:40

原帖由 AlexAu 於 2008-10-21 07:36 PM 發表


1.
public xxx(){
try {

}
catch {
show error;
xxx()
}
}
咁樣呢


我唔想用try........
我想放係if 入面
if (statement){
show error;
reload;
}
作者: sckds    時間: 2008-10-21 19:41

原帖由 rocketdive04 於 2008-10-21 07:30 PM 發表


guess what is this for

if (e.KeyChar != 8 && !Char.IsDigit(e.KeyChar))
            {
                e.Handled = true;
            }


ching , 個 KeyChar 點彈出黎架 ?

小弟初學 , 問左低能野有怪莫怪
作者: rocketdive04    時間: 2008-10-21 19:42

原帖由 sckds 於 2008-10-21 19:40 發表


我唔想用try........
我想放係if 入面
if (statement){
show error;
reload;
}


what kind of error you want to show?
作者: rocketdive04    時間: 2008-10-21 19:44

原帖由 sckds 於 2008-10-21 19:41 發表


ching , 個 KeyChar 點彈出黎架 ?

小弟初學 , 問左低能野有怪莫怪


you need to select what event of the textbox you want to happen ( keypress is your key)
put this code to this event
作者: thinkpanda    時間: 2008-10-21 19:46

原帖由 sckds 於 2008-10-21 19:29 發表


1. 就係唔想咁
我想放係if 入面
if (statement){
show error;
reload;
}

2. 請問 code 點寫 ?

thx~


1. Why?
作者: sckds    時間: 2008-10-21 19:50

原帖由 rocketdive04 於 2008-10-21 07:42 PM 發表


what kind of error you want to show?


specific exception error
作者: sckds    時間: 2008-10-21 19:51

原帖由 rocketdive04 於 2008-10-21 07:44 PM 發表


you need to select what event of the textbox you want to happen ( keypress is your key)
put this code to this event


得左

thx so much

[ 本帖最後由 sckds 於 2008-10-21 19:54 編輯 ]
作者: sckds    時間: 2008-10-21 19:51

原帖由 thinkpanda 於 2008-10-21 07:46 PM 發表


1. Why?


coz exception 出既 error 唔 specific

so use if statement

but show jor error 後冇 "後著" , 會hang左係度

[ 本帖最後由 sckds 於 2008-10-21 20:10 編輯 ]
作者: chiefumpire    時間: 2008-10-21 21:44

  1. try{
  2.    if(statement){
  3.       throw new Exception("ABC");
  4.    }
  5. }catch (Exception e)
  6. {
  7.   if(e.Message == "ABC") {
  8.     show();
  9.     reload();
  10.   }
  11. }
複製代碼
how about this ?
or you write a new kind of Exception

[ 本帖最後由 chiefumpire 於 2008-10-21 21:55 編輯 ]
作者: 大家好    時間: 2008-10-26 04:54

係咪 用 do ,While好點?

While(條件)
{
show error;
if (error); // While Looping
if (no error); // while (條件 false ,out while

}

do
{
一樣,如(條件為false,出 do Looping

While(條件);

只供參考....................!!!
作者: hoshino88    時間: 2008-10-27 00:51

唔用 try catch block 點知有error
除非你預計到會出d logic  既error 啦
if (customer <> male && customer <> female )
{ return error; }
否則其他error 要大d effort 先搵到喎





歡迎光臨 電腦領域 HKEPC Hardware (https://www.hkepc.com/forum/) Powered by Discuz! 7.2