InPutBox的输入的是字符,怎么转成自然数
#include <Array.au3>Global $ws1,$ws2,$ws3
Global $no,$no1,$no2,$no3
Dim $ws
$no=MsgBox(4+0x40,"随机实验","请分布输入各种参数")
main ($no)
$ws=MsgBox(4+0x40,"随机实验","您输入的参数如:"&@CRLF&"从"&$ws1&"到"&$ws2&"的范围内取"&$ws3&"个随机数" _
&@CRLF&'选"是"输出答案,选"否"重新填写!')
Switch $ws
Case 6
MsgBox(0x40,"随机实验",$ws1&chr(32)&$ws2& chr(32)&$ws3)
;~ For $num=0 To $ws3-1
;~ $ws[$num]=Random($ws1,$ws2,1)
;~ Next
;~ _ArrayDisplay($ws)
Case 7
$ws=6
main($ws)
EndSwitch
;~ $ws[$ws3]=Random($ws1,$ws2,1)
;~ _ArrayDisplay($ws)
Func main($x)
Switch $x
Case 7
Exit
Case 6
$ws1=InputBox("随机实验","请输入取随机数的最小范围:",""," m10")
quit(@error)
$no1=StringIsInt($ws1)
While $no1=0
$ws1=InputBox("随机实验","对不起!"&@CRLF&"您输入的数不是整数"&@CRLF&"请重新输入随机数的最小范围:",""," m10")
quit(@error)
$no1=StringIsInt($ws1)
WEnd
$ws2=InputBox("随机实验","请输入取随机数的最大范围:",""," m10")
quit(@error)
$no2=StringIsInt($ws2)
While $no2=0
$ws2=InputBox("随机实验","对不起!"&@CRLF&"您输入的数不是整数"&@CRLF&"请重新输入随机数的最大范围:",""," m10")
quit(@error)
$no2=StringIsInt($ws2)
WEnd
While $ws2<=$ws1
$ws2=InputBox("随机实验","对不起!"&@CRLF&"您输入的最大范围:"&$ws2&"小于或等于最小范围:"&$ws1 _
&@CRLF&"请重新输入随机数的最大范围:",""," m10")
quit(@error)
WEnd
$ws3=InputBox("随机实验","请输入取随机数的数量(也就是取几个随机数):",""," m10")
quit(@error)
$no3=StringIsInt($ws3)
While $ws3=0
$no1=MsgBox(4+0x40+0x100,"随机实验","您确定不取随机数!"&@CRLF&'按"是"确认并退出程序,按"否"重新输入')
Switch $no1
Case 6
Exit
Case 7
$ws3=InputBox("随机实验","请输入取随机数的数量(也就是取几个随机数):",""," m10")
quit(@error)
$no3=StringIsInt($ws3)
EndSwitch
WEnd
While $no3=0
$ws3=InputBox("随机实验","对不起!"&@CRLF&"您输入的数不是整数"&@CRLF& _
"请重新输入取随机数的数量(也就是取几个随机数):",""," m10")
quit(@error)
$no3=StringIsInt($ws3)
WEnd
While $ws3<0
$ws3=InputBox("随机实验","对不起!"&@CRLF&"您输入的数"&$ws3&"小于0"&@CRLF& _
"请重新输入取随机数的数量(也就是取几个随机数):",""," m10")
quit(@error)
$no3=StringIsInt($ws3)
WEnd
EndSwitch
EndFunc
Func quit($x)
If $x=1 Then
Exit
EndIf
EndFunc
才学AU3没几天,就自己动手写了一小段代码,发现问题不少,现在还有2个没有解决
1、我第一次输入99,第二次输入1234,提示我1234<=99,百思不得其解
2、就是关于变量声明,我想直接声明一个数组,但不知道这个数组里面要放多少数进去,如这样:
Dim $ws,$ws1[$ws2 1,因为Au3只有'一类'变量, 不像别的语言细分有字符变量, 整数等...所以, 变量的比较有时会出现你所说的 1234<=99的现象...这时, 你先用 Number($var1) <= Number($var2) 比较前,要先'取出'变量中的数字.
2,数组的定义:可以先定义好下标但不定义其元素, 它的元素一般自定义为空字符. 也可以同时定义其元素, 但元素个数只能少于或等于数组的下标数! 比如 Dim $arrayorDim $array =
or Dim $array =
非法的定义: Dim $array =
操作数组时, 特别要注意下标不可越界, 很多时候程序的崩溃都是这类潜在的错误造成( 编译时, 检测不出)的 回复 2# user3000
兄弟,我的意思是说定义数组的时候可不可以不声明下标 回复 3# 2011风之叶
可以是可以,不过如果不是特殊要求还是确定下好 不懂,进来学习下!
页:
[1]