简单数组 [英] Simple Arrays

查看:65
本文介绍了简单数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当天的第2个帖子!我刚刚在大学学习阵列,并遇到了问题。我有5个文本框用于输入数字,一个命令按钮用于将

数字添加到数组中,还有一个命令按钮,用于显示5个标签中的数组内容

。我的程序运行正常。问题是我使用一个简单的If

语句来检查任何空框。我必须削减IF语句并使用

a For Each ... Next语句检查空文本框但我正在努力

来应用这种方法。这本书还告诉我声明一个变量''Dim

MyTextBox As TextBox'',我之前从未遇到过这种变量类型。

我会发布我的工作版本的程序,希望有人可以帮助

我出去。


选项明确


昏暗数字(1到5)作为整数


私有子cmdAddToArray_Click()

昏暗索引为整数

If(txtNumbers(1 ).Text ="")或(txtNumbers(2).Text ="")或

(txtNumbers(3).Text ="")或(txtNumbers(4) ).Text ="")或

(txtNumbers(5).Text ="")然后

MsgBox"你还没输入5个数字"

Else

索引= 1到5

数字(索引)= txtNumbers(索引)。文本

下一个索引

结束如果

结束子


私有子cmdDisplayArray_Click()

昏暗指数为整数

索引= 1至5
lblNumbers(指数).Caption =数字(指数)

下一个指数

结束子

解决方案

脱离我的脑海......


dim ctl as textbox


for each ctl in me <如果typeof ctl是textbox那么
那么


如果len(ctl.text)= 0那么

msgbox" ''输入5个数字''的哪一部分你不理解?"

ctl.setfocus

退出

结束如果

结束如果

next ctl


-


Randy Birch

MVP Visual Basic
http://www.mvps。 org / vbnet /

请只回复新闻组,以便所有人都能受益。

Roy Riddex < RO ************** @ blueyonder.co.uk>在留言中写道

新闻:f6 ******************* @ news-binary.blueyonder.co.uk ...

:当天的第2个帖子!我刚刚在大学学习阵列,并且已经满足了


:一个问题。我有5个文本框用于输入数字,一个命令按钮用于添加



:数字到数组,以及一个显示数组的命令按钮

内容

:5个标签。我的程序运行正常。问题是我使用一个简单的If

:语句检查是否有空框。我要削减IF语句和

使用

:a For Each ... Next语句检查空文本框但是我是

苦苦挣扎

:应用此方法。这本书还告诉我声明一个变量''Dim

:MyTextBox As TextBox'',我之前从未遇到过这种变量类型。

:我'发布我的工作版本的程序,希望有人可以帮助

:我出去。



:选项明确



:昏暗的数字(1到5)作为整数



:私有子cmdAddToArray_Click()

:昏暗指数为整数

:if(txtNumbers(1).Text ="")或(txtNumbers(2).Text ="")或

:(txtNumbers(3).Text ="")或(txtNumbers(4).Text ="")或

:(txtNumbers(5).Text ="")然后

:MsgBox你还没有输入5个数字

:否则

:索引= 1到5

:数字(指数)= txtNumbers(指数)。文字

:下一个指数

:结束如果

:结束Sub



:Private Sub cmdDisplayArray_Click()

:Dim Index As Integer

:索引= 1到5

:lblNumbers (索引).Caption =数字(索引)

:下一个索引

:结束次级





当然,由于ctl被声明为TextBox,所以没有其他对象真的应该在循环中枚举
,所以行''如果typeof ctl是textbox然后''可能

真的被删除了。但是,如果你枚举所有对象并且声明ctl为对象,那么就有必要。

Mauro

" Randy Birch" < RG ************ @ mvps.org>在消息中写道

新闻:qv ******************* @ news02.bloor.is.net.cab le.rogers.com .. 。

脱离我的脑海......

dim ctl as textbox

对我来说每个ctl

>如果typeof ctl是文本框那么

如果len(ctl.text)= 0那么
msgbox'输入5个数字'的哪一部分''你不明白吗? ;
ctl.setfocus
退出
结束如果
结束如果
下一个ctl



Randy Birch
MVP Visual Basic
http://www.mvps。 org / vbnet /
请回复新闻组,以便所有人都能受益。

Roy Riddex < RO ************** @ blueyonder.co.uk>在消息中写道
新闻:f6 ******************* @ news-binary.blueyonder.co.uk ...
:第二篇文章那天!我刚刚在大学学习阵列并且遇到了
:一个问题。我有5个文本框用于数字输入,一个命令按钮用于添加
:数字到数组,以及一个显示数组的命令按钮
内容
:5个标签。我的程序运行正常。问题是我使用一个简单的
If:语句来检查任何空框。我要削减IF声明并使用
:For Each ... Next声明检查空文本框但是我很难
:到应用此方法。这本书还告诉我声明一个变量''Dim
:MyTextBox As TextBox'',我之前从未遇到过这个变量类型。
:我会发布我的工作版本的程序,希望有人可以
帮助:我出去。

:选项明确

:昏暗的数字(1到5)作为整数

:Private Sub cmdAddToArray_Click()
:Dim Index As Integer
:If(txtNumbers(1).Text ="")或(txtNumbers(2).Text ="" ;)或
:( txtNumbers(3).Text ="")或(txtNumbers(4).Text ="")或
:( txtNumbers(5).Text =" ;然后
:MsgBox你没有输入5个数字
:其他
:索引= 1到5
:数字(索引)= txtNumbers(索引) )。文档
:下一个索引
:结束如果
:结束Sub

:Private Sub cmdDisplayArray_Click()
:Dim Index As Integer
:对于Index = 1到5 :lblNumbers(Index).Caption = Numbers(Index)
:下一个索引
:End Sub



