关于一些良好做法的问题 [英] question about some good practises

查看:112
本文介绍了关于一些良好做法的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我第一次编译了一个应用程序但没有错误,但是跟随

警告:

1)变量声明withoit''AS'':

Dim def()

2)变量''myvar''在赋值之前使用:

Dim myvar

......

如果wk = 1那么

myvar =" yes"

ElseIf wk = 2然后

myvar =" no"

结束如果

...... 。

3)未使用的变量:myvar2

警告3)很容易解决:删除它。

警告1):重要的是指定(例如dim def()为字符串)?可以这个

导致运行时错误吗?

警告2):这是一个问题吗?我可以这样离开吗(我肯定''myvar''

会得到一个值,所以没有运行时错误的风险......)


感谢您的建议

Bob

解决方案

" Bob" < sd @qscsqschrieb:


我第一次编译了一个应用程序而没有任何错误但是跟随

警告:

1)变量声明withoit''AS'':

Dim def()

2)变量''myvar''在分配之前使用一个值:

Dim myvar

.....

如果wk = 1那么

myvar =" ;是"

ElseIf wk = 2然后

myvar =" no"

结束如果

.. ....

3)未使用的变量:myvar2


警告3)很容易解决:删除它。



是。


警告1):指定是否重要(例如dim def()为串)?可以

这会导致运行时错误吗?



最好指定数组元素的类型,因为它将使编译器能够执行类型检查




\\\

Dim Numbers(...)As Integer

Numbers(0)= Me.TextBox1。文本

///

如果启用了''Option Strict'',
....将引发编译时错误。
< blockquote class =post_quotes>
警告2):这是一个问题吗?我可以这样离开吗(我肯定''myvar''

会得到一个值,所以没有运行时错误的风险...)



这个警告在IMO中相当无用,因为VB隐式地将变量初始化为
指定的值。我通常会禁用此警告。


-

MS Herfried K. Wagner

MVP< URL:http:// dotnet.mvps.org/>

VB< URL:http://dotnet.mvps.org/dotnet/faqs/>


鲍勃,


除了Herfrieds的回答,


很好地调查这些警告而不是解决它们初始化

有些愚蠢的价值。


在你需要的级别内使用值,并且不要在

一个程序顶部的旧cobol时间(这个Cobol方法部分

也由BASIC人员编写)。


Set选项显式为On并对您的程序进行编码。


Cor


" Bob" < sd @ qscsqschreef in bericht

news:%2 **************** @ TK2MSFTNGP06.phx.gbl ...





我第一次编译了一个应用程序但没有错误,但是跟随

警告:

1)变量声明withoit''AS'':

Dim def()

2)变量''myvar''在它之前使用被分配了一个值:

Dim myvar

.....

如果wk = 1那么

myvar =" yes"

ElseIf wk = 2然后

myvar =" no"

结束如果

......

3)未使用的变量:myvar2


警告3)很容易解决:删除它。

警告1):指定是否重要(例如将dim def()作为字符串)?这可能导致运行时错误吗?

警告2):这是一个问题吗?我可以这样离开吗(我肯定''myvar''

会得到一个值,所以没有运行时错误的风险......)


感谢您的建议

Bob



谢谢两者


Cor Ligthert [MVP]" < no ************ @ planet.nlschreef in bericht

新闻:%2 **************** @ TK2MSFTNGP05.phx.gbl ...


Bob,


除了Herfrieds的回答,


很好地研究这些警告,而不是通过初始化来解决这些警告,并且有些愚蠢的价值可以用来实现。


使用在你需要它们的级别内的值,并且不要声明它们已经完成

在程序顶部的旧cobol时间(这个Cobol方法部分是

adepted by BASIC人也是。)


将选项显式设置为On并对您的程序进行编码。


Cor


" Bob" < sd @ qscsqschreef in bericht

news:%2 **************** @ TK2MSFTNGP06.phx.gbl ...


>

我第一次编译了一个应用程序,没有任何错误,但是关于
警告:
1)变量声明withoit一个'AS'':
Dim def()
2)变量''myvar''在赋值之前使用:
Dim myvar
... ..
如果wk = 1则
myvar =" yes"
ElseIf wk = 2然后
myvar =" no"
结束如果
............................................................................................................................................................................................................. dim def()as string)?这可能导致运行时错误吗?
警告2):这是一个问题吗?我可以这样离开(我肯定''myvar''
会得到一个值,所以不存在运行时错误的风险......)