"莫罗" < MB ****** @ hotmail.com>在消息新闻中写道:< _8rCb.681270


2nd post of the day! I''m just learning about Arrays at College and have met
a problem. I have 5 text boxes for number input, a command button to add the
numbers to the array, and a command button which displays the array contents
in 5 labels. My program works fine. The problem is that I use a simple If
statement to check for any empty boxes. I''ve to cut the IF statement and use
a For Each...Next statement to check for empty text boxes but I''m struggling
to apply this method. The book also tells me to declare a variable ''Dim
MyTextBox As TextBox'', I''ve never came across this variable type before.
I''ll post my working version of the program and hopefully someone can help
me out.

Option Explicit

Dim Numbers(1 To 5) As Integer

Private Sub cmdAddToArray_Click()
Dim Index As Integer
If (txtNumbers(1).Text = "") Or (txtNumbers(2).Text = "") Or
(txtNumbers(3).Text = "") Or (txtNumbers(4).Text = "") Or
(txtNumbers(5).Text = "") Then
MsgBox "You have not entered 5 numbers"
Else
For Index = 1 To 5
Numbers(Index) = txtNumbers(Index).Text
Next Index
End If
End Sub

Private Sub cmdDisplayArray_Click()
Dim Index As Integer
For Index = 1 To 5
lblNumbers(Index).Caption = Numbers(Index)
Next Index
End Sub

解决方案

off the top of my head ...

dim ctl as textbox

for each ctl in me

if typeof ctl is textbox then

if len(ctl.text) = 0 then
msgbox "what part of ''enter 5 numbers'' don''t you understand?"
ctl.setfocus
exit for
end if
end if
next ctl

--

Randy Birch
MVP Visual Basic
http://www.mvps.org/vbnet/
Please respond only to the newsgroups so all can benefit.
"Roy Riddex" <ro**************@blueyonder.co.uk> wrote in message
news:f6*******************@news-binary.blueyonder.co.uk...
: 2nd post of the day! I''m just learning about Arrays at College and have
met
: a problem. I have 5 text boxes for number input, a command button to add
the
: numbers to the array, and a command button which displays the array
contents
: in 5 labels. My program works fine. The problem is that I use a simple If
: statement to check for any empty boxes. I''ve to cut the IF statement and
use
: a For Each...Next statement to check for empty text boxes but I''m
struggling
: to apply this method. The book also tells me to declare a variable ''Dim
: MyTextBox As TextBox'', I''ve never came across this variable type before.
: I''ll post my working version of the program and hopefully someone can help
: me out.
:
: Option Explicit
:
: Dim Numbers(1 To 5) As Integer
:
: Private Sub cmdAddToArray_Click()
: Dim Index As Integer
: If (txtNumbers(1).Text = "") Or (txtNumbers(2).Text = "") Or
: (txtNumbers(3).Text = "") Or (txtNumbers(4).Text = "") Or
: (txtNumbers(5).Text = "") Then
: MsgBox "You have not entered 5 numbers"
: Else
: For Index = 1 To 5
: Numbers(Index) = txtNumbers(Index).Text
: Next Index
: End If
: End Sub
:
: Private Sub cmdDisplayArray_Click()
: Dim Index As Integer
: For Index = 1 To 5
: lblNumbers(Index).Caption = Numbers(Index)
: Next Index
: End Sub
:
:


Of course, since ctl was declared as TextBox, no other object really should
be enumerated in the loop, so the line ''if typeof ctl is textbox then'' could
really be dropped. However, if you were enumerating all objects and
declared ctl as object, then it would be necessary.
Mauro
"Randy Birch" <rg************@mvps.org> wrote in message
news:qv*******************@news02.bloor.is.net.cab le.rogers.com...

off the top of my head ...

dim ctl as textbox

for each ctl in me

if typeof ctl is textbox then

if len(ctl.text) = 0 then
msgbox "what part of ''enter 5 numbers'' don''t you understand?"
ctl.setfocus
exit for
end if
end if
next ctl

--

Randy Birch
MVP Visual Basic
http://www.mvps.org/vbnet/
Please respond only to the newsgroups so all can benefit.
"Roy Riddex" <ro**************@blueyonder.co.uk> wrote in message
news:f6*******************@news-binary.blueyonder.co.uk...
: 2nd post of the day! I''m just learning about Arrays at College and have
met
: a problem. I have 5 text boxes for number input, a command button to add
the
: numbers to the array, and a command button which displays the array
contents
: in 5 labels. My program works fine. The problem is that I use a simple If : statement to check for any empty boxes. I''ve to cut the IF statement and
use
: a For Each...Next statement to check for empty text boxes but I''m
struggling
: to apply this method. The book also tells me to declare a variable ''Dim
: MyTextBox As TextBox'', I''ve never came across this variable type before.
: I''ll post my working version of the program and hopefully someone can help : me out.
:
: Option Explicit
:
: Dim Numbers(1 To 5) As Integer
:
: Private Sub cmdAddToArray_Click()
: Dim Index As Integer
: If (txtNumbers(1).Text = "") Or (txtNumbers(2).Text = "") Or
: (txtNumbers(3).Text = "") Or (txtNumbers(4).Text = "") Or
: (txtNumbers(5).Text = "") Then
: MsgBox "You have not entered 5 numbers"
: Else
: For Index = 1 To 5
: Numbers(Index) = txtNumbers(Index).Text
: Next Index
: End If
: End Sub
:
: Private Sub cmdDisplayArray_Click()
: Dim Index As Integer
: For Index = 1 To 5
: lblNumbers(Index).Caption = Numbers(Index)
: Next Index
: End Sub
:
:



"Mauro" <mb******@hotmail.com> wrote in message news:<_8rCb.681270


这篇关于简单数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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