感谢您的建议<鲍勃




Hi,

I compiled an application for the first time with no errors but following
warnings:
1) variable declaration withoit an ''AS'':
Dim def()
2) variable ''myvar'' is used before it has been assigned a value:
Dim myvar
......
If wk = 1 Then
myvar = "yes"
ElseIf wk = 2 Then
myvar = "no"
End If
.......
3) unused variable: myvar2
Warning 3) is easy to solve: remove it.
Warning 1): is it important to specify (e.g. dim def() as string)? Can this
cause a run-time error?
Warning 2): is this a problem? Can i leave it like this (i''m sure ''myvar''
will get a value, so no risk of run-time error ...)

Thanks for advice
Bob

解决方案

"Bob" <sd@qscsqschrieb:

I compiled an application for the first time with no errors but following
warnings:
1) variable declaration withoit an ''AS'':
Dim def()
2) variable ''myvar'' is used before it has been assigned a value:
Dim myvar
.....
If wk = 1 Then
myvar = "yes"
ElseIf wk = 2 Then
myvar = "no"
End If
......
3) unused variable: myvar2
Warning 3) is easy to solve: remove it.

Yes.

Warning 1): is it important to specify (e.g. dim def() as string)? Can
this cause a run-time error?

It''s better to specify the type of the array elements because it will enable
the compiler to perform type checking:

\\\
Dim Numbers(...) As Integer
Numbers(0) = Me.TextBox1.Text
///

.... will raise a compile-time error if ''Option Strict'' is enabled.

Warning 2): is this a problem? Can i leave it like this (i''m sure ''myvar''
will get a value, so no risk of run-time error ...)

This warning is IMO rather useless in VB because VB initializes Variables to
specified values implicitly. I typically disable this warning.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>


Bob,

An addition to Herfrieds answer,

It is good investigate these warnings and not to solve them by intializing
with some dumb value as some like to do.

Use values inside the level you need them and don''t declare them as done in
the old cobol time in top of a program (this Cobol method is partially
adepted by BASIC people too).

Set option explicit to On and code your program like that.

Cor

"Bob" <sd@qscsqschreef in bericht
news:%2****************@TK2MSFTNGP06.phx.gbl...

Hi,

I compiled an application for the first time with no errors but following
warnings:
1) variable declaration withoit an ''AS'':
Dim def()
2) variable ''myvar'' is used before it has been assigned a value:
Dim myvar
.....
If wk = 1 Then
myvar = "yes"
ElseIf wk = 2 Then
myvar = "no"
End If
......
3) unused variable: myvar2
Warning 3) is easy to solve: remove it.
Warning 1): is it important to specify (e.g. dim def() as string)? Can
this cause a run-time error?
Warning 2): is this a problem? Can i leave it like this (i''m sure ''myvar''
will get a value, so no risk of run-time error ...)

Thanks for advice
Bob



Thanks both

"Cor Ligthert [MVP]" <no************@planet.nlschreef in bericht
news:%2****************@TK2MSFTNGP05.phx.gbl...

Bob,

An addition to Herfrieds answer,

It is good investigate these warnings and not to solve them by intializing
with some dumb value as some like to do.

Use values inside the level you need them and don''t declare them as done
in the old cobol time in top of a program (this Cobol method is partially
adepted by BASIC people too).

Set option explicit to On and code your program like that.

Cor

"Bob" <sd@qscsqschreef in bericht
news:%2****************@TK2MSFTNGP06.phx.gbl...

>Hi,

I compiled an application for the first time with no errors but following
warnings:
1) variable declaration withoit an ''AS'':
Dim def()
2) variable ''myvar'' is used before it has been assigned a value:
Dim myvar
.....
If wk = 1 Then
myvar = "yes"
ElseIf wk = 2 Then
myvar = "no"
End If
......
3) unused variable: myvar2
Warning 3) is easy to solve: remove it.
Warning 1): is it important to specify (e.g. dim def() as string)? Can
this cause a run-time error?
Warning 2): is this a problem? Can i leave it like this (i''m sure ''myvar''
will get a value, so no risk of run-time error ...)

Thanks for advice
Bob




这篇关于关于一些良好做法的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